Help with setting up an automation

Hi everyone first time posting here. Started transitioning a couple days ago from another platform to Home Assistant. With many trials and errors i’m mostly done. I’m having trouble with an automation though, possibly needing 2 automations to achieve what I’m looking for.

Here is what I’m trying to do.

If any of the 3 doors in my garage open I want them to trigger the light switch on. Here is what I have for names.

Garage door 1 - binary_sensor.main_garage_door_sensor

Garage door 2 - binary_sensor.3rd_stall_door_sensor

Garage door 3 - sensor.garage_entry_status

After all 3 doors have been closed for at least 15 minutes I want the light switch to turn off.

The switch name is - light.garage_lights

If anyone can help me achieve this I’d be really grateful. I don’t want to have to go back to the old system.

Bryan

Hi, I’m a complete noob, but I have had great success with NodeRed. I have an insanely over engineered setup for 2 window AC units as my initial project.

With that said, I think this would be a total breeze in NodeRed. Basically you can check the current status of each garage door, and decide to turn the light on or off.

If you are interested, take a look at getting it installed via the add-on store, it integrates very nicely.

I assume the binary sensors will be “on” when the corresponding door is open and “off” when closed. That’s the typical meaning.

But what about sensor.garage_entry_status? How does it indicate when the door is open & closed?

The easiest way to do this is to use two automations.

The first would trigger on any of the sensors changing to “open” and would turn on the light.

The second would use a template trigger that fires when all of the doors are closed with a “for” option that makes sure it has been that way for 15 minutes.

I’d do this in 2 parts:
1 automation that triggers when doors open
1 automation that triggers when doors close
1 script that waits for 15 min and switches the light off.

Automations:

alias: Garage - Door Opens
  trigger:
  - platform: state
    entity_id: binary_sensor.main_garage_door_sensor, binary_sensor.3rd_stall_door_sensor, sensor.garage_entry_status
    to: "on"
  condition:
  - condition: state
    entity_id: light.garage_lights
    state: 'off'
  action:
  - service: script.turn_off
    data:
      entity_id: script.garage_lights_timed_off
  - service: light.turn_on
    data:
      entity_id: light.garage_lights

alias: Garage - Door Closes
  trigger:
  - platform: state
    entity_id: binary_sensor.main_garage_door_sensor, binary_sensor.3rd_stall_door_sensor, sensor.garage_entry_status
    to: "off"
  condition:
  - condition: state
    entity_id: binary_sensor.main_garage_door_sensor
    state: 'off'
  - condition: state
    entity_id: binary_sensor.3rd_stall_door_sensor
    state: 'off'
  - condition: state
    entity_id: binary_sensor.garage_entry_status
    state: 'off'
  - condition: state
    entity_id: light.garage_lights
    state: 'on'
  action:
  - service: script.turn_on
    data:
      entity_id: script.garage_lights_timed_off

Script:

garage_lights_timed_off:
  alias: 'Garage Lights Timed Off'
  mode: restart
  sequence:
    - delay:
        minutes: 15
    - service: light.turn_off
      data:
        entity_id: light.garage_lights

Notes:

  • I assumed a typo on the garage_entry_status and handled it as a binary_sensor
  • Requires 0.113 or higher
  • This is untested. In case it doesn’t work, it should give you an idea on what needs to be done
  • The script’s mode: restart is not technically needed since the script gets turned off when you open one door… more info on script modes here

So the garage_entry_status is from the code in my sensors.yaml. Maybe it’s not the best way to do this?

  • platform: template
    sensors:
    garage_entry_status:
    value_template: ‘{% if is_state(“sensor.garage_entry_door_alarm_level”, “0”) %}Closed{% else %}Open{% endif %}’
    friendly_name: ‘Garage Entry Door Status’

I’ll check out node red I hadn’t heard of this, thank you.

replace your template with a binary_sensor template:

binary_sensor:
  - platform: template
    sensors:
      garage_entry_status:
        friendly_name: "Garage Entry Door Status"
        value_template: >-
          {{ state("sensor.garage_entry_door_alarm_level") != "0" }}

I’ll try these out, thanks for the replies everyone!

So I’m trying this code and cannot get the code to validate. I get an error Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 12).

Something is not right. If you’ve defined your sensors to be in the sensors.yaml file, you can’t then define a binary sensor in it…

So should I put that code in the configuration.yaml instead of sensors.yaml?

You can only define one instance of binary_sensor
Under that (I suspect already existing) binary_sensor header in your config, just add the bit that you have under binary_sensor from above screenshot

Thanks lolouk44!

This got my 90% of the way there. After changing a few things I was able to get it functioning the way I needed it to. I never got the script to work correctly. When it would trigger the script it would never turn the light off. I was able to solve it using some extra parameters in your automation script instead.

cool. If you could post your final solution, it may help others…

Absolutely, there are probably cleaner ways to do this but with my limited knowledge of this software and coding in general this is what I did to accomplish it.

automations.yaml

- id: '1596997853339'
  alias: Garage - Door Opens
  trigger:
  - entity_id: binary_sensor.main_garage_door_sensor, binary_sensor.3rd_stall_door_sensor
    platform: state
    to: 'on'
  - entity_id: sensor.garage_entry_door_alarm_level
    platform: state
    to: '255'
  condition:
  - condition: state
    entity_id: light.garage_lights
    state: 'off'
  action:
  - data:
      entity_id: script.garage_lights_timed_off
    service: script.turn_off
  - data:
      entity_id: light.garage_lights
    service: light.turn_on
  mode: single
- id: '1596997889371'
  alias: Garage - Door Closes
  trigger:
  - entity_id: binary_sensor.main_garage_door_sensor, binary_sensor.3rd_stall_door_sensor
    platform: state
    to: 'off'
  - entity_id: sensor.garage_entry_door_alarm_level
    platform: state
    to: '0'
  condition:
  - condition: state
    entity_id: binary_sensor.main_garage_door_sensor
    state: 'off'
  - condition: state
    entity_id: binary_sensor.3rd_stall_door_sensor
    state: 'off'
  - condition: state
    entity_id: sensor.garage_entry_door_alarm_level
    state: '0'
  - condition: state
    entity_id: light.garage_lights
    state: 'on'
  action:
  - delay: 
      minutes: 15
  - data:
      entity_id: light.garage_lights
      transition: 5
    service: light.turn_off
  mode: single

scripts.yaml

'1596998387401':
  alias: Garage Lights Timed Off
  mode: restart
  sequence:
  - delay: '00:15'
  - service: light.turn_off
    data:
      entity_id: light.garage.light
      transition: 5

And then this one was just to have a status indicator showing open or closed instead of On/Off 0/254 etc…

sensors.yaml

- platform: template
  sensors:
    garage_entry_status:
      friendly_name: "Garage Entry Door Status"
      value_template: '{% if is_state("sensor.garage_entry_door_alarm_level", "0") %}Closed{% else %}Open{% endif %}'

Like I said probably an ugly more complicated way of doing it but couldn’t get the other way to work properly. The script would turn the lights on but the lights would never turn off unless I manually did it.

Thanks again for everyones help!