Automation that turns a device on, then off based on condition, did I do it right?

Thank you, the template was interesting to see. Much more efficient than UI and it does the same thing. I thought the template had to be added via YAML but realized that it can be done in the UI. However, the template, because it does the same, would not resolve the issue that I encountered:

Consider this: The fan is on and the door is open. I turn off the fan. That activates the trigger with the set heat_cool string. When it gets to conditions, as soon as the automation sees the balcony door open (as part of the “or” condition), the action will fire to set the heat_cool.

This is what I did to solve the problem: By adding AND conditions to the elements that are responsive to heat_cool with a “triggered by”, I was able to isolate those triggers and keep them from firing the action unintentially.

Here is the modified configuration:

condition:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: state
            entity_id: switch.attic_fan
            state: "on"
          - condition: trigger
            id:
              - "off"
      - condition: and
        conditions:
          - condition: state
            entity_id: binary_sensor.balcony_door_contact
            state: "on"
          - condition: trigger
            id:
              - "off"
      - condition: and
        conditions:
          - condition: state
            entity_id: switch.attic_fan
            state: "off"
          - condition: state
            entity_id: binary_sensor.balcony_door_contact
            state: "off"

It’s working great now. Thank you very much, @123. I could not have done this without your help!

1 Like