How to update a sensor in home assistant using an external script

I am planning on using google apps script to sent a post request using the home assistant API to update a sensor with the value of a cell in google sheets whenever that cell is updated as it may not be always updated. I know how to do this already in google apps script to send a post request and I also know how to use the RESTful API for home assistant as I do this with my ios shortcuts. However, I am unsure what sensor type to use for this purpose. The template sensor requires a template filled and the RESTful sensor type seems to actually be the one doing the post requests. I want my google sheets to be the one that sends the update not the other way around.

See HTTP Sensor.

Basically, use the HA API to set the state of a sensor and just make up a sensor name.

Thanks! That’s exactly what I needed and even if it gets erased I can always try to do an api request at least once a day to push new data.

Will this still be part of the recorder for history purposes. Do you know?

AFAIK it should be. I can’t think of a reason it wouldn’t be (unless you specifically excluded it.)

Yea that’s what I thought was just curious. Thanks!

1 Like

One more question here that is slightly off topic, but do you know how to create an empty switch? Like one that doesn’t send an mqtt message, but one that I can use to compare against when doing an automation. I want a switch that is for a visitor ble tag activation it will be activated or not so ON or OFF, and based on that another template sensor will be either showing the house empty or not empty

Not 100% following you, but if you want an entity that shows up in the UI, and that can be on or off, that the user can change via the UI, or an automation can change, and can be seen/used in automations, etc., then check out input_boolean.

I think this is exactly what I needed. I will try it out!

1 Like