glc650
January 2, 2022, 4:07am
1
I have an automation using a wait for time to pass (5 mins) action:
alias: shop left/middle/right lights on/off with kitchen door open/close
description: ''
trigger:
- platform: state
entity_id: binary_sensor.cs_kitchen_door
from: 'off'
to: 'on'
condition: []
action:
- service: light.turn_on
target:
entity_id:
- light.shop_left_lights
- light.shop_middle_lights
- light.shop_right_lights
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.cs_kitchen_door
from: 'on'
to: 'off'
- delay:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
- service: light.turn_off
target:
entity_id:
- light.shop_left_lights
- light.shop_middle_lights
- light.shop_right_lights
mode: restart
that often just stops after the 5 minutes have passed:
or just fails/breaks at that time:
Is there a better way to handle this that would avoid this? The automation is just turning lights on when a door is open and turning them off 5 minutes after the door is closed unless the door is opened again then it resets.
tom_l
January 2, 2022, 4:12am
2
Yes. Use a second automation:
trigger:
- platform: state
entity_id: binary_sensor.cs_kitchen_door
from: 'on'
to: 'off'
for:
minutes: 5
condition: []
action:
- service: light.turn_off
target:
entity_id:
- light.shop_left_lights
- light.shop_middle_lights
- light.shop_right_lights
This can also be combined with the first automation if you want:
trigger:
- platform: state
entity_id: binary_sensor.cs_kitchen_door
from: 'off'
to: 'on'
id: 'on'
- platform: state
entity_id: binary_sensor.cs_kitchen_door
from: 'on'
to: 'off'
for:
minutes: 5
id: 'off'
condition: []
action:
- service: "light.turn_{{ trigger.id }}"
target:
entity_id:
- light.shop_left_lights
- light.shop_middle_lights
- light.shop_right_lights
glc650
January 2, 2022, 4:16am
3
I’ll give that a try thanks. Why does my automation sometimes work?
tom_l
January 2, 2022, 4:18am
4
Reloading automations or restarting Home Assistant while waiting?
glc650
January 2, 2022, 4:19am
5
Neither. I also have the same automation but for motion sensor (so no motion for one minute instead of door closed for 5) that work fine.
glc650
January 2, 2022, 4:23am
6
tom_l:
This can also be combined with the first automation if you want:
trigger:
- platform: state
entity_id: binary_sensor.cs_kitchen_door
from: 'off'
to: 'on'
id: 'on'
- platform: state
entity_id: binary_sensor.cs_kitchen_door
from: 'on'
to: 'off'
for:
minutes: 5
id: 'off'
condition: []
action:
- service: "light.turn_{{ trigger.id }}"
target:
entity_id:
- light.shop_left_lights
- light.shop_middle_ligh
What mode would this new automation be? Single?
glc650
January 11, 2022, 2:09am
8
Is there a way to adapt this to motion sensors when you are waiting on multiple motion sensors to clear before turning the lights off:
alias: kitchen sink motion lighting
description: ''
trigger:
- platform: state
entity_id: binary_sensor.ms_kitchen
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.ms_kitchen_sink
from: 'off'
to: 'on'
condition:
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: '00:10:00'
- condition: sun
before: sunrise
before_offset: '-00:10:00'
- condition: state
entity_id: light.kitchen_high_lights
state: 'off'
action:
- service: switch.turn_on
target:
entity_id: switch.kitchen_sink_lights
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.ms_kitchen
from: 'on'
to: 'off'
- platform: state
entity_id: binary_sensor.ms_kitchen_sink
from: 'on'
to: 'off'
- delay:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
- service: switch.turn_off
target:
entity_id: switch.kitchen_sink_lights
mode: restart
What you posted above would work fine for the on part but how would I adapt that to include two sensors in the off part?
jazzyisj
(Jason)
January 11, 2022, 2:59am
9
Scratch that. You need to split this automation up in to one for turning the lights on and one for turning them off. Much simpler.
glc650
January 11, 2022, 3:06am
10
Thanks I’ll give this a try.
light.kitchen_high_lights is my override. If it is on I want it to stop this rule. If this rule has already fired and light.kitchen_high_lights it turned on I have another rule that overrides (turns off this automation and the lights it turned on) this rule.
jazzyisj
(Jason)
January 11, 2022, 3:06am
11
I changed my post. Give me a second I’ll repost the automations.
jazzyisj
(Jason)
January 11, 2022, 3:08am
12
I think this will do what you want.
trigger:
- platform: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
to: 'on'
from: 'off'
condition:
- condition: state
entity_id: light.kitchen_high_lights
state: 'off'
action:
- service: switch.turn_on
target:
entity_id: switch.kitchen_sink_lights
trigger:
- platform: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
to: 'off'
from: 'on'
for:
minutes: 5
condition:
- condition: state
entity_id:
- light.kitchen_high_lights
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
state: 'off'
action:
- service: switch.turn_off
target:
entity_id: switch.kitchen_sink_lights
glc650
January 11, 2022, 3:27am
13
Combined that with what I learned from above:
alias: kitchen sink motion lighting
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
from: 'off'
to: 'on'
id: 'on'
- platform: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
from: 'on'
to: 'off'
for:
minutes: 5
id: 'off'
condition:
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: '00:10:00'
- condition: sun
before: sunrise
before_offset: '-00:10:00'
- condition: state
entity_id: light.kitchen_high_lights
state: 'off'
action:
- service: switch.turn_{{ trigger.id }}
target:
entity_id: switch.kitchen_sink_lights
mode: single
And this seems to be working.
When grouping triggers like this:
- platform: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
from: 'off'
to: 'on'
id: 'on'
is it an AND or OR situation?
jazzyisj
(Jason)
January 11, 2022, 3:30am
14
In a trigger it is OR. It will trigger if either motion sensor turns on.
The same thing in a condition is AND. They all must have the specified state to pass.
glc650
January 11, 2022, 3:32am
15
How does this actually work then? Both motion sensors need to be “off” for 5 minutes before shutting the lights off. I just tested and it seems to work but I don’t see why/how if the trigger is OR?
jazzyisj
(Jason)
January 11, 2022, 3:33am
16
The lights don’t turn off unless both motion sensors are off. The last trigger that happens when both sensors are off will be 5 minutes after the last motion sensor turns off. Then the condition passes and the lights will turn off. The automation ‘triggers’ for both sensors turning off but only runs when they are both off because of the condition.
glc650
January 11, 2022, 3:48am
17
Just tested it again twice and it’s not working that way. Soon as one trigger is off for 5 mins it shuts the lights off (even if the other trigger was reset before then).
jazzyisj
(Jason)
January 11, 2022, 3:53am
18
Can you post your conditions.
glc650
January 11, 2022, 4:37am
19
I think I got it now. Here’s what I ended up with:
alias: kitchen sink motion lighting
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
from: 'off'
to: 'on'
- platform: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
from: 'on'
to: 'off'
for:
minutes: 5
condition:
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: '00:10:00'
- condition: sun
before: sunrise
before_offset: '-00:10:00'
- condition: state
entity_id: light.kitchen_high_lights
state: 'off'
action:
- choose:
- conditions:
- condition: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
state: 'off'
for:
minutes: 5
sequence:
- service: switch.turn_off
target:
entity_id: switch.kitchen_sink_lights
default:
- service: switch.turn_on
target:
entity_id: switch.kitchen_sink_lights
mode: single
jazzyisj
(Jason)
January 11, 2022, 6:03am
20
You didn’t split the automations. You want the lights to turn off with no motion even during daylight hours if someone turned them on no?
Try these.
alias: kitchen sink motion lighting off
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
from: 'on'
to: 'off'
for:
minutes: 5
condition:
- condition: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
- light.kitchen_high_lights
state: 'off'
- condition: state
entity_id: switch.kitchen_sink_lights
state: 'on'
action:
action:
- service: switch.turn_off
target:
entity_id: switch.kitchen_sink_lights
mode: single
alias: kitchen sink motion lighting on
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.ms_kitchen
- binary_sensor.ms_kitchen_sink
from: 'off'
to: 'on'
condition:
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: '00:10:00'
- condition: sun
before: sunrise
before_offset: '-00:10:00'
- condition: state
entity_id: light.kitchen_high_lights
state: 'off'
- condition: state
entity_id: switch.kitchen_sink_lights
state: 'off'
action:
- service: switch.turn_on
target:
entity_id: switch.kitchen_sink_lights
mode: single