Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge 🌉, get rid of your proprietary Zigbee bridges 🔨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
11.78k stars 1.64k forks source link

Cannot change operation_mode on Aqara H1 Switches (Xiaomi WS-EUK01/02/04) #20036

Closed AkshayRao27 closed 9 months ago

AkshayRao27 commented 9 months ago

What happened?

Trying to change the Operation mode on three different models of Aqara H1 switches (Xiaomi WS-EUK01, WS-EUK02, & WS-EUK04) results in an error: WS-EUK01: Publish 'set' 'operation_mode' to 'Wardrobe Switch' failed: 'Error: undefined is not a object, got string ("decoupled")' WS-EUK02: Publish 'set' 'operation_mode' to 'Toilet Switch' failed: 'Error: undefined is not a object, got string ("decoupled")'' WS-EUK04: Publish 'set' 'operation_mode' to 'Bathroom Switch' failed: 'Error: undefined is not a object, got string ("decoupled")'

None of the methods that I have tried so far have been able to change the operation mode. I have tried:

This may be related to #19960, #19964, and/or #19478, but I'm not sure because those issues were about other models

What did you expect to happen?

When the Operation Mode for a switch is changed in the front end or by manually sending an MQTT Payload, there is no error & the Operation Mode changes to the specified value.

How to reproduce it (minimal and precise)

Via Z2M:

  1. Open Zigbee2MQTT & select an Aqara H1 Switch
  2. In the "Exposes" tab, find "Operation mode" and click on "decoupled"

Via MQTT:

  1. Go to Settings > Devices & Services > MQTT > Devices
  2. Select an Aqara H1 Switch, find the "Configuration" card and select a value from the "Operation mode" drop down

Via MQTT Explorer:

  1. In MQTT Explorer, navigate to the Aqara H1 Switch under the zigbee2mqtt topic
  2. Publish a packet with {"operation_mode_left": "decoupled"} to zigbee2mqtt/<Switch_Name>/operation_mode/set
  3. Just to be sure, publish a packet with {"operation_mode_left": "decoupled"} to zigbee2mqtt/<Switch_Name>/set

Zigbee2MQTT version

1.34.0

Adapter firmware version

7.3.1.0 build 0

Adapter

SONOFF ZBDongle-E

Debug log

log.txt

pusheax0 commented 9 months ago

Zigbee2MQTT version 1.34.0-dev (commit #299b37a7)

Adapter firmware version 7.3.1.0 build 0

Adapter SONOFF ZBDongle-E and SONOFF ZBDongle-P

Still having this issue too. The issue is not resolved by commit 392ad722. I completely rebuilt z2m yesterday after it was fixed, and again today to make sure. It DOES work in z2m version 1.31. database.db.json

log.txt

about log state switch
wezzle commented 9 months ago

Commit 392ad722 fixes this for xiaomi_switch_operation_mode_basic. My device seems to run xiaomi_switch_operation_mode_opple where the check is still utils.assertObject(value); https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/converters/toZigbee.ts#L2501C30-L2501C30

I have no running dev version so I can't test the fix but perhaps @Koenkk can take another look?

pusheax0 commented 9 months ago

Commit 392ad722 fixes this for xiaomi_switch_operation_mode_basic. My device seems to run xiaomi_switch_operation_mode_opple where the check is still utils.assertObject(value); https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/converters/toZigbee.ts#L2501C30-L2501C30

I have no running dev version so I can't test the fix but perhaps @Koenkk can take another look?

I replaced this line https://github.com/Koenkk/zigbee-herdsman-converters/commit/392ad722e0f9ad9f151b9bfacab433f3492904f1#diff-cdc7c627220d02e6995b7fa52a0056b8650198a9850fc9f61c3eee7365fb8698R2487

with let targetValue = utils.isObject(value) && value.hasOwnProperty('state') ? value.state : value; and it fixed it.

Koenkk commented 9 months ago

Already fixed in the dev branch

pusheax0 commented 9 months ago

Already fixed in the dev branch

Not fixed for 0pple devices. Please read thread and see that the dev branch is being used.

Sperum commented 9 months ago

Im running the latest commit and i still have the same issue (below is the error from the log) image image

Zigbee2MQTT:debug 2023-12-05 22:59:20: Received MQTT message on 'zigbee2mqtt/Switch_Light Toilet Down/set' with data '{"operation_mode_left":"decoupled"}'
Zigbee2MQTT:debug 2023-12-05 22:59:20: Publishing 'set' 'operation_mode' to 'Switch_Light Toilet Down'
Zigbee2MQTT:error 2023-12-05 22:59:20: Publish 'set' 'operation_mode' to 'Switch_Light Toilet Down' failed: 'Error: undefined is not a object, got string ("decoupled")'
Zigbee2MQTT:debug 2023-12-05 22:59:20: Error: undefined is not a object, got string ("decoupled")
    at Object.assertObject (/app/node_modules/zigbee-herdsman-converters/src/lib/utils.ts:517:15)
    at Object.convertSet (/app/node_modules/zigbee-herdsman-converters/src/converters/toZigbee.ts:2501:19)
    at Publish.onMQTTMessage (/app/lib/extension/publish.ts:249:52)
    at EventEmitter.emit (node:events:525:35)
    at EventBus.emitMQTTMessage (/app/lib/eventBus.ts:109:22)
    at MQTT.onMessage (/app/lib/mqtt.ts:141:27)
    at WebSocket.<anonymous> (/app/lib/extension/frontend.ts:130:27)
    at WebSocket.emit (node:events:513:28)
    at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:1192:20)
    at Receiver.emit (node:events:513:28)

Availability: Online Device type: Router Zigbee Model: lumi.switch.n2aeu1 Zigbee Manufacturer: LUMI Description: Aqara smart wall switch H1 EU (with neutral, double rocker) Support status: Supported Firmware build date: 11-10-2021 Manufacturer: Xiaomi Model: WS-EUK04 Interview completed: True

AkshayRao27 commented 9 months ago

Already fixed in the dev branch

I just tried this again on the dev branch by installing Zigbee2MQTT Edge in Home Assistant. The issue doesn't seem to be fixed. See screenshots: image image

ynsgnr commented 9 months ago

I have the same issue!

kirbodev commented 9 months ago

+1 same issue here

Koenkk commented 9 months ago

Pushed another fix, please try again.

Changes will be available in the dev branch in a few hours from now.

Sperum commented 9 months ago

Pushed another fix, please try again.

Changes will be available in the dev branch in a few hours from now.

Tested with : 1.34.0-dev commit: f11eb24

Error:

Zigbee2MQTT:debug 2023-12-06 21:47:45: Received MQTT message on 'zigbee2mqtt/Switch_Light Toilet Down/set' with data '{"operation_mode_left":"decoupled"}' Zigbee2MQTT:debug 2023-12-06 21:47:45: Publishing 'set' 'operation_mode' to 'Switch_Light Toilet Down' Zigbee2MQTT:error 2023-12-06 21:47:45: Publish 'set' 'operation_mode' to 'Switch_Light Toilet Down' failed: 'Error: undefined is not a object, got string ("decoupled")' Zigbee2MQTT:debug 2023-12-06 21:47:45: Error: undefined is not a object, got string ("decoupled") at Object.assertObject (/app/node_modules/zigbee-herdsman-converters/src/lib/utils.ts:517:15) at Object.convertSet (/app/node_modules/zigbee-herdsman-converters/src/converters/toZigbee.ts:2501:19) at Publish.onMQTTMessage (/app/lib/extension/publish.ts:249:52) at EventEmitter.emit (node:events:525:35) at EventBus.emitMQTTMessage (/app/lib/eventBus.ts:109:22) at MQTT.onMessage (/app/lib/mqtt.ts:141:27) at WebSocket. (/app/lib/extension/frontend.ts:130:27) at WebSocket.emit (node:events:513:28) at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:1192:20) at Receiver.emit (node:events:513:28)

AkshayRao27 commented 9 months ago

Having the same issue still. image image

pusheax0 commented 9 months ago

@AkshayRao27 Try again after version 16.2.0 is released later today. https://github.com/Koenkk/zigbee-herdsman-converters/releases

Sperum commented 9 months ago

@AkshayRao27 Try again after version 16.2.0 is released later today. https://github.com/Koenkk/zigbee-herdsman-converters/releases

I've reinstall Z2M Edge, but only the commit got updated. How do you force 16.2 update with HA ?

Thank you

AkshayRao27 commented 9 months ago

Just did a quick test with 16.2 The error message has gone away now and I can set the switch to decoupled Mode. However, even after setting it to decoupled it is still behaving like a relay - how can I figure out why exactly this may be happening? What troubleshooting info would be helpful?

gloaysa commented 9 months ago

@AkshayRao27 Try again after version 16.2.0 is released later today. https://github.com/Koenkk/zigbee-herdsman-converters/releases

I've reinstall Z2M Edge, but only the commit got updated. How do you force 16.2 update with HA ?

Thank you

The 16.2.0 release is for the converters library. The latest commit on the Z2M Edge (dev) updates the dependency of said library to 16.2.0. If you are in 1.34.0-dev commit: cb50942 on Edge, you are good to go.

I was able to set decoupled mode, but I'm not physically next to the switch (yet) to confirm is not working as a relay. @AkshayRao27 can you confirm you have "Mode switch": "fast_mode"? I think you have to have it on fast_mode (I've read it in some Reddit thread, so take it with a grain of salt).

AkshayRao27 commented 9 months ago

can you confirm you have "Mode switch": "fast_mode"?

There's no option in the frontend for checking this. I tried using MQTT Explorer to issue {"mode_switch": ""} to zigbee2mqtt/Bedroom Switch/get but it doesn't do anything in MQTT Explorer.

gloaysa commented 9 months ago

can you confirm you have "Mode switch": "fast_mode"?

There's no option in the frontend for checking this. I tried using MQTT Explorer to issue {"mode_switch": ""} to zigbee2mqtt/Bedroom Switch/get but it doesn't do anything in MQTT Explorer.

Screenshot 2023-12-08 at 14 52 03

Yes, there is.

I've been able to test and decoupled mode works in the sense that it no longer acts as a physical switch, but now when I bind the switch to a group (can't do it directly to a device for some reason), does not work.

If someone knows a workaround for the binding, I'll appreciate it. Otherwise, I get the event so I can in the meantime create an automation in Home Assistant (although I prefer binding a thousand times).

AkshayRao27 commented 9 months ago

Strange. Your layout looks different from mine: image

I restarted HA, and now pressing the switch seems to not trigger the relay. I can run automations with the "single left" action.

If I use the state switch either in the Zigbee2MQTT or in the MQTT integration in Home Assistant image then the switch continues to act like a relay. Is this intended behaviour?

With the switch in decoupled mode, the LED on the switch never turns off. If I toggle the "Flip indicator light" option, then the LED never turns on at all - is this intended behaviour too?

KMTsvetanov commented 9 months ago

one more here from me: (Aqara smart wall switch H1 EU (with neutral, double rocker) (WS-EUK04)) image

and this for the power: image

image

AkshayRao27 commented 9 months ago

@KMTsvetanov Can you check if your Edge build has updated correctly? I have the same switch ("Bedroom Switch" from the screenshot in my previous reply) and decoupled mode is working for me on this version of edge: image I had to reinstall the Edge addon twice (including the whole "check for updates" thing in the addon store in HA) and then restart HA completely before decoupled mode started working for me.

KMTsvetanov commented 9 months ago

@AkshayRao27 for me it's this: image

I'm new to this and don't know how to switch to dev version (if this is what you are asking) If yes, I'm all ears.

Clicking on "unknown" redirects me to: https://github.com/Koenkk/zigbee2mqtt/commit/unknown 404 page not found

AkshayRao27 commented 9 months ago

for me it's this:

Yup, that's the issue then. The 'operation_mode' thing isn't working on the release branch right now and has only been fixed on the latest version of the dev branch.

don't know how to switch to dev version

It's VERY easy! If you're running Home Assistant:

  1. Go to the Addon Store, make sure to click "check for updates" from the three-dot menu first, & then install Zigbee2MQTT Edge. Don't start it yet.
  2. Then, go to the non-edge version of the addon that you currently have running, go to the Configuration Tab, select "Edit in YAML" from the three-dot menu, and copy the contents of what you see to somewhere safe.
    • If you want to be extra-safe, use some kind of File Browser addon, navigate to the Zigbee2MQTT Folder (for me it was in /homeassistant/zigbee2mqtt) and copy all of the contents of that folder to your PC (highly unlikely that this would be required, but it never hurts to have a backup)
  3. Stop Zigbee2MQTT (you don't need to uninstall it).
  4. Go to the Configuration Tab in the newly installed Zigbee2MQTT Edge, select "Edit in YAML" from the three-dot menu, and paste in what you copied from Zigbee2MQTT earlier.
  5. Start Zigbee2MQTT Edge, and it should all work seamlessly.

Verify that you are on the version that I posted above - the decoupled mode should ideally work for you then :)

gloaysa commented 9 months ago

@KMTsvetanov assuming you are using a home assistant addon:

You are using the 'normal' addon of Z2M, you need to stop that addon and install Zigbee2Mqtt Edge one. To do so, go to the addons store in HomeAssistant, click on 'Check for Updates' and the right top corner menu, give a few seconds and install the Edge addon.

edit: AkshayRao27 instructions are better than mine, we published our comments at the same time.

KMTsvetanov commented 9 months ago

@AkshayRao27 ok tested. Now:

  1. Good - I can decouple
  2. Bad - I'm still getting Sensors -> Energy = Unknows image image Triend to refresh "Power" image

1 ### Question (maybe bug): I can't make trigger for clicking image

gloaysa commented 9 months ago

Regarding the trigger for clicking:

You are using the action of the physical switch (that won't work when clicking because is on decoupled mode). That will only trigger when you manually, from the UI, switch the relay on/off.

I have created this automation, sharing in case it helps:

alias: Control interruptores (temporal)
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.playroom_interruptor_action
      - sensor.cuarto_interruptor_action
      - sensor.bano_interruptor_action
      - sensor.vestidor_interruptor_action
      - sensor.aseo_interruptor_action
    to: single
condition: []
action:
  - service: light.toggle
    target:
      entity_id: >-
        {{ 'light.' ~
        trigger.to_state.entity_id.split('.')[1].split('_')[0].replace('ñ', 'n')
        ~ '_techo' }}
mode: queued
max: 10

The important take away here is that you have to use as trigger for your automation the state of your_name_action when changes to 'single' (there are other options, I'm only using the single click).

My automation reuses code for multiple switches because the lights they are turning on follows the same pattern: name of light to change: light.{name}techo name of the event that operates the light: switch.interruptor{name}_action

I want to emphasize that for me, this automation should be temporal.

Binding to lights directly is not working for me at the moment, don't know the why (it looks like they bind, but then doesn't work, no logs no nothing). I don't know if someone can report that happening to them and if I should open a ticket.

KMTsvetanov commented 9 months ago

@gloaysa when on 'decoupled' or 'control_relay' mode there are no logs (in HA) when pressing buttons (Light still turns on on control_relay). Still can't get the trigger to work: Tried the entry "sensor.0x54ef44100096461e_action" for single click, even tried for any change... Even in the Developer Tools I can't see the sate change on click for all my testing: image image

gloaysa commented 9 months ago

@KMTsvetanov it could be that the device is not responsive or not properly paired? I would try disconnecting it from the zigbee network and connecting it again.

I can say much more than that, my experience with all this is also only at user level.

KMTsvetanov commented 9 months ago

@gloaysa @AkshayRao27

Maybe a bug?

I found that I need to manually change the state of entity: sensor.0x54ef44100096461e_action to "single_right" in Developer Tools to make it work.. Clicking on the buttons doesn't change the state. Even in the logs you can't see them.

image

image

KMTsvetanov commented 9 months ago

I found what is the problem but now I need a help on how to do it:

https://github.com/Koenkk/zigbee2mqtt/discussions/16573

I need to update my firmware.

I use Zigbee 3.0 USB Dongle Plus. Can you point me to the link with the firmwares for it ?

image

I'm using the Zigbee 3.0 USB Dongle Plus ZBDONGLE-E (the 5cm in length)

If you are like me this is the way (works):

https://github.com/Koenkk/zigbee2mqtt/discussions/16573#discussioncomment-7807494

Sperum commented 9 months ago

Ok it seems its working now. However it only accept to setup controlled our decoupled trough the HA device view instead of Z2M device view. However the behavior is as expected. Thx

Ajhomepn commented 8 months ago

When will be released the version with this correction (normal not edge) ?

Ajhomepn commented 8 months ago

I'm runing the last edge version , i'm abel to go to decoupled or to relay , howerver on decoupled i can not triger anything ... this is ruining all my routines :/

gloaysa commented 8 months ago

@Ajhomepn

In case it helps, I'm sharing my automation on Home Assistant. To me, decoupled mode does not allow me to bind the switch to a bulb (or group, for that matter), so I ended using Home Assistant to control it:

alias: Switches Controller (temporal)
description: "Manages all Aqara switches, toggling lights if they haven't been recently turned on."
trigger:
  - platform: state
    entity_id:
      - sensor.playroom_interruptor_action
      - sensor.cuarto_interruptor_action
      - sensor.bano_interruptor_action
      - sensor.aseo_interruptor_action
      - sensor.vestidor_interruptor_action
    to: single
condition: []
action:
  - variables:
      room: >-
        {{ trigger.to_state.entity_id.split('.')[1].split('_')[0].replace('ñ',
        'n') }}
      light: "{{ 'light.' ~ room ~ '_techo' }}"
      light_last_changed: "{{ (as_timestamp(now()) - as_timestamp(states[light].last_changed)) }}"
  - alias: >-
      Avoid turning off a light that has just turned on (due to delay of switch
      and occupation triggering faster)
    if:
      - alias: Light hasn't changed in the last second
        condition: template
        value_template: "{{ light_last_changed > 1 }}"
    then:
      - service: light.toggle
        target:
          entity_id: "{{ 'light.' ~ room ~ '_techo' }}"
mode: queued
max: 10

I don't like to repeat myself, so this automation control all switches. The trick here is to follow a pattern on the naming of your switches and lights.

for example, all my switches follow this pattern: sensor.ROOM_SWITCH_action. all my lights follow this pattern:light.ROOM_techo.

Because of that, I'm able to toggle a light by reading the ROOM part of the switch.

If you want something simpler, you could do this for each switch instead:

alias: Switch Controller for YOUR SWITCH
description: "Manages A SWITCH, toggling lights on user input."
trigger:
  - platform: state
    entity_id:
      - sensor.YOUR_SWITCH_action # notice the _action part, that's what you are looking for.
    to: single # and also notice this single. This is a single click event
condition: []
action:
  - service: light.toggle
        target:
          entity_id: light.your_light
mode: single
drashish87 commented 6 months ago

Sorry to reopen the thread, has this been fixed in the latest Z2MQTT version or I still need to install the dev version? Having similar issue using latest firmware Sky connect zigbee dongle, thank you. Zigbee2MQTT version 1.36.0 commit: 2a53b8e5 Coordinator type EZSP v12 Coordinator revision 7.3.2.0 build 212

korobcov commented 5 months ago

I confirm, it doesn’t work for me on the stable version either Zigbee2MQTT 1.36.1

EZSP v8

6.10.3.0 build 297

Error 2024-04-14 01:43:12Publish 'set' 'operation_mode' to 'Выключатель прихожая ' failed: 'Error: ZCL command 0x54ef4410008b7064/1 manuSpecificLumi.write({"512":{"value":0,"type":32}}, {"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":4447,"transactionSequenceNumber":null,"writeUndiv":false}) failed (Timeout - 8792 - 1 - 82 - 64704 - 4 after 10000ms)'

newbyp commented 3 months ago

Sorry I am new to this, can someone confirm what the desired result is of setting the switch as decoupled.

I have just installed the 3 switch version and set as relay and all lights work fine. I now want to install more switches but need one to toggle on and off in HA but not physically switch the relay and therefore turn the light on. I assume this is decoupled mode.

I'm running z2m not the dev branch and have tried changing the setting in mqtt and checking it in z2m and regardless of what the mode is set to I don't see any changes in the operation.

Are my assumptions correct and is this an ongoing issue?

I could buy a battery powered smart switch instead of the single light switch or wait for it to be fixed.