Changing state of light

Dear community,

I’m working on getting my home assisant work with curl-scripts. I want to POST a JSON-string where I can turn my light on. I use the following line in a bash file:

curl -X POST -H "Authorization: Bearer ABCDEF" -H "content-type: application/json" -d " {\"state\": \"on\"}" http://xxx.xxx.xxx.xxx:8123/api/states/switch.light_tl

In the home assisstant you can actually see the script is working (the slider turns on) but when I execute the script the light won’t turn on. Is there something wrong with my curl command?

Thanks for the help in advance,

If you want to use Home Assistant’s REST API to turn on a light then you need to use a service call (services/switch/turn_on). What you are doing is setting the switch’s state which is not the same thing.

The relevant section of the documentation is here

Example:

curl -X POST -H "Authorization: Bearer ABCDEFGH" \
       -H "Content-Type: application/json" \
       -d '{"entity_id": "switch.light_tl"}' \
       http://xxx.xxx.xxx.xxx:8123/api/services/switch/turn_on