#Can you access historical data in templates?

1 messages · Page 1 of 1 (latest)

coarse turret
#

No. You need to use an SQL sensor

hexed cedar
#

Or depending on your use case, use a trigger-based template sensor to store the value when it happens.
For example if you want to know what the value of a sensor was last Monday at midnight, you can either:

Create an sql sensor to look up that value in the recorder database

Or

Create a template sensor that triggers every Monday at midnight and sets its state to that value.

limber flume
#

Does this require installing e.g. mysql?

#

I want to do similar to create a derivative sensor for the water level in my sump pit.

#

I'd need to get the last few timestamp/value pairs

limber flume
#

I am trying to match the states table on entity_id of my sensor but nothing in that table seems to have an entity id

fierce oriole
#

you get entity id by looking up metadata_id <-> entity_id in states_meta

limber flume
#

dare i ask why there's a an entity_id column?

fierce oriole
#

probably legacy

#

the table has been through many revisions

limber flume
#

i don't suppose you can tell me how to write a join?

#

i haven't done much sql for a while

fierce oriole
#

not off top of my head

limber flume
#

select state, count(*) from states left join states_meta on (states_meta.metadata_id = states.metadata_id) where states_meta.entity_id = ... seems to work