Hi,
I am trying to write a python script that fetches data from Home Assistant’s REST API. I have tried to follow the instruction at REST API | Home Assistant Developer Docs.
I’m trying to send data from a sensor connected to a Raspberry Pi to HA. I know that using an ESP32 and ESPhome would be easier, but this RPi is already there doing other stuff and has the sensor in question…
To get started, I tried switiching a light on and off:
from requests import post
url = "http://192.123.123.123:8123/api/services/switch/toggle"
headers = {
"Authorization": "Authorization: Bearer ...",
"content-type": "application/json",
}
data = '{"entity_id": "switch.feather_esp32v2_latching_relay"}'
response = post(url, headers=headers, data=data)
print(response.text)
The REST API calls work using the Flic app, so I’m pretty sure that I have all that correct. The response I get, however, is “401 Unauthorized”. Not sure what I’m doing wrong.
Assuming someone can point me in the right direction regarding the Unauthorized issue, how would I go about writing a number into an entitie’s state (in this case it’s a lux value)?