ZHA light state incorrect if issuing lots of light on/off commands

I’m having an annoying issue where the light state isn’t updated even though the command executed successfully.

I have around 45 IKEA Tradfri lights directly connected to a ConBee II stick and ZHA (no bridge), if I fire too many commands in a sequence – like in my night mode script where I switch off most lights, the interface won’t update some lights. Even though they did turn off HA says they are still on.

If I divide the script into sections separated with a 1sec delay it works fine. Is there a similar issue like the Hue bridge has that it can’t process commands fast enough or what’s going on here?

It’s not the end of the world as I’ve already worked around it, but it would be fun to hear if there is any known cause or possibly even a better fix?

This is a gwneral limitation of zigbee networks when too many commands get sent at the same time, it can lead to delayed or even lost messages. However if you create zigbee groups (on the ConBee side) and send the command to this geoup instead of the individual lights, you only send one command to the controller and the command is automagically propagated to the individual devices, no delay/lost messages. So in your case, I’d create one large group containing all lights and some smaller groups for the individual rooms. I do the same and it works fine. It’s important to create the groups om the zigbee side, not on the HA side. HA groups/light groups suffer from the same issue as calling each light individually.

1 Like

Although there never was a reply from @ZyberSE, I don’t think @Burningstone addressed the actual issue. As I understand it, the issue was not, that lights don’t turn off, but that the state in HA remains on, even though the lights successfully turned off.
I have the same problem with my light groups with 3 or 4 entities. I turn the group on or off and all lights turn on or off, but almost always one state in the group is wrong afterwards.

This is something reported by a number of people in different threads. To my knowledge there is no solution. E.g.

Personally I have purchased a Zonoff 3.0, however do not like the work of re-paring my 60+ devices, so I live with the workarrounds like the rest of you. For now I have setup the sonoff zigbee2mqtt and play around with the devices in the basement.

Thank you for this. This method seems to work to make the lights actually turn off or on. However it does not solve the issue with the state changes not showing up in the UI - in fact it seems to make it slightly worse. Presumably because the state change updates all come simultaneously.

I have implemented a workaround:
I use this custom component: GitHub - mdeweerd/zha-toolkit: 🧰 Zigbee Home Assistant Toolkit - service for "rare" Zigbee operations using ZHA on Home Assistant (needs enabling in configuration.yaml once installed)
Then after any batch on/off operations I trigger this automation which force state updates of every light that ZHA provides (it doesn’t play nicely with ZHA light groups and I can’t find a way to make it continue on error)

alias: "[Lighting] Update states"
description: >-
  Sometime, particularly when batch turn on/turn off operations are performed.
  Lights' states in home assistant don't get updated accurately. This automation
  forces a state update.
trigger: []
condition: []
  - repeat:
      for_each: >-
        {{states.light | map(attribute='entity_id') | select('in',
        integration_entities('zha')) | list }}
        - continue_on_error: true
          service: zha_toolkit.attr_read
            ieee: "{{ repeat.item }}"
            cluster: 6
            attribute: 0
mode: single

This somewhat old thread is alive again:-) I ended up moving everything to the Sonoff 3.0 plus and using Z2M. Have not seen issues afterwards.

@khvej8 – How many lights are you controlling at once? I’ve had problems with this (14+12 lights all changing color temperature at the same time) and I’m wondering if it is worth getting the Sonoff and re-pairing everything…
Thanks! -David

I do not have more than lights 4 in a zigbee group, and do control more than 8 in any one command (scene activate).

I do turn off 40+ lights in my “leave home” automation, however not sure how the “light.off” works when used with areas. Might be devided into many zigbee commands.

With conbee2 I did see issues on groups of 4.

I am actually trying to use this.
I tried to issue the command to a stuck light. Based on the response

zha_toolkit_version: v1.1.2
zigpy_version: 0.57.2
zigpy_rf_version: 0.11.5
ieee_org: light.office_ceiling
ieee: 34:25:b4:ff:fe:98:08:b9
command: attr_read
command_data: null
start_time: "2023-10-23T15:05:05.016503+00:00"
errors: []
  cluster_id: 6
  attr_id: 0
  dir: 0
  tries: 1
  expect_reply: true
  args: []
  force_update: true
  read_before_write: true
  read_after_write: true
attr_type: "0x10"
write_is_equal: false
  - "0": 0
  - {}
success: true

It reads fine as 0 (off) but on the gui the state is still wrong:

Any ideas what I am doing wrong here?