I want a script that lives on a Linux machine to push values to my home assistant instance.
For example, I have a value for uptime in minutes. Because of a weird configuration issue on my end, I want this to get pushed to HA instead of using some uptime integration.
I can do something like this with hass-cli:
hass-cli state edit input_number.uptime_from_linux 450
The issue is that the input_number gets edited and clobbers the unique_id, pretty name, units, icon, etc.
Did I miss an easier way to push a value to an existing sensor without editing away all the meta data?
I would use a webhook. You create an automation in Home assistant to process the data and store it where you want it, and e.g. use curl to send the data. See the docs about webhook triggers and how to supply data:
I like the hass-cli interface. I don’t really like using the webhook, because I have to set up an automation to call a service to change the input number for each thing I want to change. The webhook would work, but it seems like more steps.
What did work though (which came from that suggestion) is to use the hass-cli to call a service input_number.set_value. This sets the value only, instead of setting the whole state:
cli service call input_number.set_value --arguments entity_id=input_number.server_uptime,value=$UPTIME
With regard to webhooks: You seem to forget that service calls are fully templatable. So if you also set a template for the service itself and for the entity id and data. With that you could create one webhook automation to do pretty much anything.
The only thing is I would not open the webhook to the outside, because automations can do too much - if any one learns how to use the webhook you are very vulnerable.
The upside of the webhook is that you do not need any specific software installed to call it. But you seem to have found a similar way with the cli. It pretty much amounts to the same thing.