Home Assistant REST API Access Data

It’s actually fairly easy to control Home Assistant remotely using curl but I couldn’t find a complete solution on how to do this, so here goes…

  Activate the api in configuration.yaml by adding the line api:
  Get an Authorization token from HA (It's a Long-Lived Access Tokens which can be created on your HA user profile page)
  This list of exposed states can be found using curl -X GET -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" http://YOUR_IP:8123/api/states | prettyjson

  Note prettyjson is an alias for python -m json.tool, you don't need this it's just easier to read.

  To get the state of a device append the entity.id to the URL, eg curl -X GET -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" http://YOUR_IP:8123/api/states/switch.mylight | prettyjson
  The API documentation shows you how to change the states but this does not actually turn on the lights, etc. Instead, use the services. First find the correct service and the domain with curl -X GET -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" http://YOUR_IP:8123/api/services | prettyjson
  For the switch domain there are toggle, turn_on and turn_off on my system. To turn the switch on use curl -X POST -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" -d '{"entity_id": "switch.mylight"}'http://YOUR_IP:8123/api/services/switch/turn_on | prettyjson

curl -H “Authorization: Bearer TOKEN” -H “Content-Type: application/json” https://YOUR.DOMAIN/api/states/sensor.SENSOR_NAME | jq