So, this automation triggers 3 lights based on 2 motion sensors and gives the lights a random color and the brightness of the adaptive lighting sensor. That works. The issue : If the motion sensor turns on, you walk by, and 3 seconds later you walk by again, the motion sensor again flips from off to on and thus triggering this automation again, changing the lights colors. I thought to be smart to add a condition : If lights are off, then run the automation, but that breaks the entire flow because it’s in restart mode, so than the condition fails and the lights are never turned off.
Any tips?
why don’t you either change the mode to something other than restart or you could add a condition that the automation hasn’t been triggered for x amount of time before it can run the actions again?
I have two motion sensors and 1 switch to trigger basement bar lighting. This is how I did it.
alias: Bar Lights - Turn on and off based on stairwell light and motion sensors.
description: Turn on and off all the lights in the bar area by motion or switch
trigger:
- id: 'bar_on'
platform: state
entity_id: binary_sensor.bar_stairwell_motion_sensor_motion
from: 'off'
to: 'on'
- id: 'bar_on'
platform: state
entity_id: binary_sensor.bar_main_motion_sensor_motion
from: 'off'
to: 'on'
- id: 'bar_on'
platform: state
entity_id: switch.stairwell_light
from: 'off'
to: 'on'
- id: 'bar_off'
platform: state
entity_id: binary_sensor.bar_main_motion_sensor_motion
from: 'on'
to: 'off'
for: '00:01:30'
- id: 'bar_off'
platform: state
entity_id: switch.stairwell_light
from: 'on'
to: 'off'
- id: 'bar_off1'
platform: state
entity_id: binary_sensor.bar_stairwell_motion_sensor_motion
from: 'on'
to: 'off'
for: '00:01:30'
condition: []
action:
- choose:
- conditions:
- "{{ trigger.id == 'bar_on' }}"
sequence:
- service: switch.turn_on
target:
entity_id:
- switch.area_cans
- switch.bar_pool_table_light
- switch.rope_lights
- switch.bar_hall_to_media
- switch.bar_landing
- switch.stairwell_light
- service: light.turn_on
target:
entity_id:
- light.bar_pendant_light
- light.bar_back_bar_cans
data:
brightness_pct: 50
- conditions:
- "{{ trigger.id == 'bar_off' }}"
sequence:
- service: switch.turn_off
target:
entity_id:
- switch.area_cans
- switch.bar_pool_table_light
- switch.rope_lights
- switch.bar_hall_to_media
- switch.bar_landing
- switch.stairwell_light
- service: light.turn_off
target:
entity_id:
- light.bar_back_bar_cans
- light.bar_pendant_light
- conditions:
- "{{ trigger.id == 'bar_off1' }}"
- "{{ states('binary_sensor.bar_main_motion_sensor_motion') == 'off' }}"
sequence:
- service: switch.turn_off
target:
entity_id:
- switch.area_cans
- switch.bar_pool_table_light
- switch.rope_lights
- switch.bar_hall_to_media
- switch.bar_landing
- switch.stairwell_light
- service: light.turn_off
target:
entity_id:
- light.bar_back_bar_cans
- light.bar_pendant_light
default: []
mode: single
As long as there is motion the lights will stay on. My motion detectors are shellies so there is a one minute delay automatically built in to my motion detection. If both your motion sensors are visible in the room you will need to add that condition.