Thought I’d share my steps for getting a hue tap switch working, as there were a few steps involved and I had to scout info from a few separate places to get it all working.
First up - find the IP address of your hue bridge (and maybe set it to static on your router). Then, press the button on the hue bridge before issuing this command (with the IP address of your bridge in place of the Xs below:
curl -X POST -d '{"devicetype":"my_hue_app"}' http://XXX.XXX.XXX.XXX/api --header "Content-Type:application/json"
This will spit out something like this:
[ { "success": { "username": "SeCrETsECretMuMboJUmBO" } }]
Now, point a web broswer to:
http://XXX.XXX.XXX.XXX/api/SeCrETsECretMuMboJUmBO/sensors
This will give you a bunch of details about all your hue sensors and their possible states. Do a search on that page for “tap” and find out the sensor number that is assigned to the tap device (it will be the integer in quotes followed by :{“state”:{… BEFORE the name “Hue tap switch”)
Now you have the info you need for your configuration.yaml file. Replace the Y at the end of the resource lines below with that integer:
sensor:
- platform: rest
resource: http://XXX.XXX.XXX.XXX/api/SeCrETsECretMuMboJUmBO/sensors/Y
value_template: '{{ value_json.state.buttonevent }}'
name: 'Hue Tap'
scan_interval: 1
- platform: rest
resource: http://XXX.XXX.XXX.XXX/api/SeCrETsECretMuMboJUmBO/sensors/Y
value_template: '{{ value_json.state.lastupdated }}'
name: 'Hue Tap last updated'
scan_interval: 1
Finally, one automation to rule them all:
- id: tap_switching
alias: Hue tap switch controls
trigger:
- entity_id: sensor.hue_tap_last_updated
platform: state
action:
- delay:
milliseconds: 20
- data_template:
entity_id:
- light.
{%- if is_state('sensor.hue_tap', '34') -%}
your_first_light
{%- elif is_state('sensor.hue_tap', '16') -%}
your_second_light
{%- elif is_state('sensor.hue_tap', '17') -%}
your_third_light
{%- elif is_state('sensor.hue_tap', '18') -%}
your_fourth_light
{%- else -%}
this_light_should_never_happen
{% endif %}
service: light.toggle
A few notes:
- The 20 ms delay is in the automation because without it, on my system, the automation would be triggered by a button press detection before the button state sensor had updated, causing the automation to toggle the light corresponding to your previous button press, not the current one;
- 34 = button 1; 16 = button 2; 17 = button 3; 18 = button 4. Why? Because weird binary thing about how the switch registers presses, maybe;
- replace your_first_light, etc. with your light entity names, MINUS the “light.” part - because that’s templated in;
- enjoy!