Red Series Dimmer in Smart Bulb Mode, how to get changes to the bulb back to the switch

I’ve got a red series dimmer in my daughter’s room and just installed some WiFi RGB bulbs. The dimmer is connected to Home Assistant via Zwave-js and the bulbs are connected via the Tuya integration. There are 4 WiFi bulbs and they are in a light group.

I have the dimmer in Smart Bulb mode and I’ve used the blueprint below to create an automation to control the lights from the switch. By itself, this works well and the lights turn on/off & dim from the switch and a double tap up sets brightness to 100% and resets the bulbs to white.

However, what I’m lacking is the ability to have changes to the bulbs reflected back to the switch. So if I turn on/off the bulbs or change the brightness via HA, the status of the switch doesn’t change. I created an automation to do this, but having both automations enabled seems to create loops and leads the overall control of the lights to be unreliable and unpredictable.

Any recommendation on how this can be solved so that the switch controls the bulbs and if the bulbs are changed via HA it is reflected in the switch.

Blueprint: Home Assistant Blueprint - Inovelli Red On/Off or Dimmer Scene to Actions · GitHub

Switch Automation:

alias: 'Kid''s Bedroom Light Sync: Switch'
description: ''
use_blueprint:
  path: mikemsd/inovelli_red_on_off_or_dimmer_scenes_zwavejs.yaml
  input:
    inovelli_switch: ece22faf34c95dadcaaf690e637a61e7
    config_action:
      - service: light.toggle
        target:
          entity_id: light.kids_strip_lights
    up_x2_action:
      - service: light.turn_on
        target:
          entity_id: light.kids_bedroom_lights
        data:
          brightness_pct: 100
      - service: light.turn_on
        target:
          entity_id: light.kids_bedroom_light_bulbs
        data:
          kelvin: 2700
          brightness_pct: 100
    up_action:
      - service: light.turn_on
        target:
          entity_id: light.kids_bedroom_light_bulbs
    up_release_action:
      - service: light.turn_on
        target:
          entity_id: light.kids_bedroom_light_bulbs
        data:
          brightness: '{{ state_attr(''light.kids_bedroom_lights'',''brightness'') }}'
    down_release_action:
      - service: light.turn_on
        target:
          entity_id: light.kids_bedroom_light_bulbs
        data:
          brightness: '{{ state_attr(''light.kids_bedroom_lights'',''brightness'') }}'
    down_action:
      - service: light.turn_off
        target:
          entity_id: light.kids_bedroom_light_bulbs

Bulb Automation:

alias: 'Kid''s Bedroom Light Sync: Bulb'
description: ''
trigger:
  - platform: state
    entity_id: light.kids_bedroom_light_bulbs
  - platform: state
    entity_id: light.kids_bedroom_light_bulbs
    attribute: brightness
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.kids_bedroom_light_bulbs
            state: 'on'
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.kids_bedroom_lights
            data:
              brightness: >-
                {{
                state_attr('light.kids_bedroom_light_bulbs','brightness')
                }}
    default:
      - service: light.turn_off
        data: {}
        target:
          entity_id:
            - light.kids_bedroom_lights
mode: queued
max: 10

I do my automations in node red so I won’t be able to help with the yaml, but I’ll run you through my general thought process here.

The way I’d approach this would be using the bulb’s brightness attribute as the trigger.
From there the first step should be checking the brightness of the switch. If it matches, do nothing. If it doesn’t, set the switch brightness to match the bulb brightness.

Then on your automation to control brightness of the bulbs from the switch, you’ll want to implement the same logic.
Brightness of the switch as the trigger.
Check the brightness of the bulbs, if they match do nothing, if they don’t, set the bulb brightness to match the switch.

Implementing the check before calling the service should eliminate the loop you’re seeing.

Thanks for the advice. I added the brightness match in a couple of places and also added a condition to only run if the other automation isn’t running (I had to modify the blueprint I was using to add the condition). I honestly haven’t checked to see which helped more, but adding both seemed to get rid of the loops and improve responsiveness.

automation.kids_bedroom_light_sync_switch:

alias: 'Kid''s Bedroom Light Sync: Switch'
description: ''
use_blueprint:
  path: inovelli_red_on_off_or_dimmer_scenes_with_condition_zwavejs.yaml
  input:
    inovelli_switch: ece22faf34c95dadcaaf690e637a61e7
    up_action:
      - service: light.turn_on
        target:
          entity_id: light.kids_bedroom_light_bulbs
    down_action:
      - service: light.turn_off
        target:
          entity_id: light.kids_bedroom_light_bulbs
    automation_condition: automation.kids_bedroom_light_sync_bulb
    config_action:
      - service: light.toggle
        target:
          entity_id: light.kids_strip_lights
    up_release_action:
      - choose:
          - conditions:
              - condition: template
                value_template: >-
                  {{ state_attr('light.kids_bedroom_light_bulbs','brightness') != state_attr('light.kids_bedroom_lights','brightness') }}
            sequence:
              - service: light.turn_on
                target:
                  entity_id: light.kids_bedroom_light_bulbs
                data:
                  brightness: >-
                    {{ state_attr('light.kids_bedroom_lights','brightness') }}
        default: []
    down_release_action:
      - choose:
          - conditions:
              - condition: template
                value_template: >-
                  {{ state_attr('light.kids_bedroom_light_bulbs','brightness') != state_attr('light.kids_bedroom_lights','brightness') }}
            sequence:
              - service: light.turn_on
                target:
                  entity_id: light.kids_bedroom_light_bulbs
                data:
                  brightness: >-
                    {{ state_attr('light.kids_bedroom_lights','brightness') }}
        default: []
    up_x2_action:
      - service: light.turn_on
        target:
          entity_id: light.kids_bedroom_lights
        data:
          brightness_pct: 100
      - service: light.turn_on
        target:
          entity_id: light.kids_bedroom_light_bulbs
        data:
          kelvin: 2700
          brightness_pct: 100

automation.kids_bedroom_light_sync_bulb:

alias: 'Kid''s Bedroom Light Sync: Bulb'
description: ''
trigger:
  - platform: state
    entity_id: light.kids_bedroom_light_bulbs
  - platform: state
    entity_id: light.kids_bedroom_light_bulbs
    attribute: brightness
condition:
  - condition: template
    value_template: '{{ is_state_attr(''automation.kids_bedroom_light_sync_switch'', ''current'', 0) }}'
  - condition: state
    entity_id: script.kids_bedroom_lights_reset_to_white
    state: 'off'
  - condition: template
    value_template: >-
      {{ state_attr('light.kids_bedroom_light_bulbs','brightness') != state_attr('light.kids_bedroom_lights','brightness') }}
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.kids_bedroom_light_bulbs
            state: 'on'
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.kids_bedroom_lights
            data:
              brightness: >-
                {{ state_attr('light.kids_bedroom_light_bulbs','brightness') }}
    default:
      - service: light.turn_off
        data: {}
        target:
          entity_id:
            - light.kids_bedroom_lights
mode: queued
max: 10