Skip to content

Commit

Permalink
fix: Improve battery % calculation for Tuya TS0203 and WSD500A (#7725)
Browse files Browse the repository at this point in the history
  • Loading branch information
deviantintegral committed Jul 3, 2024
1 parent 31a7861 commit 9b6f729
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/devices/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,17 @@ const definitions: Definition[] = [
exps.push(e.linkquality());
return exps;
},
meta: {
battery: {
// These sensors do send a Battery Percentage Remaining (0x0021)
// value, but is usually incorrect. For example, a coin battery tested
// with a load tester may show 80%, but report 2.5V / 1%. This voltage
// calculation matches what ZHA does by default.
// https://github.com/Koenkk/zigbee2mqtt/discussions/17337
// https://github.com/zigpy/zha-device-handlers/blob/c6ed94a52a469e72b32ece2a92d528060c7fd034/zhaquirks/__init__.py#L195-L228
voltageToPercentage: '3V_1500_2800',
},
},
configure: async (device, coordinatorEndpoint) => {
try {
const endpoint = device.getEndpoint(1);
Expand Down Expand Up @@ -2866,6 +2877,17 @@ const definitions: Definition[] = [
exposes: [e.battery(), e.temperature(), e.humidity(), e.battery_voltage()],
configure: tuya.configureMagicPacket,
whiteLabel: [tuya.whitelabel('Tuya', 'TH02Z', 'Temperature and humidity sensor', ['_TZ3000_fllyghyj', '_TZ3000_saiqcn0y'])],
meta: {
battery: {
// These sensors do send a Battery Percentage Remaining (0x0021)
// value, but is usually incorrect. For example, a coin battery tested
// with a load tester may show 80%, but report 2.5V / 1%. This voltage
// calculation matches what ZHA does by default.
// https://github.com/Koenkk/zigbee2mqtt/discussions/17337
// https://github.com/zigpy/zha-device-handlers/blob/c6ed94a52a469e72b32ece2a92d528060c7fd034/zhaquirks/__init__.py#L195-L228
voltageToPercentage: '3V_1500_2800',
},
},
},
{
fingerprint: [...tuya.fingerprint('TS0201', ['_TZ3000_dowj6gyi', '_TZ3000_8ybe88nf']), {manufacturerName: '_TZ3000_zl1kmjqx'}],
Expand Down

0 comments on commit 9b6f729

Please sign in to comment.