Skip to content

Instantly share code, notes, and snippets.

@quallenbezwinger
Last active January 11, 2025 16:33
Show Gist options
  • Select an option

  • Save quallenbezwinger/3e5c23acb05fb639bafdc5036b91aae6 to your computer and use it in GitHub Desktop.

Select an option

Save quallenbezwinger/3e5c23acb05fb639bafdc5036b91aae6 to your computer and use it in GitHub Desktop.
Homeassistant blueprint for motion-activated light scene with surrounding light level check
blueprint:
name: Motion-activated light scene with surrounding light level check
description: Turn on a light scene when motion is detected. Three different scenes can be defined depending on time of day. Furthermore a source for checking sourrounding light can be defined to enable light only if it is dark enough.
domain: automation
source_url: https://gist.github.com/dirkk1980/3e5c23acb05fb639bafdc5036b91aae6
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
lightsensor_entity:
name: Illuminance Sensor
selector:
entity:
domain: sensor
device_class: illuminance
illuminace_level:
name: Max Illuminance
description: Maximal immuminance level in lux. If illuminance is higher, light will not be enabled
default: 600
selector:
number:
min: 0
max: 5000
unit_of_measurement: lux
light_target:
name: Light
selector:
target:
entity:
domain: light
scene_morning:
name: Scene for the morning
selector:
entity:
domain: scene
time_scene_morning:
name: Time for the morning scene
description: A time input which defines the time from which on the scene will be activated if motion is detected
selector:
time:
scene_day:
name: Scene for the bright day
selector:
entity:
domain: scene
time_scene_day:
name: Time for the day scene
description: A time input which defines the time from which on the scene will be activated if motion is detected
selector:
time:
scene_evening:
name: Scene for the evening
selector:
entity:
domain: scene
time_scene_evening:
name: Time for the evening scene
description: A time input which defines the time from which on the scene will be activated if motion is detected
selector:
time:
scene_night:
name: Scene for the dark night
selector:
entity:
domain: scene
time_scene_night:
name: Time for the night scene
description: A time input which defines the time from which on the scene will be activated if motion is detectedd
selector:
time:
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
mode: restart
max_exceeded: silent
trigger:
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
action:
- choose:
- conditions:
- condition: time
after: !input time_scene_morning
before: !input time_scene_day
- condition: numeric_state
entity_id: !input lightsensor_entity
below: !input illuminace_level
sequence:
- scene: !input scene_morning
- conditions:
- condition: time
after: !input time_scene_day
before: !input time_scene_evening
- condition: numeric_state
entity_id: !input lightsensor_entity
below: !input illuminace_level
sequence:
- scene: !input scene_day
- conditions:
- condition: time
after: !input time_scene_evening
before: !input time_scene_night
- condition: numeric_state
entity_id: !input lightsensor_entity
below: !input illuminace_level
sequence:
- scene: !input scene_evening
- conditions:
- condition: time
after: !input time_scene_night
before: !input time_scene_morning
- condition: numeric_state
entity_id: !input lightsensor_entity
below: !input illuminace_level
sequence:
- scene: !input scene_night
- 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
@RasmusC92
Copy link
Copy Markdown

Hi there!

I'm a big fan of this blueprint, but i'm missing a feature that can solve an issue for me :)

Is it possible that you can add a condition that checkes if a phone "device_tracker" is in the zone "Home" before it does anything?

An example:

"motion_entity" triggered <From: off to :on>
condition: check if phone "device_tracker" is home:
If "home" execute what this blueprint normally would do (Turn on the light according to the scene selected)
if "not_home" or "away" execute nothing (Do not turn on the light)

I have tried to implement it myself, but after tons of failures i gave up.

Thanks in advance,
Rasmus

@M4SSO
Copy link
Copy Markdown

M4SSO commented Oct 3, 2023

Hi I'm trying to use this code with Hue sensors, they rely on occupancy sensors not motion sensors and cannot be entered into your file. How do I input occupancy rather than motion into the blueprint.
Sorry if this is a stupid question
Thanks
M4SSO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment