I would like to write an automation condition that checks if the temperature now is less than or equal to the temperature 60 minutes ago.
I tried the following condition:
conditions:
- condition: template
value_template:
"{{ (states('sensor.1st_temperature') | float) <=
(shell_command.get_state_asof('sensor.1st_floor_temperature', (now() - timedelta(minutes=60)).timestamp()) | float) }}"
Where get_state_asof
is a shell command that takes a sensor
and a timestamp
and returns the last value of the state of the sensor
up to and including the timestamp
time.
Note that the shell command get_state_asof
basically runs a sqlite command to return the last value of state
up to and including timestamp
. The shell command works perfectly when I use it in an action
. I just don’t know how to use it in an automation condition
Note I am doing this to avoid having to create another sensor to track the history of the sensor. But if there is a simple way to do what I am trying to do, I am all ears…