This is a simple automation that turns a light on when there is motion, and turns it off when there is not.
but I added a condition so that it only trigger only in sunset, it is possible to configure the sunset and sunrise offset.
Get started
Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)
Or import this Blueprint by using the forum topic URL:
blueprint:
name: Motion-activated Light with sun condition
description: Turn on a light when motion is detected and sunset.
domain: automation
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
light_target:
name: Light
selector:
target:
entity:
domain: light
no_motion_wait:
name: Wait time
description: Time to leave the light on after last motion is detected.
default: 120
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
sunset_offset:
name: Offset to turn on lights
description: Define offset to sunset
default: 60
selector:
number:
min: 0
max: 240
unit_of_measurement: minutes
sunrise_offset:
name: Offset to turn off lights
description: Define offset to sunrise
default: 45
selector:
number:
min: 0
max: 240
unit_of_measurement: minutes
# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent
trigger:
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
condition:
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: !input sunset_offset
- condition: sun
before: sunrise
before_offset: !input sunrise_offset
action:
- service: light.turn_on
target: !input light_target
- wait_for_trigger:
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
- delay: !input no_motion_wait
- service: light.turn_off
target: !input light_target
No. When light is on manual automation not run, but when light is off (no turn manual) automation based on motion and elevation sun run…
But for this we must add condition…
via the integrations light.switch i can see the devices as entities and selectable , so i will work like that. many thanks for the info. edit: not working for me , i use fibaro double switch, when added this one , all of them go unavailable …with single swicthes it works. Changed the domain, all the lights that i need are on a switch , so that is a better solution for me.
Does this have a manual override of the motion detector? I want this in the bedroom but I do not want the light turning on when I move during my sleep.
Thank you for the blueprint. I’m new to HA from smartthings I’ve been wanting sun setting forever with smartthings. I do however have a question. Is there a way to add a time based stop? EX I like the motion in the evenings but after 10pm when everyone is asleep I don’t need the animals running through the motion rooms turning on and off lights all night? thanks for the help
Hi, thanks for this, however I can’t get it to trigger correctly. I’m trying to do a basic ‘Turn off lights after 5 seconds, when there is no motion detected’. I have set the ‘Wait time’ to ‘5 seconds’, but the light still stays on.
Blueprint:
alias: Turn of WC Light when no motion
description: ''
use_blueprint:
path: >-
Marcos_Felipe/turn-light-on-and-off-based-on-detected-motion-with-sun-condition.yaml
input:
motion_entity: binary_sensor.wc_motion_sensor
light_target:
entity_id: light.wc_light
sunrise_offset: 5
sunset_offset: 2
no_motion_wait: 5
Is there any reason the offsets are not allowed to be less than 0? I want my automation to be able to trigger 30 minutes before sunset, but the min_value for sunset_offset is 0.
blueprint:
name: Motion-activated Light On at Sunset
description: Turn on a light when motion is detected On At Sunset.
domain: automation
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
elevation_shift:
name: Elevation Shift
description: Using an elevation offset (height of sun relative to the horizon) to shift the sunset trigger, either earlier or later. Positive values bring the automation start time forward, whilst negative values delay the start time.
default: 0.0
# Use a selector, to set the time shift or offset
selector:
number:
min: -10.0
max: 10.0
mode: slider
step: 1.0
target_light:
name: Lights
description: This is the light (or lights) that will be activated at sunset
selector:
target:
entity:
domain: light
target_brightness:
name: Brightness
description: Brightness of the light(s) when they're activated
default: 50
selector:
number:
min: 5.0
max: 100.0
mode: slider
step: 5.0
unit_of_measurement: '%'
target_color_temp:
name: Temperature
description: Termperature of the light(s) when they're activated
default: 280
selector:
number:
min: 153
max: 454
mode: slider
step: 1
no_motion_wait:
name: Wait time
description: Time to leave the light on after last motion is detected.
default: 120
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent
variables:
target_brightness: !input 'target_brightness'
target_color_temp: !input 'target_color_temp'
trigger:
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
condition:
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
below: !input elevation_shift
action:
- service: light.turn_on
target: !input target_light
data_template:
brightness_pct: '{{ target_brightness | int }}'
color_temp: '{{ target_color_temp | int }}'
- wait_for_trigger:
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
- delay: !input no_motion_wait
- service: light.turn_off
target: !input target_light