ageee
(Adam)
December 31, 2021, 10:17pm
1
Hello Community! I have been migrating my smart home to Home Assistant over the last few weeks and am having trouble replicating an automation I have working in Hubitat/WebCore.
I want to turn on the lights in the guest room, but only if motion hasn’t been detected there for 30 minutes. My initial attempt at the automation is below, but, as written, this will never trigger an action. I am pretty sure the motion detected from when I walk in the room is what is blocking this from working. How can I re-write this?
Thanks for the help and Happy New Year to all!
- id: 'Guest Room Lights - On'
alias: 'Guest Room Lights - On'
trigger:
- platform: state
entity_id: binary_sensor.guest_room_motion
from: 'off'
to: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: input_select.home_mode
state:
- "Day"
- "Night"
- "Late Night"
- condition: state
entity_id: binary_sensor.guest_room_motion
state: "off"
for:
minutes: 30
action:
- choose:
- conditions:
- condition: state
entity_id: input_select.home_mode
state:
- "Day"
- "Night"
sequence:
- service: switch.turn_on
entity_id:
- switch.guest_room_light
- switch.guest_room_lamp
- choose:
- conditions:
- condition: state
entity_id: input_select.home_mode
state:
- "Late Night"
sequence:
- service: switch.turn_on
entity_id:
- switch.guest_room_lamp
Wouldn’t your trigger states need to be the opposite? Going from on
to off
?
Is something like this close? The lights turn off 30 minutes after the last motion is detected. I did this in the Automation UI & then adjusted a bit.
- id: 'Guest Room Lights - On'
alias: 'Guest Room Lights - On'
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.guest_room_motion
from: 'off'
to: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: input_select.home_mode
state:
- "Day"
- "Night"
- "Late Night"
action:
- service: switch.turn_on
target:
entity_id:
- switch.guest_room_light
- switch.guest_room_lamp
- delay:
hours: 0
minutes: 30
seconds: 0
milliseconds: 0
- service: switch.turn_off
target:
entity_id:
- switch.guest_room_light
- switch.guest_room_lamp
ageee
(Adam)
December 31, 2021, 11:39pm
4
I’m trying to turn the lights ‘on’ if motion hasn’t been detected in the room for 30 minutes. The use case here is guests wanting the lights off while they are in the room without the lights on automation being triggered.
brg468
(Brian)
December 31, 2021, 11:40pm
5
Can’t really test it myself but try this:
- id: 'Guest Room Lights - On'
alias: 'Guest Room Lights - On'
trigger:
- platform: state
entity_id: binary_sensor.guest_room_motion
from: 'off'
to: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: input_select.home_mode
state:
- "Day"
- "Night"
- "Late Night"
- condition: template
value_template: "{{now().timestamp() - trigger.from_state.last_changed.timestamp() > 1800}}"
action:
- choose:
- conditions:
- condition: state
entity_id: input_select.home_mode
state:
- "Day"
- "Night"
sequence:
- service: switch.turn_on
entity_id:
- switch.guest_room_light
- switch.guest_room_lamp
- choose:
- conditions:
- condition: state
entity_id: input_select.home_mode
state:
- "Late Night"
sequence:
- service: switch.turn_on
entity_id:
- switch.guest_room_lamp
[/quote]
1 Like
ageee
(Adam)
January 1, 2022, 9:40pm
6
That worked perfectly! Thanks for the help
1 Like