i would love to have a light to turn on automatically whenever motion is detected. if no motion is detected within 10mins, turn light off. if motion is detected, then add another 10mins. is this even possible???
this is what i have in the house so far:
binary_sensor.motion
no motion, state= off
motion detected, state= on
light is connected to the Belkin WeMo switch, switch.light.
switch on, state= on
switch off, state= off
If your binary sensor is already a template binary sensor, you can try using the delay_off option, otherwise, just create another template binary sensor with delay_off based on your binary_sensor.motion. Automation can be as simple as: sensor on -> light on, sensor off -> light off.
Here is the example of delay_off: template binary sensor - delay_off
automation kitchen_light_movement:
alias: Turn on off kitchen lights when there is movement
trigger:
- platform: state
entity_id: binary_sensor.Family_Room_Motion
to: 'on'
- platform: state
entity_id: binary_sensor.Family_Room_Motion
to: 'off'
for:
minutes: 10
action:
- service_template: 'light.turn_{{trigger.to_state.state}}'
entity_id: light.kitchen_light
Probably thatâs my luck, using the for in the state platform has not been reliable for me, or I just did not do it right. With to: âoffâ as trigger, does that mean change state to âoffâ or has a value âoffâ?
Also, with these different âwaitâ methods, can they all execute the wait action even if HA restarts during the wait time?
Sorry for side-tracking.
I use the timer method. The PIR detects motion, turns on the light, starts the timer. As long as their is motion at the PIR, the timer gets restarted. After (in my case 2 minutes) there is no motion, the lights shuts off. Works great.
Automation file
- alias: Turn on driveway floodlight when there is movement
trigger:
- platform: state
entity_id: binary_sensor.drivewaypir
to: 'on'
condition:
- condition: state
entity_id: sun.sun
state: 'below_horizon'
action:
- service: homeassistant.turn_on
entity_id: script.timed_driveway
Script file
timed_driveway:
alias: "Turn on floodlight and set timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.driveway_off
- service: switch.turn_on
data:
entity_id: switch.ge_unknown_type4952_id3033_switch_13_0
# Set new timer
- service: script.turn_on
data:
entity_id: script.driveway_off
driveway_off:
alias: "Turn off floodlight after 2 minutes"
sequence:
- delay:
minutes: 2
- service: switch.turn_off
data:
entity_id: switch.ge_unknown_type4952_id3033_switch_13_0
Understood. I think your method is a little cleaner than mine, but Iâll probably leave mine as is. Hopefully the info was helpful to the original poster.
For simple ON/OFF it doesnât make a big difference. It become useful when you want to pause/cancel/extend or display the remaining duration of a timer
I often deactivate the turn off automation so that the light stay on. With script itâs not that convenient (the automation is shown in front end)
yeah my defaults as active and inactive, i wanted to group them so i could say if group âactiveâ then blah, but as a group it says unknown. argh well hereâs mine as they currently stand
##########################################################################
################# Bathroom Motion Lights On ##################################
##########################################################################
- alias: "Motion Bathroom Lights On"
trigger:
platform: state
entity_id: 'sensor.smartthings_xiaomi_bathroom_motion_sensor_detection'
to: 'active'
condition:
condition: and
conditions:
- condition: state
entity_id: light.bathroom
state: 'off'
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: "-2:00:00"
- condition: state
entity_id: sun.sun
state: below_horizon
- condition: numeric_state
entity_id: sensor.smartthings_xiaomi_bathroom_motion_sensor_lux
below: 13
action:
- service: light.turn_on
entity_id: light.bathroom
i just tried your method and it worked flawlessly! first i added this section of your code to my automations.yaml file
- alias: Light on if motion
trigger:
- platform: state
entity_id: binary_sensor.motion
to: 'on'
action:
- service: timer.start
entity_id: timer.timer_lamp
- service: switch.turn_on
entity_id: switch.light
- alias: Turn off lights at end of timer
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer_lamp
action:
service: switch.turn_off
entity_id: switch.light
then i added this section to my configuration.yaml
timer:
timer_lamp:
duration: '00:10:00'
restarted HA and it worked. amazing!
at first i was skeptical, because everything in my automations.yaml file starts out with - action
while yours started out with - alias
but as long as it works, itâs great!