How to reset the value to false before calculating the template

Hi everybody!

This is my trigger:

platform: template
value_template: >-
  {{  (states('sensor.2_13_it_box_temperature') | float(0) -
  states('sensor.2_7_sred_komn_temperature') | float(0)) > 20 }}

It passes when the value changes from false to true. But I would like to check this every time from the beginning, that is, before checking, I need to reset some variable where “true” already lies. How can I do it?

Please clarify what you are trying to do.

OK. I have two thermometers. One of them hangs on the wall, another is in the box with equipment, fans and filters. When the filters are dusty, the differense between this sensors is more then 20, the trigger sets, and automation script sends me message “wash the filters” and disables itself. Another script enables first script averyday at 6:00:00, and I want it to retest condition of filters. But the condition ia already “true” and trigger can’t pass for the second time

Post the automation and script configurations… it sounds like you have made this more complicated than it needs to be.

alias: Запуск проверки фильтров IT box
description: ""
trigger:
  - platform: time
    at: "05:00:00"
condition: []
action:
  - service: automation.turn_on
    metadata: {}
    data: {}
    target:
      entity_id:
        - automation.proverka_filtrov_it_box
mode: single
alias: Проверка фильтров IT box
description: ""
trigger:
  - platform: template
    value_template: >-
      {{  (states('sensor.2_13_it_box_temperature') | float(0) -
      states('sensor.2_7_sred_komn_temperature') | float(0)) > 20 }}
    for:
      hours: 0
      minutes: 0
      seconds: 3
condition: []
action:
  - service: notify.old
    metadata: {}
    data:
      message: Помой фильтры на  ITшном ящике
  - service: notify.lena
    metadata: {}
    data:
      message: Помой фильтры на  ITшном ящике
    enabled: false
  - service: automation.turn_off
    metadata: {}
    data:
      stop_actions: true
    target:
      entity_id:
        - automation.proverka_filtrov_it_box

To clarify, is this what you want?:

  1. As soon as the difference between the temp sensors exceeds 20deg, issue a notification, regardless of the time of day.
  2. If the temperature difference still exists at 05:00, then issue another notification, and keep repeating this notification every day at 05:00 until the issue is fixed.

If so, you just need one automation, and you need to repeat the template as a trigger and as a condition:

alias: Запуск проверки фильтров IT box
description: ""
trigger:
  - platform: time
    at: "05:00:00"
  - platform: template
    value_template: >-
      {{  (states('sensor.2_13_it_box_temperature') | float(0) -
      states('sensor.2_7_sred_komn_temperature') | float(0)) > 20 }}
    for:
      hours: 0
      minutes: 0
      seconds: 3
condition:
  - condition: template
    value_template: >-
      {{  (states('sensor.2_13_it_box_temperature') | float(0) -
      states('sensor.2_7_sred_komn_temperature') | float(0)) > 20 }}
action:
  - service: notify.old
    metadata: {}
    data:
      message: Помой фильтры на  ITшном ящике
  - service: notify.lena
    metadata: {}
    data:
      message: Помой фильтры на  ITшном ящике
    enabled: false
mode: single

Unfortunately you cannot have a for: key in the condition, so if that is really important to you, you would need to create a template binary sensor in YAML with the setting delay_on: 3, and then use that new binary sensor in a state trigger and state condition in the automation, instead of the template trigger and template condition. Alternatively you could do something with a delay or a wait_for_trigger in the actions section but that is kind of a hack.

1 Like

Yes, you understood my idea correctly. And Yes, your variant works correctly. Thank you very much!

“For” is just some kind of anti-rattle from sensor values, but I think will be no rattle because battery-powered zigbee thermosensors are very lazy and it will no any random fluctuations.

Thank you!

Keep in mind that if the 3 second debounce on the template trigger isn’t long enough, you will receive repeated notifications as the temperature difference fluctuates above and below 20deg. If this is a slowly changing system, and nothing critical happens at exactly 20deg (i.e. you could change the threshold to 21deg or 19deg and the automation would be equally as effective), then I would suggest you change the trigger for: setting to a few minutes as opposed to 3 seconds.

The absence of the debounce in the conditions probably won’t affect you much; unless it is fluctuating around that 20deg delta and it happens to be greater than 20deg at 05:00. And in that case you’d just get 2 notifications, one at 05:00 and another once it has holds steady above 20deg for longer than the debounce.

As a quick and dirty solution, you can also add a lengthy delay (5 minutes?) as the last step in the actions. Since the automation mode is set to single it is not possible to trigger the automation while it is already running. So if it runs and sends you a notification, the delay at the end will prevent another trigger and notification for the next 5 minutes. However restarting HA will abort any running automation so keep that in mind.

Initially this timeout was 1 hour, but I temporaty made it 3 secs for debugging purpose. Anyway i will play with this a little, maybe I’ll remove it at all.

1 Like