I have a motion sensor at the top and bottom of my stairs that when triggered after dark, will turn on the lights of the rooms at the top and bottom with dim light for 40 seconds and then shuts the lights off.
alias: Motion Livingroom - Turn on Stair Lights
description: ''
trigger:
- entity_id: binary_sensor.livingroom_motion
from: 'off'
platform: state
to: 'on'
- platform: state
entity_id: binary_sensor.downstairs_motion
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: light.living_room
state: 'off'
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- data:
brightness: 100
entity_id: light.living_room
rgb_color:
- 255
- 205
- 120
entity_id: light.living_room
service: light.turn_on
- data:
brightness: 100
entity_id: light.hall_down
rgb_color:
- 255
- 205
- 120
entity_id: light.hall_down
service: light.turn_on
- delay: '40'
- data: {}
entity_id: light.living_room
service: light.turn_off
- data: {}
entity_id: light.hall_down
service: light.turn_off
mode: single
This works great with one exception. When someone wants to go into the room instead of down the stairs and they turn on the lights it will already have triggered a 40-second timer and then after the person goes in and sits down the lights will turn off on them.
My thoughts for a solution was to have a way to interrupt the automation. I thought maybe set it that if the brightness of the lights was altered it would terminate the rest of the steps. That way you could walk into the room trigger the dim lights and then reach over and turn up the lights and they would stay on.
However, I can not figure out how to do that.
I know as of 0.113.2 you can now stop an automation without it continuing to run in the background.
I also know there are new repeat functions.
I thought maybe have it count to 10 check conditions are met of (brightness = 100) and repeat 4 times then turn off the light. If conditions are not met then terminate the process.
But I can’t seem to figure out how to make that work.
There is probably a much easier way to do this.
Please advise.
(This causes some hilarious ninja-like actions from my children, trying to figure out how to turn the light on at the switch without the motion sensor seeing them, so the lights won’t go out on them.)
I had a thought. I could make a second automation that triggers on changing the brightness of that light from X brightness. To reload automations. This seems a tad aggressive though.
The way I achieve a similar function is to have my light trigger automation start a script. That script deals with the timing and if the automation is re-triggered or the light is requested to stay on permanently, a script_stop
service is called which cancels the timing.
The automation and scripts were created prior to the new automation functionality and I just haven’t yet looked into upgrading them so perhaps it can be improved, I just haven’t had time and they work perfectly at the moment so I don’t want to ruin the W.A.F changing them!
Wouldn’t it be better to turn on the downstairs light, when motion has been detected at the downstairs sensor after it has been detected at the upstairs sensor and the same vice versa for the upstair lights? Or is the light up and downstairs needed in order to use the stairs?
Well, it’s the living room light so it’s both used to use the stairs as well as go grab something in the living room or kitchen late at night. So the sub-minute long dim light is pretty convenient most of the time. The issues really don’t arrive until morning when the sun still hasn’t risen but people want to start the day.
So this is what I am trying.
For some reason even though automations have a setting for attribute, changing the brightness did not trigger the automation to start.
So I created a sensor to monitor the brightness.
- platform: template
sensors:
living_room_lights_brightness:
friendly_name: "Living Room Lights Brightness"
value_template: '{{ states.light.living_room.attributes.brightness }}'
Then I created a second automation to monitor be triggered when brightness changed from 100 brightness.
alias: STOP Automation - When LIVING ROOM light changes brightness
description: ''
trigger:
- platform: state
entity_id: sensor.living_room_lights_brightness
from: '100'
condition: []
action:
- service: automation.reload
data: {}
mode: single
This one reloads all automation and thus stops the countdown timer.
This works, as you can now walk into the room and turn up the brightness with the HUE switch on the wall and it will no longer shut the lights off after 40 seconds.
Like I said before though I feel like Automation.reload is rather aggressive as it stops all automations and even prevents one from being triggered for a few seconds. Does anyone know of a way to stop just one specific automation?
Final Chapter here (unless someone has a better way ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=9)
I changed the automation.reload to automation.turn_off and then turn_on
This allowed me to only stop/kill that one automation and not the entire list.
So to accomplish my goal I have:
Automation 1 to turn on the lights dim for 40 seconds
alias: Motion Livingroom - Turn on Stair Lights
description: ''
trigger:
- entity_id: binary_sensor.livingroom_motion
from: 'off'
platform: state
to: 'on'
- platform: state
entity_id: binary_sensor.downstairs_motion
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: light.living_room
state: 'off'
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- data:
brightness: 100
entity_id: light.living_room
rgb_color:
- 255
- 205
- 120
entity_id: light.living_room
service: light.turn_on
- data:
brightness: 100
entity_id: light.hall_down
rgb_color:
- 255
- 205
- 120
entity_id: light.hall_down
service: light.turn_on
- delay: '40'
- data: {}
entity_id: light.living_room
service: light.turn_off
- data: {}
entity_id: light.hall_down
service: light.turn_off
mode: single
A sensor to monitor the brightness of the lights.
- platform: template
sensors:
living_room_lights_brightness:
friendly_name: "Living Room Lights Brightness"
value_template: '{{ states.light.living_room.attributes.brightness }}'
A second automation to cancel the timer on the first when the brightness chages from 100.
description: ''
trigger:
- platform: state
entity_id: sensor.living_room_lights_brightness
from: '100'
condition: []
action:
- service: automation.turn_off
data: {}
entity_id: automation.motion_lights_stairs
- delay: '5'
- service: automation.turn_on
data: {}
entity_id: automation.motion_lights_stairs
mode: single
Thanks, All