Get the value of a sensor at a specific time

Hi

I would like to get the state of a sensor at a specific historical time. I can see it in the graph in the UI, but would like to have an automation based on this.
Example: what was the value of the sensor 3 hours ago?

I searched a lot but couldn’t find anything…

Thanks
Cadish

1 Like

This post here will help.

Thanks a lot @petro! Will try this…

Anyway, it’s strange that to have it in an easier way is not a wanted feature for a lot of people.

Oddly enough, not many people want this. I think I’ve seen ~4 posts over the past 4 years.

1 Like

Does seem like a odd use case. What automation would you want triggered specifically at a 3hr past moment in time?otherwsie historical values can be seen in the log charts, or grafana.

My use case: I have a Zigbee light that defaults to ON after every power failure. Now I want to create an Automation to switch off the light after the power failure was resolved. BUT, I only want it to happen if the light was OFF before the power failure occurred. Thus, I want to query the light’s state at the time just before the power failure occurred and if it was off, then the light must be switched off by the automation.

Hi,

do you get a solution. I want to switch back my devices after a power failure to the old state but I get it not running.

Thanks, Steffen

You can use an “input select” for this, without the query:
Set the value, “on”, “off”, “dimmed” or whatever, based on events and create an automation that triggers on change of the “input select” and sets e.g. scenes.
When the power is back on again execute the automation and you’re good.
Also handy when you want to activate another scene temporarily, e.g. as action on a motion event and go back to the previous state after.

1 Like

Thought i would add my use case for being able to retrieve a historic sensor value: i have a humidty sensor in my shower. When the humidity spikes at a certain rate, i assume the shower is being used, and switch the air ventilation system to a higher value. I would like to be able to retrieve the value of the humidity sensor just before the spike starts, so that when the value drops to (close to that) pre-spike-value, i switch the air ventilation back to a lower gear. I now have it run 30 minutes at the high capacity, but maybe often times that is too long, wasting energy, or maybe sometimes it is to short.

I will see whether i can solve it with SQL - Home Assistant and Sensor state 24 h ago - #13 by alfwro13

Make it 5 now. I’m seeing an errant value being displayed in a historical graph and the manufacturer wants ME to dig up the discrete value to prove it’s their problem, not an HA problem.

Another use case would be to notify me if my propane tank got filled.

If sensor.propane(-15min) - sensor.propane(-2hr) > 25 then send notification

I don’t want an alert to be sent when my propane goes from 25% to 50%, I want an alert sent once my propane guy is done filling the tank (which he will fill to 80%), hence historical values would be valuable.

You can use the derivative integration to do that.