Trigger on Philips Hue dimmer switch button press and not state

Is it possible to trigger an automation on a button press on the Philips Hue dimmer switch, instead of state?

I have this automation, that turns fluxer off if some one dims the light with the remote:

- id: 'turn_off_fluxer_when_manual_light_adjust'
   alias: Turn off fluxer when manual light adjustment
   initial_state: true
   trigger:
     - platform: state
       entity_id:
         - sensor.philips_hue_dimmer_switch 
       to: '2_click_up'
     - platform: state
       entity_id:
         - sensor.philips_hue_dimmer_switch 
       to: '3_click_up'
   condition:
     - condition: state
       entity_id: switch.fluxer
       state: 'on'
   action:
     - service: switch.turn_off
       entity_id: switch.fluxer

And this works as intended, but not when the same button is pressed as the current state. Is there a way to trigger on button press and not state? or is there another way to do this?

1 Like

Curious to learn if you found a way…

Why do you want to trigger it If it has allready the right state? Or why is the state wrong?

The automation above only works when state is changed. So if the remote (sensor.philips_hue_dimmer_switch) is in state ‘2_click_up’ and fluxer (switch.fluxer) is on and i press the button for dim up the state is the same and the automation will not run. But if i press the button for dim down the state change to ‘3_click_up’ and it works. If the current state is ‘3_click_up’ the opposite don’t trigger this automation.

So that is not really family friendly, because they don’t know the current state. So if they press the button and nothing happens then they are not happy :wink:

So my current workaround is that when you want to manually change the lights (dim up or down), then you press the dim up button and then dim down button, then you can manually change the lights because that will always trigger this automation.

Ah, I understand. Do you know how other switches works? I have no switches yet.

Just some rough ideas:

  • if the state is changed to “up” or “down”, a script removes the state. an automation can do this.
  • or the switch triggers always a script which changes the dim-level and as next step the state (back to something neutral)

on the other hand you can switch through the functions with your workaround and the counter component… hmm… I need a switch :slight_smile:

Thanks for your suggestions. I only have hue dimmer switches.

I started writing my first python script and then i noticed something, so i did some changes to automation and it works now.

- id: 'turn_off_fluxer_when_manual_light_adjust'
   alias: Turn off fluxer when manual light adjustment
   initial_state: true
   trigger:
     - platform: state
       entity_id:
         - sensor.philips_hue_dimmer_switch 
       to: '2_click'
     - platform: state
       entity_id:
         - sensor.philips_hue_dimmer_switch 
       to: '3_click'
   condition:
     - condition: state
       entity_id: switch.fluxer
       state: 'on'
   action:
     - service: switch.turn_off
       entity_id: switch.fluxer

State 2_click_up is when button is released and state 2_click is on button pressed. So i changed the automation to trigger on click and not click_up and now it works.

BUT this means that using state 2_click_up should also works because when current state is 2_click_up and i press the button it changes to 2_click (for a short moment) and when i release button state changes to 2_click_up. So i tested this again and it also works.

So i don’t know why it didn’t work the first time, but now it works (both variants of this automation) and i have learned something new. So thanks for your input, it got me on the right path.

Forgot to say that to get this switches working in HA iam using 0.7 of this Hue-sensors-HASS custom component.

2 Likes

Nice. Thats what I like on the HA-playground: You will always find something to get it work :slight_smile:

I’ve been experimenting with this and as far as I can see ‘x_click’ captures a press and long hold on the switch while ‘x_click_up’ captures the switch being released which ends with the state as up.

As the state always has to end ‘up’, if you long hold (it’s not very long but it is a clear press and hold not just click), you’ll capture that state change from ‘click_up’ to just ‘click’ and can therefore capture a repeated press on the same switch.

This dost seem to be reliably working for me, sometimes the switch will report #_click and sometimes the state wont change but the last update time in the attributes section will. Thought this was going to be a simple fix :confused:

Is it possible for an automation to read the lust update tom and activate when it changes?

I use this. I can make any press do anything I want. Mine are used to trigger scenes and input_booleans to keep track of when people take medications.

After some more research and trial and error I have worked out how to make the hue dimmer switch rock solid (sorry If this was obvious to some people but it wasn’t to me).
To use the hue dimmer switch with home assistant (and the fantastic Hue sensors HASS component) in an automation a trigger should not be used to detect the state of the switch but a condition. This solves the issue of the state being the same for two subsequent button pushes as the trigger simply looks for any call from the switch to home assistant then the condition checks to see what button was pressed. Here is a photo of how a hue dimmer switch should be set up in an automation.

Hope this helps anyone that was running into the same issues as me :slightly_smiling_face:

1 Like

I am very, very new to HA. I have used the robmarkcole code in my configuration. I now can see my dimmer switches but I do not have a clue on how to set up the buttons to work my various smart home items in HA. Please direct me to a step by step understanding on what I need to put in automations, script and/or configurator to use more functionality of my dimmer switches!!