I need a sensor that I can change value on by contacting the Home-Assistant API. But I can’t se any good way to do this.
The most relevant I have found:
input_number: But I don’t want the values to be changed in the UI. http_sensor: But it is not permanent, I need somthing that don’t get deleted after each start.
You need to setup an mqtt server that houses it. If you have hassio, it’s pretty simple. If you use hassbian, it can get complicated if you don’t know what you’re doing. As for the sensor, the topic for it will persist so the sensor will persist through shutdowns.
EDIT: Looks like the last one crashed the system on first POST.
File "uvloop/loop.pyx", line 2591, in subprocess_shell
File "uvloop/loop.pyx", line 2563, in __subprocess_run
File "uvloop/handles/process.pyx", line 595, in uvloop.loop.UVProcessTransport.new
File "uvloop/handles/process.pyx", line 130, in uvloop.loop.UVProcess._init
OSError: [Errno 9] Bad file descriptor
I think you’re confusing entities and the State Machine.
The State Machine contains representations of the current state of the entities in the system. However, it can also contain anything. I.e., you can write a “state” to the State Machine that has nothing to do with a real entity. In fact, if you want to write something there, it’s better not to have it correspond to a real entity, because as you’ve discovered, the entity will overwrite what you just wrote (at some point.)
Basically, you can “make up” an entity_id and write (or update) its state in the State Machine, and that will cause a state_changed event just like when real entities update. The only rules (that I’m aware of) is that an entity_id should be a string containing one and only one period/dot, and otherwise contain only letters, numbers or underscores. (Preferably each “half” of the entity_id should start with a letter, and all letters should be lower case.) And the state string (or when converted to a string) must be no longer than 255 characters.
I would recommend you use an entity_id of “sensor.XXX” where XXX is some unique “object ID”.
EDIT: Having said all that, the states in the State Machine are not restored after a restart by themselves. They need to be written there again by something. For real entities, that’s typically done by the recorder (for some types of entities) or by the entities being updated shortly after restart (by their usual periodic update mechanism, etc.)
If you’re looking for something that will retain the state, then other suggestions made already might suit you better. I was just trying to clarify the difference between HA’s State Machine (which entities and the HA API write to), and “real” entities. Hopefully I didn’t just confuse you more.