How can I reset sensor state to detect sequential Hue Dimmer button press?

I am using the excellent Hue Sensor component from @robmarkcole to have my Hue Dimmer remote pull double-duty. It directly controls a couple Hue bulbs through the Hue hub, AND I am able to react to the button presses in Home Assistant (I did a write-up on how I’m using it here). In theory, this setup is beautiful.

However, I’ve discovered a flaw in this setup for my use case. Because the value of the sensor for the remote is always the last value, you’re not actually able to truly detect button presses – you only can react if the current button press was different from the last press (because otherwise the sensor state doesn’t change).

In my case, I use the dimmer remote to turn off my bedroom lamps, which also deactivates an input_boolean that turns off a motion sensor. However, since the lights come on automatically (not using the remote), I pretty much only ever press the Off button. Which means the sensor state for the remote doesn’t change, which means my automation doesn’t get triggered:

- alias: Disable bedroom motion lights when lamps off
  trigger:
    - platform: state
      entity_id: sensor.hue_dimmer_1
      to: '4_click'
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: input_select.mode
        state: 'Evening'
      - condition: state
        entity_id: input_select.mode
        state: 'Morning'
      - condition: state
        entity_id: input_select.mode
        state: 'Night'
  action:
    - service: homeassistant.turn_off
      entity_id: input_boolean.bedroom_motion_lights

I’ve looked into manually setting the sensor for the dimmer to some 0 value, but my research in other threads has indicated sensors are read-only.

Does anyone have any ideas on how I can detect button presses from this remote even if the press is the same as the last time?

Had a pretty lengthy thread on this feature previously. In summary, the attribute last_updated does change with every press.

OK, that’s interesting…so I could watch last_updated, and use that changing as a trigger, combined with a condition that the sensor value is 4_click?

Don’t think I’ve used attributes as triggers before but I’ll poke around with it. Thanks!

Yep, template sensor and an automation should do it

You can also take to: out of the trigger and add a condition that the state of the remote sensor is the button you want. That will also work!

Doesn’t all these solutions hit issues with the dimmer reporting additional state changes?

The dimmer switches have an attribute for battery_level. I think with these suggestions all your dimmer automation would end up retriggering whatever the last button push was whenever the dimmer reports a battery level update?

@phishsoft you seem to be correct regarding the updates on battery Level. Has someone got an idea how to stop battery Level updates triggering automations? Ich am currently using a hue dimmer at my bedside to turn_off everything at night…triggered two Times this afternoon.

I switched my triggers to only trigger if the battery is the same as last time. Once in a while this means it will ignore a click, but I’d rather that then it randomly triggering. So the condition ends up being:

condition:
condition: and
conditions:
- condition: template
value_template: “{{ (trigger.to_state.last_updated != trigger.from_state.last_updated) and (trigger.to_state.attributes.battery == trigger.from_state.attributes.battery) }}”
- condition: state
entity_id: sensor.my_hue_dimmer
state: ‘1_click’