Automation - trigger if sensor above variable input_number

Hello,
I am trying to use a input_number as a trigger but i can not use the input_number.
Is the syntax wrong or should i use the template trigger below?

autmations:

  • alias: co_wert_ueberschritten
    trigger:
    • platform: numeric_state
      entity_id: sensor.co_gehalt_am_arduino
      above: 140
      #above: {{states.input_number.schwellwert_co.state | int }}
      action:
    • service: notify.Pushbullet
      data:
      title: “CO Wert zu hoch”
      message: “C0 Wert ist zu hoch: ‘{{states.sensor.co_gehalt_am_arduino.state }}’ ppm”

this way works not too:

  - alias: co_wert_ueberschritten
    trigger:
      -platform: template      
       value_template: "{{ states('input_number.schwellwert_co')| int > states('sensor.co_gehalt_am_arduino') |int }}"
    action:  
      - service: notify.Pushbullet
        data:
          title: "CO Wert zu hoch"
          message: "C0 Wert ist zu hoch: '{{states.sensor.co_gehalt_am_arduino.state }}' ppm"

What I would do is trigger on just a state change of the sensor and then have a condition that checks the sensor value against the input_number, since above: can’t have a template in it. Your second automation I think would work if you changed it so that the sensor is checked against the input_number, in other words reverse it like so …{{ states(‘sensor.co_gehalt_am_arduino’)| int > states(‘input_number.schwellwert_co’) |int }}

Thanks, it works :slight_smile:

this is the code:

Co & C02 Werte überstiegen

  • alias: co_wert_ueberschritten
    trigger:
    platform: template
    #value_template: “{{ states(‘input_number.schwellwert_co’)| int > states(‘sensor.co_gehalt_am_arduino’) |int }}”
    value_template: “{{ states(‘sensor.co_gehalt_am_arduino’) |int > states(‘input_number.schwellwert_co’)| int}}”
    action:
    • service: notify.Pushbullet
      data:
      title: “CO Wert zu hoch”
      message: “CO Wert ist zu hoch: ‘{{states.sensor.co_gehalt_am_arduino.state }}’ ppm”

screen schwellwerte

I have similar problem, but for me nothing is working correctly if I’m using input_number:

So my code for variable:

input_number:
    variable_kabinet_prizgi_klima:
      name: Nivo vklopa
      min: 16
      max: 32
      step: 0.5
      unit_of_measurement: "°C"

and my code for automation:

# Prižgi KLIMA - KABINET: Če je temperaturni senzor več kot 23 stopinj
- id: '1502'
  alias: KABINET - prižgi KLIMA
  trigger:
#    platform: numeric_state
#    entity_id: sensor.kabinet_t
#    above: '23'
    platform: template
    value_template: “{{ states('sensor.kabinet_t')|int > states('input_number.variable_kabinet_prizgi_klima')|int }}”
    for:
      hours: 0
      minutes: 15
      seconds: 0
  condition:
      - condition: numeric_state
        entity_id: sensor.zunaj_t
        above: '4'
  action:
    - service: climate.set_temperature
      entity_id: climate.melcloud_XXX_9999999
      data:
        temperature: '19'
    - service: climate.set_fan_mode
      entity_id: climate.melcloud_XXX_9999999
      data:
        fan_mode: 'Speed Auto'
    - service: climate.set_hvac_mode
      data:
        entity_id: climate.melcloud_XXX_9999999
        hvac_mode: 'cool'
    - service: climate.set_swing_mode
      entity_id: climate.melcloud_XXX_9999999
      data:
        swing_mode: 'Swing'
    - service: notify.simon
      data:
        message: "KABINET - vklop klime (hlajenje)."
        title: "KLIMA VKLOP"

Do anybody know what I’m doing wrong?

If I’m using above function which is #, then all is working normally…

This is how it looks…

The quotes look wrong in your value template.

If you run Config Check, does it report any errors for your automation?

No… everything is fine in Config Check. Quotes are not the problem… I’m using similar with input_datetime and it’s working fine:

image

Code:

platform: template
value_template: "{{ states('sensor.time') == (states.input_datetime.variable_zunaj_prizgi_led_zjutraj.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"

So what is the wrong with syntax…?

I will try to change from:

value_template: “{{ states('sensor.kabinet_t')|int > states('input_number.variable_kabinet_prizgi_klima')|int }}”

to:

value_template: "{{ states('sensor.kabinet_t')|int < states('input_number.variable_kabinet_ugasni_klima')|int }}"

And we will see if this will fix the problem…

Nop, nothing helps… If I triger manual it’s working or if it’s static below value, but with value_template it’s not working…

So what should be wrong with there lines?

    platform: template
    value_template: "{{ states('sensor.kabinet_t') | int < states('input_number.variable_kabinet_ugasni_klima') | int }}"

hmm… anybody knows?

Or how to use in other way to replace static value:

    platform: numeric_state
    entity_id: sensor.kabinet_t
    below: '20'

Is the problem in “for” statement? If yes, how to use that in value_template…

It works because when you trigger an automation manually, it skips trigger and condition and just executes the action.

Yes, the problem is somewhere in “for” condition under trigger… So I need to make teplate_value to be conditioned with time value…

I tested your code using a door sensor and everything worked.

- alias: A Test Automation
  initial_state: on
  trigger:
    platform: template
    value_template: "{{ states('binary_sensor.visonic_mct_340_e_0b3e4322_1_1280') == 'off' }}"
    for:
      hours: 0
      minutes: 5
      seconds: 0
  condition:
      - condition: numeric_state
        entity_id: sensor.office_lux_sensor
        above: '4'
  action:
    - service: script.slack_ha_channel
      data_template:
        message: >
          The Office LUX is {{ states.sensor.office_lux_sensor.state }}

Are you sure your value_template is staying true for 15 minutes? Have you run it through the template in Developer Tools? Perhaps reduce the for from minutes to seconds to test.

The problem was, that I tried to use directly, so not via binary_sensor.

Sensor via input_number…


# SCHRACK - prižgi VENTILATOR (več kot 25)
    variable_kabinet_prizgi_schrack_ventilator:
      name: Nivo vklopa
      min: 15
      max: 30
      step: 0.1
      unit_of_measurement: "°C"

I solve problem via binary_sensor.

# SCHRACK ventilator - prižgi/ugasni
  - platform: template
    sensors:
      schrack_prizgi_ventilator_boolean:
        friendly_name: "SCHRACK - prižgi ventilator (stanje)"
        icon_template: mdi:gate-and
        value_template: "{{ states('sensor.schrack_t') | int > states('input_number.variable_kabinet_prizgi_schrack_ventilator') | int }}"

And then via binary sensor I trigger automation…

# Prižgi SCHRACK ventilacijo - KABINET: Če je temperaturni senzor več kot 25 stopinj
- id: '3001'
  alias: SCHRACK - prižgi VENTILATOR
  trigger:
#    platform: numeric_state
#    entity_id: sensor.schrack_t
#    above: '25'
    platform: template
    value_template: "{{ is_state('binary_sensor.schrack_prizgi_ventilator_boolean', 'on') }}"
    for:
      hours: 0
      minutes: 15
      seconds: 0
  condition:
      - condition: state
        entity_id: switch.schrack_fan
        state: 'off'
      - condition: state
        entity_id: binary_sensor.schrack_ugasni_ventilator_boolean
        state: 'off'
  action:
    service: switch.turn_on
    entity_id: switch.schrack_fan  # Use the actual name of your switch here

And now it’s working…

Now that you are simply monitoring the state of a binary_sensor, you can use a State Trigger:

  trigger:
    platform: state
    entity_id: binary_sensor.schrack_prizgi_ventilator_boolean
    to: 'on'
    for: '00:15:00'

EDIT
For future reference, in recent versions of Home Assistant, for accepts a template (should you need it).