I can create an input helper from a bash script like this:
#!/bin/bash
ha_url="https://ha.local"
ha_token="my_longlived_token"
# Create an input_boolean "foo" with friendly name "Foo helper" and sets the state to "on"
curl -X POST \
-H "Authorization: Bearer ${ha_token}" \
-H "Content-Type: application/json" \
-d '{"state": "on", "attributes": {"friendly_name": "Foo helper"}}' \
"$ha_url"/api/states/"input_boolean.foo"
I can then update the state using the same script by replacing āstateā: āonā with āstateā: āoffā.
However, I seem unable to change the state from within Home Assistant, I can see the toggle on my dashboard and within the āhelpersā page, but when I toggle it from its current state it reverts back again.
Is this expected behaviour? Is there a way to stop it?
If I create the input helper from within Home Assistant itself, rather than via the API, I can change it freely in the dashboard and via the API.
Thatās because you didnāt actually make an input helper. The API you are using simply allows you to set state. It takes an id and a state to set and adds it to the state machine with that id. The state machine is basically just a giant hash map for that API, no integration will manage or update the state of entities you create with it.
The domain you use is irrelevant there. Just because you picked input_boolean doesnāt make it an input boolean. Itās not handled by that integration, itās just a state. It canāt be updated in the UI, added to an area, canāt set its name in the UI and wonāt be restored after restart (i.e. the things you would expect a properly made input boolean to do).
That API primarily exists so that you can manually change the state of an entity in the developer tools tab. I wouldnāt recommend it for regular use. You should use the UI to make helpers.
PS They donāt get deleted when HA restarts, I cant figure out how to delete them. They are not in the ā.storageā directory so Iām guessing they are orphaned in the HA database.
Huh thatās strangeā¦ Do they actually appear in the UI in the states tab of developer tools? Or do you mean that they still appear in the db?
History is still kept in the db even if it is orphaned because the entity it is removed. Records are only removed when they are older then purge_keep_days. So if thatās what you mean then thatās to be expected. But they shouldnāt show up in the UI after restartā¦