Is it possible to use a shell_command in the 'condition' portion of an automation

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…

No this is not possible. You can not perform actions in conditions and certainly not inside jinja templates. You will have to create a sensor.

No, but you may be able do it at the top of the Actions block if your first action pulls the Response from the command and the second action is a Template condition. Something like:

actions:
  - action: shell_command.get_state_asof
    response_variable: response
    data:
      sensor: sensor.1st_floor_temperature
      timestamp: "{{ now().timestamp() - 3600 }}"
  - condition: template
    value_template: "{{ states('sensor.1st_temperature') | float(0) <= response | float(0)  }}"
....
1 Like

Ahhh that’s cool… and that is a great solution.
Thanks!