I have an automation that turns on a light when a PIR detects movement.
How can I reset or retrigger the turn off delay? In other words, as long as the PIR sees movement, the light stays on. When there is no movement, the light turns off after X minutes.
It is pretty easy in Node Red, but I want to learn more about automations.
so now each the motion turn on the “boolean” 1 sec turn it off maths easyer
so now we can put some good logic in place
#=======================================================================
# now This Is the Brains of it
# if the state does NOT change for X minutes do something
# you mite want to as some conditions to make it smarter
# this automation is where you set the action
#=======================================================================
- id: "13aee00d-8806-443b-9f1c-41b69871ca91"
alias: "motion on for x min"
initial_state: true
trigger:
- platform: state
entity_id: input_boolean.someone_in_room_1
to: "off"
for: "00:{{states.input_select.motion_delay_1.state}}:00"
condition:
# ********************************************
# added a condition to make it smarter
# ie I know the states of the office switch
# off = Auto turn on/off
# ********************************************
- condition: state
entity_id: sensor.office_switch
state: "OFF"
#
action:
- data:
entity_id: input_select.motion_a_1
option: "clear"
service: input_select.select_option
# set the off action
- data:
entity_id: light.office
service: light.turn_off
#=========================================================
now the on bit
#=======================================================================
# Now the ON BIT
# again add some conditions
# office light MUST be off and the Light switch MUST be OFF
#=======================================================================
- id: "motion in office : light on "
alias: "motion in office : light on "
initial_state: true
# the motion action
trigger:
- platform: state
entity_id: binary_sensor.office_motion
to: "on"
# ********************************************
# added a condition to make it smarter
# ie I know the states of the office switch
# off = Auto turn on/off
# ********************************************
condition:
condition: and
conditions:
- condition: state
entity_id: sensor.office_switch
state: "OFF"
action:
# Action to turn ON
- data:
entity_id: light.office
service: light.turn_on
#=======================================================================
Thanks.
And I thought this would be an opportunity to increase my understanding of automations. But, “clear as mud” reminds me of why I did it in Node Red for my garage light. One node was all it took.
But you have provided me with things to think about.
each time the binary_sensor.office_motion goes "on it turn on the input_boolean.someone_in_room_1 and them 1 sec later it input_boolean.someone_in_room_1 off
now i wait for the Trigger input_boolean.someone_in_room_1 to off for input_boolean.someone_in_room_1 in a time format of “00:00:00”
to make it a bit smarter
I have a condition is the “sensor.office_switch” off which is the switch on the wall
Even I’m lost about what @myle is talking about. It seems overly complicated for a simple ‘turn my lights off after x amount of minutes’ automation. But whatever works for you!
The simplest way is:
automation:
trigger:
- platform: state
entity_id: binary_sensor.kitchen_motion
from: 'on'
to: 'off'
for: '00:05:00'
action:
- service: light.turn_off
data:
entity_id: light.kitchen
This will turn off the kitchen light, only when there has been no motion detected for 5 mins.