Updating HA light brightness after stopping a smooth dimming down action

I’m using Hue dimmer switches with the continuous dimming (up and down) option on my Hue bulbs, by using a service call (light.turn_on with a brightness step and transition) to start dimming when the long press starts and a ZHA cluster command (3 = stop) to stop dimming (there isn’t a service level equivalent to that cluster command) when the long press ends. See snippets below.

The point of this is to have smooth dimming without doing multiple requests for dimming, and it relies on a specific ZigBee cluster command that Hue bulbs implement (so, quite specific to my setup). It works well but the issue is that when dimming down, as soon as I issue the light.turn_on service call, HA updates the entity status in the UI to off (which makes sense, because the service call is asking to turn off the light, albeit in a progressive manner). When I stop dimming half-way with that ‘stop’ command, the dimming stops (possibly with the light still on) but the state of the light in the UI actually stays off and there is a discrepancy between the light status as known by HA and the actual light status (i.e. HA thinks it’s off but it’s not).

So the question is, is there a way to force HA to update the light status and level after running that ZHA cluster command? I was thinking of the following:

  • a light.turn_on service call with no parameters: that would have the disadvantage of turning the light back on if the smooth dimming did turn off the light.
  • emitting a state_changed event: I’ve been looking at the events that do get emitted when a light state changes and I’d have to basically recreate a full event from scratch, is that even possible?

Here are the snippets:

Long press start:

    - conditions: "{{ command in ['up_hold','down_hold'] }}"
      sequence:
      - service: light.turn_on
        target:
          entity_id: "{{ entities_light_on }}"
        data:
          brightness_step: "{{ iif(command == 'up_hold',255,-255) }}"
          transition: 5

Long press end:

    - conditions: "{{ command == 'stop' }}"
      sequence:
      - repeat:
          for_each: "{{ entities_light }}"
          sequence:
          - variables:
              zha_identifiers: "{{ device_attr(repeat.item, 'identifiers') | selectattr(0,'eq','zha') | map(attribute=1) | list }}"
          - if:
              - condition: template
                value_template: "{{ zha_identifiers | length > 0 }}"
            then:
                - service: zha.issue_zigbee_cluster_command
                  data:
                    ieee: "{{ zha_identifiers | first }}"
                    endpoint_id: 11
                    cluster_id: 8
                    cluster_type: in
                    command: 3
                    command_type: server

Link to the full blueprint if that’s useful (it’s a bit more complicated in there because the blueprint supports ZigBee groups as well):

I’ve actually found that you can just trigger an HA update

      - service: homeassistant.update_entity
        target:
          entity_id: "{{ entities_light }}"

It does work somewhat, although I had to add a delay of 5s to make sure the update works after stopping the dimming (and even then, sometimes it misses one, although rarely). Not sure where that’d be coming from but overall this is working well enough I guess ? If there’s a better solution I’ll take it!