Am I overthinking / overcomplicating this automation?

I am drawing out a flow for HVAC automation. I am wondering if some of the conditions are unnecessary.

Basically what I am wanting to do…

  • if window opened, start timer
  • on event timer.finished turn off HVAC

Simple enough right? Well, here is where my brain wants to over complicate things. I’m thinking it would be a good practice NOT to send unnecessary commands. For example, if the HVAC system is already off, no need to send it a command to turn off.

Is it best practice to explicitly test for state desired before sending state?
Also, when using a timer, should I be looking at the event bus for timer.finished or entity state change? I’m trying to think ahead in case there is a random reboot or something where state may not be correct.

Here is some example yaml. Note, the ha start and automation reload are there as a protection in case something odd happens to hopefully detect the proper state.

alias: test1
description: ""
trigger:
  - platform: homeassistant
    event: start
    id: ha_start
    alias: HA Start
  - platform: event
    event_type: automation_reloaded
    alias: Automation Reload
    id: automation_reload
  - platform: state
    entity_id:
      - binary_sensor.dining_area_window_1
    to: "on"
    id: daw1_open
    alias: Dining Area Window 1 Open
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.window_hvac_timer
    alias: HVAC Timer Finished
    id: hvac_timer_finished
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: or
                conditions:
                  - condition: trigger
                    id: ha_start
                    alias: HA Start
                  - condition: trigger
                    id: automation_reload
                    alias: HA Reload
                alias: HA Start or Reload
              - condition: state
                entity_id: timer.window_hvac_timer
                state: idle
                alias: HVAC Timer Idle
              - condition: state
                entity_id: binary_sensor.dining_area_window_1
                state: "on"
                alias: Dining Area Window Open
            alias: HA Start OR Reload AND Timer Finished, Window Open
          - condition: not
            conditions:
              - condition: state
                entity_id: climate.downstairs_ecobee
                state: "off"
                alias: Downstairs Ecobee Off
        sequence:
          - service: climate.set_hvac_mode
            data:
              hvac_mode: "off"
            target:
              entity_id: climate.downstairs_ecobee
            alias: HVAC Off
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: daw1_open
                alias: Dining Area Window 1 Open
              - condition: not
                conditions:
                  - condition: state
                    entity_id: timer.window_hvac_timer
                    state: active
                    alias: HVAC Timer Active
                alias: NOT HVAC Timer Active
            alias: DAW1 Open AND Timer NOT Active
        sequence:
          - service: timer.start
            data: {}
            target:
              entity_id: timer.window_hvac_timer
            alias: Activate HVAC Timer
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: hvac_timer_finished
                alias: HVAC Timer Finished
              - condition: not
                conditions:
                  - condition: state
                    entity_id: climate.downstairs_ecobee
                    state: "off"
                    alias: Downstairs Ecobee Off
                alias: Downstairs Ecobee NOT Off
            alias: HVAC Timer Finished AND HVAC NOT Off
        sequence:
          - service: climate.set_hvac_mode
            data:
              hvac_mode: "off"
            target:
              entity_id: climate.downstairs_ecobee
            alias: HVAC Off
mode: single

As far as whether all the conditions are strictly “necessary” I guess that all depends on your level of fault tolerance.

Is it a big deal that an “off” command is missed on a probably rare occasion?

What is likely to fail?

The timer will (now…finally…) survive a restart so that won’t be an issue.

(now…finally…I think…) reloading automations will only reload the automation you changed so this automation won’t get reloaded every time. So that likely won’t ever be an issue.

How often do you restart HA? and what are the chances of the window opening or timer finishing at the exact time that HA restarts? it could happen but not likely.

And again if those very unlikely things happen and the HVAC doesn’t get turned off automatically is it that big of a deal? what did you do before HA when you wanted to turn it off? :grinning_face_with_smiling_eyes:

And I personally think this is probably a good candidate for using two automations - one to start the timer and one to turn off the HVAC. Especially if you do decide that you need to keep all of the checks in place.

Some people are too compulsive in thinking that they have to use one automation when doing so overcomplicates things and makes it hard to read and more importantly maintain later.

But you also have two choices where the action is the same. you could probably combine both of those into one. which will help with the complication.

Bottom line is that it’s all pretty much personal preference.