Templates in aan from to concept to trigger automation

Hello everybody!

I cannot figure out how to combine templates in a from to to trigger automation.
I want to start charging my waterheater based on an inputnumber (batt_input_number_start_autoladen) and when my solar battery (sensor.batterij_lading_int) reaches this charge, it switches a high voltage switch.
This works fine:

  trigger:
    - platform: template
      value_template: >-
        {{ states('sensor.batterij_lading_int') | int(0) ==
        states('input_number.batt_input_number_start_autoladen') | int(0) }}

BUT my problem is that I only want to trigger the automation when value is reached by ascending not by descending.
For example: my input number is 95 at the moment. Battery starts charging and when the charge changes from 94 to 95 automations starts.
Another automations shuts of the high voltage switch when water is heated.
So for example battery is still at 100%, water is heated. Night comes and battery discharges. When it changes from 96% to 95% the automation (obviously) is triggered again. And this is what I do NOT want.

Any ideas on how to do this?

P.S.: I could ofcourse use a boolean for this as an extra condition, but that feels a bit … you know

Use > instead of ==.

1 Like

In addition to using different operators, you may want to consider including a duration to avoid bouncing the relay on and off:

  triggers:
    - trigger: template
      value_template: >-
        {{ states('sensor.batterij_lading_int') | int(0) >=
        states('input_number.batt_input_number_start_autoladen') | int(0) }}
      for: "00:00:30"

Thx Sir_G, but then I would trigger it on every change of a var, not?

hi Didgeridew,
I do not think this would help me, since it is not a question of duration but of ‘direction’ of value. It can easily go from 94 to 96 in less than 30s. And when my fantastic wife is cooking all the way … the other way …
thx 4 taking the time to help me out!

You may wish to consider using a Numeric State Trigger.

  trigger:
    - platform: numeric_state 
      entity_id: sensor.batterij_lading_int
      above: input_number.batt_input_number_start_autoladen

It will trigger the moment when the sensor’s value increases and exceeds the input_number’s value. In other words, triggering occurs only when the sensor’s value crosses the threshold from below to above it.

1 Like

Thank you Taras!
Think I lost myself in the templating idea.
Just to make it perfect I made a template sensor

- platform: template
  sensors:
    batt_input_number_min_1_start_autoladen:
      value_template: "{{states('input_number.batt_input_number_start_autoladen')|int(0) -1}}"
      friendly_name: "batt_input_number_min_1_start_autoladen"

and used that with the above condition, so it matches my ui

thanks again!

1 Like