HTTP binary sensor not working

Hello,

I am struggling with the HTTP binary sensor. In the documentation it says, the binary sensor will be created upon the first REST API call. Doing so by cURL, however, always results in {“message”: “Entity not found”} for me. Here is my cURL line:

curl -X GET -H "x-ha-access: XXX" -H "Content-Type: applicaton/json" -d '{"state": "on", "attributes": {"friendly_name": "REST_SW"}}' http://192.168.1.100:8123/api/states/binary_sensor.REST_SW

In my config.yaml I have frontend enabled. home-assistant version 0.69.1

What is it I am doing wrong? Other REST API calls are working fine.


PS: What I am trying to accomplish is to use the REST API to trigger an automation. Within the automation I am listening on any state change of the HTTP Binary Sensor.

- id: rest_api_sw_test
  alias: rest_api_sw_test
  trigger:
    platform: state
    entity_id: binary_sensor.REST_SW
  action:
    - service: light.toggle
      entity_id: light.kitchen

Is this the proper way to do it?

You use GET to retrieve the sensor’s state. To generate the binary sensor and change its state you have to use POST:

curl -X POST ...

On a different note, entity IDs are always lower-case. In this particular case it does not seem to matter when you specify the entity ID in upper-case in the curl call, but I wouldn’t count on that an upper-case entity ID works in an automation trigger. So better go with binary_sensor.rest_sw.

1 Like

Thank you!
Sometimes it only takes to not remember the difference between POST and GET to be wondering what is going on for a couple of hours… :disappointed_relieved:

Not it works. :star_struck:

1 Like