Hue Tap, making buttons toggle

I just acquired my first Philips Hue Tap Switch. I have connected it to HA via mqtt:

##  Philips Hue Tap Switch
### Dining Room
- platform: rest
  resource: http://[hue_bridge_ip]/api/[hue_bridge_user]/sensors/18
  value_template: '{{ value_json.state.buttonevent }}'
  name: 'Hue Tap Dining'
  scan_interval: 1
- platform: rest
  resource: http://[hue_bridge_ip]/api/[hue_bridge_user]/sensors/18
  value_template: '{{ value_json.state.lastupdated }}'
  name: 'Hue Tap Dining Last Updated'
  scan_interval: 1

and then I created this automation (button 1: 34, button 2: 16, button 3: 17, button 4: 18):

######                                         ######
##         Hue Tap Dining Automations              ##
######                                         ######
- alias: Hue Tap Dining automations
  trigger:
    platform: state
    entity_id: sensor.hue_tap_dining
    to: "16" 
  action:
    - service: switch.toggle
      entity_id: switch.alcohol_cabinet

And it works… just as it should, but not how I want it to.
The problem: If I press button 2, the light toggles to on, but if I press button 2 again to toggle off, HA sees this as no change of state since it was already 16. I would have to press a different button to change state and then press button 2 again for the toggle off to work. The Hue Tap also has a state: lastupdated that updates a UTC timestamp (formatted: 2017-06-17T22:22:19) to the last time a button was pressed on the Hue Tap, but I am not certain how I can implement this logic into my automation.
Has anyone else set up an automation for the Hue Tap and used a single button to toggle? I tried searching the site and web, but it seems most results are for the Hue Dimmer Switch, which works a little different.
Any suggestions would be greatly appreciated! :slight_smile:

1 Like

documentation says the “to” is optional.
What happens if you take it out?
Your trigger should fire for every state event.

@treno, that is accurate.
I had the “to” in there because I want to use each of the 4 buttons on the Hue Tap for 4 different toggles. I wasn’t sure how else I can check the state for button numbers, since I haven’t been able to figure out how to make separate conditions have their own respective actions.

EDIT: actually, it is not entirely accurate @treno. I just tested it to see. As long as I press one of the other buttons, so I do not press the same button back to back, it works. But since the state does not change from “on/off” and simply changes from 34, 16, 17, or 18 (depending what button was pressed last), the “state” does not change if repeatedly pressing the same button.

I was playing around with this earlier and found out that buttons will respond with every press if you use last_updated as the trigger and add a condition that checks for which button was pressed.

trigger:
  platform: state
  entity_id: sensor.tap_kitchen_updated
condition:
  condition: state
  entity_id: sensor.tap_kitchen
  state: '34'
1 Like

Sorry, I did eventually figure it out as well and thought I had posted my solution here. I did the same thing as you @dumbstart

I ended up writing:

######                                         ######
##            Hue Tap Button 2 (16)                ##
######                                         ######
- alias: Hue Tap Dining Button 2
  hide_entity: True
  trigger:
    platform: state
    entity_id: sensor.hue_tap_dining_last_updated
  condition:
    condition: state
    entity_id: sensor.hue_tap_dining
    state: '16'
  action: 
    - service: switch.toggle
      entity_id: switch.alcohol_cabinet
1 Like