Custom Entity / State in Home Assistant#
Warning
🔥 highly experimental stuff here 😅
Idea: Instead of using Baby Buddy [1], create an entity named baby
and set its state accordingly, i.e. one of
sleep
eat
drink
piss
shit
play
Create the Entity#
Settings > Devices & Services > Helpers > Template
template a sensor
Name:
baby
State template: the literal string
idle
Get API Key#
/profile
> Security > Long-lived access tokens: Create Token
name: e.g.
felix@locutus
Set State via REST API#
https://developers.home-assistant.io/docs/api/rest/
TOKEN=
curl \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"state": "sleep"}' \
http://localhost:8123/api/states/sensor.baby
Sources#
how create a fake sensor to store state https://community.home-assistant.io/t/rest-api-and-unique-id/177788/10
workaround using
python_scripts
(that I reduced to its essentials) https://community.home-assistant.io/t/how-to-manually-set-state-value-of-sensor/43975/3
Next Steps#
reduce duplication (jinja for-loop)
get name from button (if that’s even possible)
think of / find something better than this hack ;)