Numeric state below/above input number for set time

Hi All,
I have this challenge of which I actually did not expect it to be a challenge.
The thing I want is to have a numeric state trigger that triggers on a value below or above a value of a helper value (input_number) for a certain time.

The first part is easily done with a relatively simple template trigger, for example:

{{ states('sensor.power')|int > states('input_number.slider_1')|int }}

The challenge is to have it work like a numeric state so you can basically say “state above value X for Y time”. I expected to be able to use the template option, but a manually entered value in above/below is required.

Is there anyone that:

  1. knows if the template is also part of the for condition (my test did not confirm that)?
  2. knows if it is part of, what is the correct syntax?
  3. has another way of achieving this goal?

What about

automation:
  trigger:
    platform: template
    value_template: "{{ states('sensor.power')|int > states('input_number.slider_1')|int or states('sensor.power')|int < states('input_number.slider_1')|int }}"
    for:
      minutes: "{{ states('input_number.minutes')|int(0) }}"

Take a look at https://www.home-assistant.io/docs/automation/trigger/#template-trigger

2 Likes

:blush: I guess i was so focused on the numeric state that I just didn’t think of looking at the docs of template…

Sorry and thank you! It works like a charm!

1 Like