History sensor

How can I obtain the value of a sensor in history (i.e. 10 minutes ago)?

Use an SQL sensor.

SELECT state FROM states WHERE entity_id = 'sensor.your_sensor_here' AND MINUTE(TIMEDIFF(UTC_TIMESTAMP(), last_updated))>=10 ORDER BY last_updated DESC LIMIT 1


This is the SQL query I use… make sure to set state for the column value.

SELECT state from states 
WHERE entity_id = 'sensor.YOUR_SENSOR' 
AND last_updated <= datetime('now','-10 minutes') 
ORDER BY last_updated DESC LIMIT 1;

Keep in mind that, depending on the update frequency of your sensor and other factors, this may not be a 100% accurate reflection of the actual situation you are measuring. Since your database won’t necessarily have a value saved exactly 10 minutes ago you need to use “>=” or “<=” to get one of the closest values.

Thank you for this tip, it worked for me.