Toggle Phillips Hue Sensors on/off from Hass

My Philips Hue is running in parallel / autonomous from Hass; rules for lights automation are primarily created and run using the Hue app, and occasionally I use Hass to change a scene or toggle a specific light. I am doing this for (1) keeping the Hue app functional (WAF) (2) because I’m too lazy to write redundant rules into Hass when Hue is satisfactory

Now the question is:
I would like to be able to disable the Hue motion sensor from Hass temporarily (projector, movie) instead of launching the Hue app and disabling the sensor manually.
Any ideas where I should start looking for an answer?

2 Likes

Did you ever get an answer to this? I too have this issue and thought that a REST switch may help, but I have to confess that I don’t understand the syntax well enough to get it to work.

I couldnt get the REST switch to work because syntax requires command and state endpoints to match, whereas for Hue the switch and state endpoints differ. Workaround in my case was a command line switch to set the state of the Hue motion sensor on / off.

- platform: command_line
  switches:
    motion_sensor_state:
     friendly_name: motion_sensor_state
      command_on: curl -X PUT -d '{"on":true}' "http://HUE_IP/api/HUE_API_KEY/sensors/SENSOR_ID/config"
      command_off: curl -X PUT -d '{"on":false}' "http://HUE_IP/api/HUE_API_KEY/sensors/SENSOR_ID/config"
      command_state: 'curl http://HUE_IP/api/HUE_API_KEY/sensors/SENSOR_ID/'
      value_template: '{{value_json.config.on}}'
4 Likes

That’s brilliant. Good work. This worked perfectly for me.

Can I just confirm I understand this properly…

I currently have a hue motion sensor in the bathroom that switches off the light after no motion for a few minutes. The undesirable side effect being that if you lie still in the bath you end up in the dark.

I was going to transfer the automation over to homeassistant and add a bath time switch that keeps the light on.

Will your command line switch work for this use case instead? (ie disable the sensor when someone is in the bath and re-enable afterwards?)

Thanks in advance.

It should work if you disable that motion sensor for a certain amount of time and then turn it back on.

Would it not be simpler to customize a bathroom light automation in Hass and disable that room on the hue?

Well, no, if that code works then that’s the only code I need. (8 lines)

To bring it in to homeassistant I would need either a complicated automation with templated off time/on time etc, or a combination of a couple of automations. (minimum 14 lines, probably more).

Bearing in mind that I still need to tell homeassistant it’s bath time somehow, so I can just use that switch (probably exposed to emulated_hue) and its done. Otherwise it would be an input boolean to use as a condition etc etc.

If you have Alexa or Google Home, exposing the input_boolean or switch would be one super easy way to do it. Alternatively, Dasher could be a great solution for this. Not sure if Dasher supports the PUT function as is required here, but it could turn off or on an input_boolean or switch if you had already set up the command line as noted above.

Dash buttons are $5 or cheaper (if they have a sale). Setup in Hassio is super easy, but I found the hass setup to be much more complex. Details for HASS are here:

and

Yeah, I’m trying to use fewer buttons where possible, I’ll try the switch out and see how it goes :+1:

A laudable goal, for sure. For what it’s worth, I put a 5-minute delay on restarting the motion sensor after my scene completed. I didn’t want to get out of my chair to go upstairs and immediately set off the sensor again. You may have the same issue on your end.

1 Like

HI

trying this switch it keeps flooding the log with errors, what have i missed?

motion_sensor_switch:
 friendly_name: Motion sensor switch
 command_on: curl -X PUT -d '{"on":true}' "ip/api/key/sensors/5/config"
 command_off: curl -X PUT -d '{"on":false}' "ip/api/key/sensors/5/config"
 command_state: curl ip/api/key/sensors/5/
 value_template: '{{value_json.config.on}}'

it seems to boil down to the command_state that wont stop running. tried with and without quotes. not sure if theres a solution there. Shouldn’t there be a GET in the state command?

I have done it this way:

rest_command:
    turnoffmotion:
        url: 'http://YOURIP/api/YOURTOKEN/sensors/YOURSENSORNUMBER/config'
        method: 'put'
        payload: '{"on":false}'

And then call the rest_command from a script.

Hope this helps.

1 Like

also valid indeed, thanks.
still you would need some value_template for the sensor to show in /off in the frontend.

im using this template now, reading the state of the regular sensor:

motion_sensor_switch:
  friendly_name: "Motion sensor switch"
  command_on: >-
    curl -X PUT -d '{"on":true}' "ip/api/key/sensors/5/config"
  command_off: >-
    curl -X PUT -d '{"on":false}' "ip/api/key/sensors/5/config"
#     command_state: curl ip/api/key/sensors/5/
#     value_template: '{{value_json.config.on}}'
  value_template: >-
     "{{ is_state('sensor.corridor_motion_sensor', 'on') }}"

works great. Many thanks

I tried the same for a rule. But i can’t get the state.
command_on and command_off are working.
Could anyone tell me, how to get the correct state, to toggle the switch in Home Assistant?

- platform: command_line
  switches:
    enable_disable_rule_23:
      command_on:  curl -X PUT --data '{"status":"enabled"}' "http://192.168.88.37:8080/api/xxxxx/rules/23"
      command_off: curl -X PUT --data '{"status":"disabled"}' "http://192.168.88.37:8080/api/xxxxx/rules/23"
      command_state: 'curl http://192.168.88.37:8080/api/xxxxx/rules/23'
      value_template: "{{value_json.data.status}}"
      friendly_name: Enable Disable Rule 23

I do not know about Hue rules, but for sensors the state endpoint is different from the command endpoint.
Your command_state is probably looking for state in the wrong place.

thanks for your answer.
the value_template was wrong.

value_template: "{{value_json.status == 'enabled'}}" is working.