Using state from past in automation


I can’t find anything related to that (Problably my fault), but I can’t figure if it’s possible to retrieve the state of a sensor in the past.

What I want to do is create an automation that sends me each evening if my house is hotter or colder than yesterday.

I’ve been playing with templating and I did not found anything regarding querying through history.

Is there something I’m missing? Is there another way to do what I want to do? (Have a template_sensor that records only the sensor temperature at a given hour?)

If you are using nodered this is quite easy with “get history” node.
It uses the home asistant API.


can be used, with history api direct from an automation. You setup a rest command then that will gives you a new service rest_command.<the_name_of_your_rest_command> that you will be able to call from an automation. (you’ll need an long lived access token that you can get from your profile page on frontend, it will replace the ABCDEFGH in my example)
Example :

    url: http://localhost:8123/api/history/period/?filter_entity_id=sensor.temperature
    method: GET
      authorization: 'Bearer ABCDEFGH'
      content-type: 'application/json'

This example will get the state of sensor.temperature 1 day ago.

1 Like

I don’t have nodered, but i’ll try the restful_command and let you know.


you can have an automation, triggered at any time you decide you need it, eg daily at 23.59, to record the value you want using the custom_component variable, and see/use the history of that value.

That’s smart too, thanks. The only problem with that is that it does not work if the automation fails for whatever reason.

I’m giving nodered a try actually, so far it seems really promising

1 Like

Triggering an automation at 23:59 without further conditions will never fail…
No reason to fear that.

For sure nodered will do the job for this particular case and much more again !