When I open the main gate or one of the garage doors, a yard light gets turned on. When it’s turned on, a timer is started. When the light is turned off, the timer gets cancelled, otherwise the timer runs out and the light will be turned off.
My very strange scenario is that when the gate gets opened, there are three triggers of my automation and one of them reports to be turning off the light, even though that action isn’t referenced.
How is it possible for that middle logbook entry to have happened?
Automation that turns on the light and starts a timer:
- alias: "Switch On Front Door Light When Any Cover Opened"
id: "2f00ee50-2203-4ba6-a6f2-37052dfba07e"
initial_state: true
trigger:
platform: state
entity_id:
- cover.main_gate
- cover.garage_doors_lhs
- cover.garage_doors_rhs
to: "open"
mode: queued
condition:
- condition: and
conditions:
- condition: or
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
- condition: state
entity_id: light.front_door
state: "off"
action:
- service: script.turn_on
target:
entity_id: script.turn_on_light_and_timer
data:
variables:
light: light.front_door
duration: "00:03:00"
The script used above:
script:
turn_on_light_and_timer:
description: "Turn on a light and its corresponding timer"
fields:
light:
description: "A light entity"
example: "light.my_light"
duration:
description: "A duration in %H:%M:%S format"
example: "00:03:00"
mode: single
sequence:
# https://www.home-assistant.io/docs/scripts/conditions/
- service: light.turn_on
target:
entity_id: "{{ light }}"
- service: timer.start
target:
entity_id: "{{ light | replace('light.', 'timer.') }}_timer"
data:
duration: "{{ duration }}"
Automation that turns off a light when the corresponding timer has run out:
- alias: "Switch Off Light When Timer Expires"
id: "23c86717-220f-4d56-b67c-d19e2f171836"
initial_state: true
trigger:
# same entities as for "Stop Light Timer If Running When Light Turned Off"
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.living_room_lamp_timer
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.front_door_timer
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.foyer_timer
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.kitchen_counter_timer
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.scullery_counter_timer
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.hallway_timer
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.bedroom_bedlamp_timer
mode: parallel
action:
- service: light.turn_off
data:
entity_id: "{{ trigger.event.data.entity_id | replace('_timer', '') | replace('timer', 'light') }}"
Definition of my cover, in case that’s helpful:
cover:
- platform: template
covers:
main_gate:
friendly_name: "Main Gate"
device_class: gate
open_cover:
# https://community.home-assistant.io/t/cover-template-open-close/248449
- condition: state
entity_id: binary_sensor.main_gate_gate_status
state: "off"
- service: switch.turn_on
data:
entity_id: switch.main_gate_remote
close_cover:
- condition: state
entity_id: binary_sensor.main_gate_gate_status
state: "on"
- service: switch.turn_on
data:
entity_id: switch.main_gate_remote
stop_cover:
service: switch.turn_on
data:
entity_id: switch.main_gate_remote
# true (on) means open
value_template: "{{ is_state('binary_sensor.main_gate_gate_status', 'on') }}"
icon_template: >-
{%- from 'security.jinja' import get_cover_icon -%}
{{ get_cover_icon('binary_sensor.main_gate_gate_status', 'binary_sensor.main_gate_alert', 'mdi:gate') }}
availability_template: "{{ not is_state('binary_sensor.main_gate_gate_status', 'unavailable') }}"