Automation triggering when condition changes

Hello, I have this automation that alerts me if the patio door is left open AND there is a two or more degree temperature difference between inside the house and the outside temperature

...
  trigger:
    - platform: state
      entity_id: binary_sensor.patio_door_sensor
      to: 'on'
      for:
        seconds: 65
  condition:
    condition: state
    entity_id: binary_sensor.temp_delta_greater_than_two_degrees_inside_outside
    state: on
...


However, if the door is left open when the temp delta between outside and insider was less than two degrees but an hour passes and now the temp delta is greater than two degrees. The problem is the trigger is already in the ‘on’ state so the automation never fires again.

What’s a better way to address this issue?

I’ve never done this, but could your condition be numeric state with a value template? There are a lot of examples in the docs.

Have you considered running the automation every X minutes and having both of the binary sensors be conditions. This will force the automation to trigger. It can be resource intensive if the interval between triggering is small. I think every 5 minutes and you will be fine.

This may not give the desired results based on what your actions are doing. It will ensure that the automation will run every 5 minutes and execute actions when both conditions are true.

Use two State Triggers, one for each binary_sensor, and conditions to confirm:

  1. The temperature binary_sensor is on.
  2. The door binary_sensor is on.
  3. The door binary_sensor has been on for at least 65 seconds.
  trigger:
    - platform: state
      entity_id: binary_sensor.patio_door_sensor
      to: 'on'
      for:
        seconds: 65
    - platform: state
      entity_id: binary_sensor.temp_delta_greater_than_two_degrees_inside_outside
      to: 'on'
  condition:
    - "{{ is_state('binary_sensor.temp_delta_greater_than_two_degrees_inside_outside', 'on') }}"
    - "{{ is_state('binary_sensor.patio_door_sensor', 'on') }}"
    - "{{ (now() - states.binary_sensor.patio_door_sensor.last_changed).total_seconds() >= 65 }}" 
1 Like

@123 Thx, Let me test this.

Edit. Tested works. Thx