Hue Motion restful sensor switch problem

Hello, I’ve created a couple of restfull switches so I can control my hue motion sensors and turn them on or off whenever I need to. Up until yesterday I had no issues. But this morning I noticed one of the switches is no longer working.

I didn’t change a thing in my config or hue bridge.

This is my config:

switch:
  - platform: rest
    name: woonkamer_sensor_motion #Switch om de motion sensor aan of uit te zetten
    resource: "https://<Hue-Bridge-IP>/api/<API-KEY>/sensors/104"
    body_on: '{"config": {"on": true}}'
    body_off: '{"config": {"on": false}}'
    is_on_template: "{{value_json.config.on}}"
    method: PUT
    headers:
      Content-Type: application/json
    verify_ssl: false
  - platform: rest
    name: keuken_sensor_motion #Switch om de motion sensor aan of uit te zetten
    resource: "https://<Hue-Bridge-IP>/api/<API-KEY>/sensors/138"
    body_on: '{"config": {"on": true}}'
    body_off: '{"config": {"on": false}}'
    is_on_template: "{{value_json.config.on}}"
    method: PUT
    headers:
      Content-Type: application/json
    verify_ssl: false
  - platform: rest
    name: atelier_sensor_motion #Switch om de motion sensor aan of uit te zetten
    resource: "https://<Hue-Bridge-IP>/api/<API-KEY>/sensors/109"
    body_on: '{"config": {"on": true}}'
    body_off: '{"config": {"on": false}}'
    is_on_template: "{{value_json.config.on}}"
    method: PUT
    headers:
      Content-Type: application/json
    verify_ssl: false
  - platform: rest
    name: hal_sensor_motion #Switch om de motion sensor aan of uit te zetten
    resource: "https://<Hue-Bridge-IP>/api/<API-KEY>/sensors/99"
    body_on: '{"config": {"on": true}}'
    body_off: '{"config": {"on": false}}'
    is_on_template: "{{value_json.config.on}}"
    method: PUT
    headers:
      Content-Type: application/json
    verify_ssl: false
  - platform: rest
    name: bijkeuken_sensor_motion #Switch om de motion sensor aan of uit te zetten
    resource: "https://<Hue-Bridge-IP>/api/<API-KEY>/sensors/153"
    body_on: '{"config": {"on": true}}'
    body_off: '{"config": {"on": false}}'
    is_on_template: "{{value_json.config.on}}"
    method: PUT
    headers:
      Content-Type: application/json
    verify_ssl: false

This is the switch that is no longer working:

  - platform: rest
    name: bijkeuken_sensor_motion #Switch om de motion sensor aan of uit te zetten
    resource: "https://<Hue-Bridge-IP>/api/<API-KEY>/sensors/153"
    body_on: '{"config": {"on": true}}'
    body_off: '{"config": {"on": false}}'
    is_on_template: "{{value_json.config.on}}"
    method: PUT
    headers:
      Content-Type: application/json
    verify_ssl: false

This is what i’m seeing in the log :

2020-10-27 09:46:19 ERROR (MainThread) [homeassistant.components.rest.switch] Got non-ok response from resource: 503

Any idea on how to figure ou what the problem is?

I suspect that there is an issue with the sensor, can you use a browser to see what it is returning?

Maybe it just needs a quick click of the reset button with a pin (just to nudge it, rather than to reset it to pairing mode). But see what you’re actually getting back from it first as it may give you a better idea.

This is the response I’m getting from the API debug tool
Seems to be working fine.

{
	"state": {
		"presence": false,
		"lastupdated": "2020-10-27T09:10:35"
	},
	"swupdate": {
		"state": "noupdates",
		"lastinstall": "2020-10-25T08:24:52"
	},
	"config": {
		"on": true,
		"battery": 90,
		"reachable": true,
		"alert": "none",
		"sensitivity": 1,
		"sensitivitymax": 2,
		"ledindication": false,
		"usertest": false,
		"pending": []
	},
	"name": "Bijkeuken sensor",
	"type": "ZLLPresence",
	"modelid": "SML001",
	"manufacturername": "Signify Netherlands B.V.",
	"productname": "Hue motion sensor",
	"swversion": "6.1.1.27575",
	"uniqueid": "00:17:88:01:04:b5:7c:5b-02-0406",
	"capabilities": {
		"certified": true,
		"primary": true
	}
}

I’ll try a soft reset when I get back home.

To be fair that looks normal so I can’t really see a reason why your rest switch wouldn’t work :man_shrugging:

dont want to take away from your restful setup, but after a lot, and I mean a lot of experimenting and trial and error switching the Hue motion sensors from HA, I finally ended up with a foolproof setup that has been working steady as a rock for over 2 years. The rest platform is a platform Ive learned the hard way causing a lot of trouble in the setup, so Ive replaced that as much as possible with the command_line platform.

also for these switches:

switch:

  - platform: command_line
    switches:

      library_sensor_motion:
        friendly_name: Library motion sensor switch
        command_on: >
          curl -X PUT -d '{"on":true}' "http://192.168.1.212/api/dredactedq/sensors/20/config/"
        command_off: >
          curl -X PUT -d '{"on":false}' "http://192.168.1.212/api/dredactedq/sensors/20/config/"
        command_state: curl http://192.168.1.212/api/dredactedq/sensors/20/
        value_template: >
          {{value_json.config.on}}

all you have to do is find the correct sensor number and you’re set (but you have these already of course)

btw, as of late I sometimes see a single sensor not being connected in HA, always when being ‘off’ as sensor in Hue. Which really shouldn’t matter.

1 Like

Thanks! I’ve had no issues with the switches, apart from the one no longer working.

I’ll give your command line approach a go. Maybe it brings back my dead switch.