Hey,
im searching for a way to control ha entitys from my desktop pc. Maybe sth like log into ha via ssh and send a command to turn off a switch. A alternative would be to control it via selenium in a python script but i hope for a simpler solution.
Im not really shure if i search for the right things but everything i get when i search for “ssh, terminal, entity, control…” is the “command line switch”.
I’m not sure what the use case is but that doesn’t sound really that much different than opening a web page on that PC (HA usual Lovelace dashboard) and clicking the already provided switch there.
Alternatively, I know there is an API that is provided by HA itself that you can use but I’ve never used it so I don’t have any info on it.
Controlling it in the browser via selenium would work but i dont like it since i have to redo everything when i change sth in the ui. I saw the API but i dont know how to work with it REST API | Home Assistant Developer Docs .
curl -X POST -H "Authorization: Bearer ABCDEFGH" \
-H "Content-Type: application/json" \
-d '{"state": "25", "attributes": {"unit_of_measurement": "°C"}}' \
http://localhost:8123/api/states/sensor.kitchen_temperature
How would i translate the example to a switch.turn_on named Switch_1?
EDIT:
curl -k -X POST -H "Authorization: Bearer MyGeneratedToken" -H "Content-Type: application/json" -d '{"entity_id": "switch.light2"}' https://XxX.duckdns.org/api/services/switch/turn_on
Should be the way to go but i always get a “401: Unauthorized”.
I copied the Token only partially…
curl -k -X POST -H "Authorization: Bearer MyGeneratedToken" -H "Content-Type: application/json" -d '{"entity_id": "switch.light2"}' https://XxX.duckdns.org/api/services/switch/turn_on
Works now.