Skip to content

Commit

Permalink
fix: Set power to 0 when TS011F_plug_1 changes state to OFF Koenk…
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Dec 16, 2023
1 parent 1bbbb5d commit 27e6d1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/devices/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,19 @@ const fzLocal = {
return result;
},
} satisfies Fz.Converter,
TS011F_onoff: {
...fz.on_off,
convert: async (model, msg, publish, options, meta) => {
const result = await fz.on_off.convert(model, msg, publish, options, meta);
if (result.state === 'OFF') {
// Device takes a lot of time to report power 0 in some cases. When the state if OFF
// we can assume power == 0
// https://github.com/Koenkk/zigbee2mqtt/discussions/19680#discussioncomment-7868445
result.power = 0;
}
return result;
},
} satisfies Fz.Converter,
TS011F_threshold: {
cluster: 'manuSpecificTuya_3',
type: 'raw',
Expand Down Expand Up @@ -3289,7 +3302,7 @@ const definitions: Definition[] = [
ota: ota.zigbeeOTA,
extend: tuya.extend.switch({
electricalMeasurements: true, electricalMeasurementsFzConverter: fzLocal.TS011F_electrical_measurement,
powerOutageMemory: true, indicatorMode: true, childLock: true}),
powerOutageMemory: true, indicatorMode: true, childLock: true, onOffFzConverter: fzLocal.TS011F_onoff}),
configure: async (device, coordinatorEndpoint, logger) => {
await tuya.configureMagicPacket(device, coordinatorEndpoint, logger);
const endpoint = device.getEndpoint(1);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1200,10 +1200,10 @@ const tuyaExtend = {
endpoints?: string[], powerOutageMemory?: boolean, powerOnBehavior2?: boolean, switchType?: boolean, backlightModeLowMediumHigh?: boolean,
indicatorMode?: boolean, backlightModeOffNormalInverted?: boolean, backlightModeOffOn?: boolean, electricalMeasurements?: boolean,
electricalMeasurementsFzConverter?: Fz.Converter, childLock?: boolean, fromZigbee?: Fz.Converter[], toZigbee?: Tz.Converter[],
exposes?: Expose[],
exposes?: Expose[], onOffFzConverter?: Fz.Converter
}={}) => {
const exposes: Expose[] = options.endpoints ? options.endpoints.map((ee) => e.switch().withEndpoint(ee)) : [e.switch()];
const fromZigbee: Fz.Converter[] = [fz.on_off, fz.ignore_basic_report];
const fromZigbee: Fz.Converter[] = [options.onOffFzConverter ?? fz.on_off, fz.ignore_basic_report];
const toZigbee: Tz.Converter[] = [tz.on_off];
if (options.powerOutageMemory) {
// Legacy, powerOnBehavior is preferred
Expand Down

0 comments on commit 27e6d1e

Please sign in to comment.