And Automation not working

I am new at this with almost no programming skills. I have created two separate automations. There are a total of 12 windows.

I am trying to create an automation that will:

  1. Switch the air conditioner mode to “off” when any window is opened or left open. (I have accomplished this).

  2. Switch the air conditioner back to “cool” when all/every window is closed. My attempt at this one does not seem to function.

This is a copy of automation 2:

alias: Allow A/C to Run After Windows Are Closed
description: End Whole House Fan Operation
trigger:

  • platform: state
    entity_id: binary_sensor.master_toilet_window
    from: ‘On’
    to: ‘Off’
    condition:
  • condition: and
    conditions:
    • condition: state
      state: ‘off’
      entity_id: binary_sensor.master_shower_tub
    • condition: and
      conditions:
      • condition: state
        entity_id: binary_sensor.back_bathroom_patio
        state: ‘Off’
      • condition: and
        conditions:
        • condition: state
          entity_id: binary_sensor.back_bedroom_sliding
          state: ‘Off’
        • condition: and
          conditions:
          • condition: state
            entity_id: binary_sensor.dining_room_window
            state: ‘Off’
          • condition: and
            conditions:
            • condition: state
              entity_id: binary_sensor.master_patio_window
              state: ‘Off’
            • condition: and
              conditions:
              • condition: state
                entity_id: binary_sensor.living_room_window
                state: ‘Off’
              • condition: and
                conditions:
                • condition: state
                  entity_id: binary_sensor.master_front_window
                  state: ‘Off’
                • condition: and
                  conditions:
                  • condition: state
                    entity_id: binary_sensor.master_bathroom_sliding
                    state: ‘Off’
                  • condition: and
                    conditions:
                    • condition: state
                      entity_id: binary_sensor.wetbar_sliding_patio
                      state: ‘Off’
                    • condition: and
                      conditions:
                      • condition: state
                        entity_id: binary_sensor.front_bedroom_sliding
                        state: ‘Off’
                      • condition: and
                        conditions:
                        • condition: state
                          entity_id: binary_sensor.kitchen_window_left
                          state: ‘Off’
                          action:
  • service: climate.set_hvac_mode
    target:
    device_id: d050031c984183e50190c27f79659d37
    entity_id: climate.american_standard_heat_pump
    area_id: main_house
    data:
    hvac_mode: cool
    mode: single
    max: 10

Any help and or suggestions are greatly appreciated!

Thanks

You REALLY need to format your code correctly for the forum. Especially for that one.

edit your post above and put three backticks (```) on the line before and on the line after your code block.

You can likely reduce the code significantly by getting rid of all those “condition: and” lines. But it’s hard to tell if that’s the only problem because we can’t see the actual formatting of your existing code.

Sorry for that error with leaving out the back ticks. I created this automation with “visual editor” then opened it with “YAML” to post it here.

Before I posted it as code this site warned me to add the tick marks. I am not seeing the option for back tick marks on my iphone keyboard, so I clicked on the “post it anyway” button.

Also, any extra code words in there were from the visual editor to YAML translation I suppose.

Thanks

I hope this is helpful.

alias: Allow A/C to Run After Windows Are Closed
description: End Whole House Fan Operation
trigger:
   - platform: state
      entity_id: binary_sensor.master_toilet_window
      from: 'On'
      to: 'Off'
condition:
   - condition: and
      conditions:
         - condition: state
            state: 'off'
            entity_id: binary_sensor.master_shower_tub
         - condition: and
            conditions:
               - condition: state
                  entity_id: binary_sensor.back_bathroom_patio
                  state: 'Off'
               - condition: and
                  conditions:
                     - condition: state
                        entity_id: binary_sensor.back_bedroom_sliding
                        state: 'Off'
                     - condition: and
                        conditions:
                           - condition: state
                              entity_id: binary_sensor.dining_room_window
                              state: 'Off'
                           - condition: and
                              conditions:
                                 - condition: state
                                    entity_id: binary_sensor.master_patio_window
                                    state: 'Off'
                                 - condition: and
                                    conditions:
                                       - condition: state
                                          entity_id: binary_sensor.living_room_window
                                          state: 'Off'
                                       - condition: and
                                          conditions:
                                             - condition: state
                                                entity_id: binary_sensor.master_front_window
                                                state: 'Off'
                                             - condition: and
                                                conditions:
                                                   - condition: state
                                                      entity_id: binary_sensor.master_bathroom_sliding
                                                      state: 'Off'
                                                   - condition: and
                                                      conditions:
                                                         - condition: state
                                                            entity_id: binary_sensor.wetbar_sliding_patio
                                                            state: 'Off'
                                                         - condition: and
                                                            conditions:
                                                               - condition: state
                                                                  entity_id: binary_sensor.front_bedroom_sliding
                                                                  state: 'Off'
                                                               - condition: and
                                                                  conditions:
                                                                     - condition: state
                                                                        entity_id: binary_sensor.kitchen_window_left
                                                                        state: 'Off'
action:
   - service: climate.set_hvac_mode
      target:
         device_id: d050031c984183e50190c27f79659d37
         entity_id: climate.american_standard_heat_pump
         area_id: main_house
      data:
         hvac_mode: cool
mode: single
max: 10

Much better. Thank you.

Conditions are AND by default so all you need is:

condition:
  - condition: state
    entity_id: binary_sensor.master_shower_tub
    state: 'off'
  - condition: state
    entity_id: binary_sensor.back_bathroom_patio
    state: 'off'
  - condition: state
    entity_id: binary_sensor.back_bedroom_sliding
    state: 'off'
  - condition: state
    entity_id: binary_sensor.dining_room_window
    state: 'off'
  - condition: state
    entity_id: binary_sensor.master_patio_window
    state: 'off'
  - condition: state
    entity_id: binary_sensor.living_room_window
    state: 'off'
  - condition: state
    entity_id: binary_sensor.master_front_window
    state: 'off'
  - condition: state
    entity_id: binary_sensor.master_bathroom_sliding
    state: 'off'
  - condition: state
    entity_id: binary_sensor.wetbar_sliding_patio
    state: 'off'
  - condition: state
    entity_id: binary_sensor.front_bedroom_sliding
    state: 'off'
  - condition: state
    entity_id: binary_sensor.kitchen_window_left
    state: 'off'

This requires all the sensors to be off for the condition to be true and allow the actions to occur.

Also take care with the case of your states. Off is not the same as off.

1 Like

Thank you!
I will make the changes, test it out and reply back here .

I have made these changes to the automation. It’s still not able to bring the A/C unit back into “Cool” mode.

alias: Allow A/C to Run After Windows Are Closed (Duplicate)
description: End Whole House Fan Operation
mode: single
trigger:
   - platform: state
      entity_id: binary_sensor.master_toilet_window
      to: 'off'
      from: 'on'
condition:
   - condition: state
      entity_id: binary_sensor.master_shower_tub
      state: 'off'
   - condition: state
      entity_id: binary_sensor.back_bathroom_patio
      state: 'off'
   - condition: state
      entity_id: binary_sensor.back_bedroom_sliding
      state: 'off'
   - condition: state
      entity_id: binary_sensor.dining_room_window
      state: 'off'
   - condition: state
      entity_id: binary_sensor.master_patio_window
      state: 'off'
   - condition: state
      entity_id: binary_sensor.living_room_window
      state: 'off'
   - condition: state
      entity_id: binary_sensor.master_front_window
      state: 'off'
   - condition: state
      entity_id: binary_sensor.master_bathroom_sliding
      state: 'off'
   - condition: state
      entity_id: binary_sensor.wetbar_sliding_patio
      state: 'off'
   - condition: state
      entity_id: binary_sensor.front_bedroom_sliding
      state: 'off'
   - condition: state
      entity_id: binary_sensor.kitchen_window_left
      state: 'off'
action:
   - service: climate.set_hvac_mode
      target:
         device_id: d050031c984183e50190c27f79659d37
         entity_id: climate.american_standard_heat_pump
         area_id: main_house
      data:
         hvac_mode: cool
max: 10

If I hit the “Run Actions” button in the automation, it does switch to “Cool” mode. I realize that this is not a true test of the whole automation but I do have a connection to the A/C unit.

I created the whole automation over from scratch. Tested the new version and found that it is working so far. Thanks for the help!

This is the latest version that works:

alias: Allow A/C to run when all windows close
description: ''
trigger:
   - platform: state
      entity_id: binary_sensor.kitchen_window_left
      from: 'on'
      to: 'off'
condition:
   - condition: state
      entity_id: binary_sensor.wetbar_sliding_patio
      state: 'off'
   - condition: state
      entity_id: binary_sensor.master_toilet_window
      state: 'off'
   - condition: state
      entity_id: binary_sensor.master_shower_tub
      state: 'off'
   - condition: state
      entity_id: binary_sensor.back_bathroom_patio
      state: 'off'
   - condition: state
      entity_id: binary_sensor.back_bedroom_sliding
      state: 'off'
   - condition: state
      entity_id: binary_sensor.dining_room_window
      state: 'off'
   - condition: state
      entity_id: binary_sensor.dining_room_window
      state: 'off'
   - condition: state
      entity_id: binary_sensor.master_patio_window
      state: 'off'
   - condition: state
      entity_id: binary_sensor.living_room_window
      state: 'off'
   - condition: state
      entity_id: binary_sensor.master_front_window
      state: 'off'
   - condition: state
      entity_id: binary_sensor.master_bathroom_sliding
      state: 'off'
   - condition: state
      entity_id: binary_sensor.front_bedroom_sliding
      state: 'off'
action:
   - service: climate.set_hvac_mode
      target:
         area_id: main_house
         device_id: d050031c984183e50190c27f79659d37
         entity_id: climate.american_standard_heat_pump
      data:
         hvac_mode: cool
mode: single