I’m trying to setup an automation based on binary sensor input from my Envisalink panel and the alarm door sensors. What I want to do is to set the thermostats to away mode if any of the doors are left open for more than 2 minutes. I think the code below will work to set it to away mode (based on another automation that I have working) but I know it can be collapsed further than this.
automation 7:
- alias: Set Climate to Away Mode If front door is open
trigger:
platform: state
entity_id: binary_sensor.front_door
state: 'on'
for:
minutes: 2
action:
service: climate.set_away_mode
data:
entity_id: group.climate
away_mode: true
- alias: Set Climate to Away Mode if living room door is open
trigger:
platform: state
entity_id: binary_sensor.living_room_door
state: 'on'
for:
minutes: 2
action:
service: climate.set_away_mode
data:
entity_id: group.climate
away_mode: true
So my questions are as follows. How can I collapse the above code further to include even more door sensors into fewer lines of code? Multiple entity_IDs? Then, how do I create the script to resume the thermostat schedule? I know this command resumes my thermostats but I had this activated using an input_boolean for my “vacation mode”. Thanks in advance for the help!
The first part of my code works but I need some help with my restore script and the conditions. How would I use a condition of either of my two thermostats being away_mode: on to then resume schedule on my thermostat after the door closes again? Below is what I have tried but this gives me a config error. away_mode: on is listed in the attributes of the thermostats.
- alias: Restore Climate After Doors Are Closed
trigger:
platform: state
entity_id: binary_sensor.mudroom_door
to: 'off'
for:
minutes: 1
condition:
condition: or
conditions:
- condition: state
data:
entity_id: climate.downstairs
away_mode: on
- condition: state
data:
entity_id: climate.upstairs
away_mode: on
action:
service: climate.set_hold_mode
data:
entity_id: group.climate
hold_mode: None
Got this working and here’s the code if anyone else needs it. Probably not the cleanest I am sure but it does work. I created a template switch for the resume schedule function just to see that it was working quickly in the interface.
- alias: Set Climate to Away Mode if doors are left open
trigger:
- platform: state
entity_id: binary_sensor.mudroom_door
state: 'on'
for:
minutes: 2
- platform: state
entity_id: binary_sensor.living_room_door
state: 'on'
for:
minutes: 2
- platform: state
entity_id: binary_sensor.master_door
state: 'on'
for:
minutes: 2
- platform: state
entity_id: binary_sensor.front_door
state: 'on'
for:
minutes: 2
action:
service: climate.set_away_mode
data:
entity_id: group.climate
away_mode: true
- alias: Restore Climate After Doors Are Closed
trigger:
- platform: state
entity_id: 'binary_sensor.living_room_door'
to: 'off'
- platform: state
entity_id: 'binary_sensor.master_door'
to: 'off'
- platform: state
entity_id: 'binary_sensor.front_door'
to: 'off'
- platform: state
entity_id: 'binary_sensor.mudroom_door'
to: 'off'
condition:
condition: and
conditions:
- condition: state
entity_id: 'binary_sensor.living_room_door'
state: 'off'
- condition: state
entity_id: 'binary_sensor.master_door'
state: 'off'
- condition: state
entity_id: 'binary_sensor.front_door'
state: 'off'
- condition: state
entity_id: 'binary_sensor.mudroom_door'
state: 'off'
- condition: state
entity_id: switch.climateaway
state: 'on'
action:
service: homeassistant.turn_off
entity_id: switch.climateaway