What is wrong with my automation

All,

Please help with my below code - I can’t get it debugged.
Basically what I want to do is the following:
When I am home and before 21:00 and one of my 3 windows is open for longer then 10minutes I want to switch off the heating.
If all the windows are closed again, I want to switch on the heating again.

- alias: "Climate - Window Open For 10 Minutes"
  trigger:
    - platform: time
      minutes: '/10'
  condition:
    - condition: state
      entity_id: input_select.dieter_status
      state: 'Home'
    - condition: time
      before: '21:00'
    - condition: or
      conditions:
        - condition: state
          entity_id: binary_sensor.kitchen_window_120
          state: 'on'
        - condition: state
          entity_id: binary_sensor.sitting_window_109
          state: 'on'
        - condition: state
          entity_id: binary_sensor.tv_room_window_110
          state: 'on'
  action:
    - service: climate.set_away_mode
      data:
        entity_id: climate.kitchen
        away_mode: 'true'
    - wait_template: "{{ states.binary_sensor.kitchen_window_120.state == 'off' and states.binary_sensor.sitting_window_109.state == 'off' and states.binary_sensor.tv_room_window_110.state == 'off'}}"
    - service: climate.set_away_mode
      data:
        entity_id: climate.kitchen
        away_mode: 'false'
- alias: "Climate - Window Open For 10 Minutes"
  trigger:
    - platform: state
      entity_id:
          - binary_sensor.kitchen_window_120
          - binary_sensor.sitting_window_109
          - binary_sensor.tv_room_window_110
      to: 'on'
      for:
        minutes: 10

  condition:
    - condition: state
      entity_id: input_select.dieter_status
      state: 'Home'
    - condition: time
      before: '21:00'
  
  action:
    - service: climate.set_away_mode
      data:
        entity_id: climate.kitchen
        away_mode: 'true'
    - wait_template: "{{ states.binary_sensor.kitchen_window_120.state == 'off' and states.binary_sensor.sitting_window_109.state == 'off' and states.binary_sensor.tv_room_window_110.state == 'off'}}"
    - service: climate.set_away_mode
      data:
        entity_id: climate.kitchen
        away_mode: 'false'
1 Like

It works, big thanks!

Cool, the only thing I don’t like is the wait template to turn the climate back on once they close.

It works but if you restart HA during that wait your climate maybe left off as the turn on never executes. You might want to set another automation that runs at 9pm and turns on the climate if you are home just to catch that situation.

Hi jwelter, thanks for the suggestion.

At this moment I have programmed below:

  • Climate off when Entering Sleeping / Away / Vacation Mode
  • Climate on when entering Home Mode
  • Climate off when in home mode and during a working week and at 21:00 (I go to bed at 22:00 during a working week :slight_smile: )
  • Climate off when in home mode and a window opens for more then 10min
  • Climate on when in away mode and during a working week and at 16:00

Now you just need the automation to take a picture of Santa coming in through the window :santa:

Merry Christmas!

Merry Christmas to you too!
Thanks for the help the last couple of days!

@jwelter any suggestions for my below problem :slight_smile:

I am making notifications.
I already have notifications when I an away and a door or a window opens.
But now I also want to have notifications when I am leaving and a door or a window is still open.
I have 11 window/door sensors.
Temporarily I made 11 Automation Notifications as per below, but I was hoping to combine all of them to one automation, that only sends one notification with a list of all window/door sensors that have been left open.

- alias: "Notification Text - Bath Room Window Left Open Leaving Home Mode"
  initial_state: true
  hide_entity: true
  trigger:
    - platform: state
      entity_id: input_select.dieter_status
      from: 'Home'
  condition:
    - condition: state
      entity_id: binary_sensor.bath_window_113
      state: 'on'
  action:
    - service: notify.pushbullet
      data_template:
        title: "Home Assistant"
        message: 'Bath Room Window Has Been Left Open.'

Here’s a snipped from a script I use to check for open doors when we leave home. You can adapt if for your windows…

########################################################
## Door check
########################################################
doors_closed:
  alias: Doors Closed

  sequence:
    - condition: state
      entity_id: group.all_doors
      state: 'on'
  
    - wait_template: "{{ is_state('script.notify_ios_engine' , 'off') }}"
 
    - service: script.notify_ios_engine
      data_template:
        message: >- 
          {%- set open_doors = states | selectattr('entity_id', 'in', state_attr('group.all_doors','entity_id')) | selectattr('state','in',['on','open']) | map(attribute='name') | list -%}
          {%- if open_doors | length == 1 -%}
            The {{ open_doors[0] }} door is open.
          {%- else -%}
            The {{ open_doors[:-1] | join(' door, ') }}{{' door,' if open_doors | length > 2 else ' door'}} and {{ open_doors[-1]}} door are open.
          {%- endif -%}
        who: "family"

It works! Thanks!

Would this command be possible to limit to a certain group of switches. e.g. If I would make a group “DownStairs Switches” that I can execute a command to only turn off those switches.

- service: switch.turn_off
  data_template: 
    entity_id: >- 
      {{ states.switch | selectattr('state','eq','on') | map(attribute='entity_id') | join(',') }}

Thanks.