How to take a value of sensor from history?

Hello guys!
Ive got temperature sensors that return value every minute via MQTT

How can I return a value from history e.g. 1 hour before now?

Need somethink like that:
{{ states.sensor.temperature | (now() - timedelta( hours = 1 )) }}

The promblem looks simple, but i cant find a solution)

1 Like

Should be possible with:

Thanks, Ill try to, just thought that it could be done without integrations.

Maybe this will be of use? history_stats

I tried it, but I don’t know the syntax how to connect the sensor and history

Added to configuration.yaml:

sensor:

  • platform: sql
    queries:
    • name: sstate
      query: β€œSELECT * FROM states WHERE entity_id = β€˜sensor.temperature’ ORDER BY state_id DESC LIMIT 1;”
      column: β€œstate”

Now I can call it by {{ states('sensor.sstate') }} Trying to select past values via SQL

If it could be done by using API (GET /api/logbook/)
so it must be internal variable to do the same.

1 Like