I would like the action « Get last state » to evolve into « Get state » with an option allowing to specify whether you want the last state, or the state recorded in the device’s history some time ago (for example 10 minutes ago, or 1 hour, or 24 hours, …).
Concretely, this would simplify scenes where you want to set up behavior depending on a sensor’s variation over a certain period. For example: trigger an alert if the rainwater tank level has dropped by more than 5% in 30 minutes (because that can indicate a leak or a tap left slightly open).
Today, (but there may be a simpler way, I’m open to suggestions…) you need to create a dummy MQTT device, and trigger a scene regularly that stores the sensor’s « last state » value in the MQTT device, then wait 30 minutes, then retrieve the « last state » value again and compare the two values.
It works well, but it’s not intuitive to have to create an MQTT device for that…
I would imagine something like this:
I’m rereading this mockup and I find that the phrase « L’état le plus proche après : » is ambiguous.
I think that « L’état historisé il y a… » would be clearer. And the note will become « Clarification: it’s the first state recorded after that instant that will be returned. If the device has no history, it will therefore be the last state. »
I’m also interested in that, but I’d go even further by having the inverse as well: retrieving the date when a state had a certain value. For example what is the last date my tank was filled to 100% 
@Nagromdark I understand the need you describe, but I think this is clearly a different feature request. I suggest you make a separate request. And it seems to me that you’ll need to specify two aspects :
- what should be returned by this action if there is no date at which the value you’re looking for was reached
- should the returned date be the standard numeric value in computing (it’s the number of seconds since 1/1/1970)? Or the number of seconds between that date and now? Or a date in a text format? But in that case how should it be formatted? Because honestly, in computing, a date is a pain to define properly
…
Thanks for your reply, yes indeed the dates are a pain, I’ll make a separate request.
Thanks for your suggestion @StephaneB, I already had the same need!
One thing to watch out for is how the historical value is retrieved.
Suppose your sensor sends a value every 15 seconds. What should the stored state « 30 minutes ago » correspond to? The value closest to « H-30min »?
Could it be simpler by indicating « the previous value », or « the last state between and »?
Suppose again that your sensor didn’t send anything for 1 hour (interference, battery failure, Gladys restart, etc.). How should you react? Stop the scene?
In any case, that would make it easier for me to perform certain calculations like in your case, for example to know if the temperature is increasing or decreasing too quickly.