Created
April 20, 2021 20:54
-
-
Save WizBangCrash/e6d67e8a2340b998914fcabe952748b9 to your computer and use it in GitHub Desktop.
Occupancy Blueprint for Philips Hue SML001 motion sensor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Blueprint to control a light (or lights) using a Philips Hue SML001 | |
# motion sensor connected to Home Assistant via ZHA | |
# | |
# Home Assitant configures the sensor to be an Occupancy Sensor at boot, | |
# setting the Occupied to Unoccipied time and sensitivity of the sensor. | |
# I used to use HA timers to do this, but Blueprint is now much more simple :-) | |
# | |
# Additionally the sensor can be disabled using a oneof two entities. | |
# I usually link this to a TV state, as I do not want my lights going on & off | |
# while sitting in the Lounge watching TV. | |
# I also use an input_boolean to enable me to disable all my occupancy sensors. | |
# | |
blueprint: | |
name: Occupancy Detection Response (SML001) | |
description: | | |
The basic occupancy sensor automation does the following: | |
The sets the sensor attributes when Home Assistant boots | |
Turn on light(s) when occupancy detected and off when unoccupied. | |
Uses a different brightness at night | |
Optionally, choose a TV and the occupancy sensor will be ignored when the TV is on | |
domain: automation | |
input: | |
occupancy_entity: | |
name: Occupancy Sensor | |
description: "The occupancy sensor to use for this automation" | |
selector: | |
entity: | |
domain: binary_sensor | |
device_class: occupancy | |
ieee_id: | |
name: Occupancy Sensor Zigbee IEEE ID | |
description: "The zigbee network id of the sensor" | |
selector: | |
text: | |
o_to_u_delay: | |
name: Occupied to Unoccupied delay | |
description: | | |
Set the time in seconds we require the light(s) to stay on. | |
This delay is reset each time motion is detected. | |
NOTE: Restart Home Assistant on changing this value | |
default: 180 | |
selector: | |
number: | |
min: 0 | |
max: 1800 | |
mode: box | |
unit_of_measurement: "seconds" | |
sensitivity: | |
name: Sensitivity of sensor | |
description: | | |
Set how sensitive we want the sensor to be: 0 = least sensitive | |
NOTE: Restart Home Assistant on changing this value | |
default: 2 | |
selector: | |
number: | |
min: 0 | |
max: 2 | |
illuminance_entity: | |
name: Illuminance | |
description: "The luminance sensor to use" | |
selector: | |
entity: | |
domain: sensor | |
device_class: illuminance | |
luminance_value: | |
name: Light trigger level | |
description: "Anything darker than this will turn on the light" | |
default: 6 | |
selector: | |
number: | |
min: 2 | |
max: 3000 | |
mode: box | |
unit_of_measurement: "lx" | |
light_entity: | |
name: Lights | |
description: The light(s) to control | |
selector: | |
entity: | |
domain: light | |
daytime_brightness: | |
name: Daytime Brightness | |
description: "The brightness to set the light during the day (100%)" | |
default: 75 | |
selector: | |
number: | |
min: 10 | |
max: 100 | |
mode: box | |
unit_of_measurement: "%" | |
nighttime_brightness: | |
name: Nighttime Brightness | |
description: "The brightness to set the light at night(100%)" | |
default: 10 | |
selector: | |
number: | |
min: 10 | |
max: 100 | |
mode: box | |
unit_of_measurement: "%" | |
daytime_colour: | |
name: Daytime colour temperature | |
description: "The colour temperature during the day (4500K)" | |
default: 4500 | |
selector: | |
number: | |
min: 2200 | |
max: 6500 | |
step: 100 | |
mode: box | |
unit_of_measurement: "Kelvin" | |
nighttime_colour: | |
name: Nighttime colour temperature | |
description: "The colour temperature during the night (3000K)" | |
default: 3000 | |
selector: | |
number: | |
min: 2200 | |
max: 6500 | |
step: 100 | |
mode: box | |
unit_of_measurement: "Kelvin" | |
disable_entity: | |
name: Input Boolean to use for disabling sensor | |
description: > | |
Set to an input_boolean. If the input_boolean is in the 'on' state | |
then the occupancy sensor will be disabled | |
default: {} | |
selector: | |
target: | |
entity: | |
domain: input_boolean | |
media_entity: | |
name: If this media player is on than disable occupancy sensor | |
description: > | |
Set to a media_player e.g. TV. If the media player is in the 'on' state | |
then the occupancy sensor will be disabled e.g. | |
media_player.lounge_tv | |
default: {} | |
selector: | |
target: | |
entity: | |
domain: media_player | |
# | |
# The automation | |
# | |
variables: | |
ieee_id: !input ieee_id | |
disable_entity: !input disable_entity | |
media_entity: !input media_entity | |
# Trigger mode | |
mode: single | |
# Trigger | |
trigger: | |
# When HA starts | |
- platform: homeassistant | |
event: start | |
# Occupancy sensor. Any state change | |
- platform: state | |
entity_id: !input occupancy_entity | |
# Conditions | |
condition: | |
# Using a template allows us to cater for either of these entities being "None" | |
- alias: "Exit if sensor is disabled" | |
condition: template | |
value_template: "{{ True if not disable_entity else is_state(disable_entity.entity_id, 'off') }}" | |
- alias: "Exit if media player on" | |
condition: template | |
value_template: "{{ True if not media_entity else is_state(media_entity.entity_id, 'off') }}" | |
# Actions | |
# TODO: Figure out how to get ieee address of sensor from entity | |
action: | |
- alias: "What caused the trigger?" | |
choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ trigger.platform == 'homeassistant' }}" | |
sequence: | |
# Set device occupancy off delay | |
- service: zha.set_zigbee_cluster_attribute | |
data: | |
ieee: "{{ ieee_id }}" | |
endpoint_id: 2 | |
cluster_id: 0x0406 | |
cluster_type: in | |
attribute: 0x0010 | |
value: !input o_to_u_delay | |
# Set device sensitivity | |
- service: zha.set_zigbee_cluster_attribute | |
data: | |
ieee: "{{ ieee_id }}" | |
endpoint_id: 2 | |
cluster_id: 0x0406 | |
cluster_type: in | |
attribute: 0x0030 | |
value: !input sensitivity | |
- conditions: | |
- condition: template | |
value_template: > | |
{{ | |
trigger.platform == 'state' | |
and trigger.to_state.state == 'on' | |
}} | |
- condition: numeric_state | |
entity_id: !input illuminance_entity | |
below: !input luminance_value | |
sequence: | |
- alias: "Night time or day time?" | |
choose: | |
- conditions: | |
- condition: time | |
after: "22:00:00" | |
before: "07:00:00" | |
sequence: | |
- service: light.turn_on | |
entity_id: !input light_entity | |
data: | |
brightness_pct: !input nighttime_brightness | |
kelvin: !input nighttime_colour | |
default: | |
- service: light.turn_on | |
entity_id: !input light_entity | |
data: | |
brightness_pct: !input daytime_brightness | |
kelvin: !input daytime_colour | |
- conditions: | |
- condition: template | |
value_template: > | |
{{ | |
trigger.platform == 'state' | |
and trigger.to_state.state == 'off' | |
}} | |
sequence: | |
- service: light.turn_off | |
entity_id: !input light_entity | |
default: [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@WizBangCrash What i’m trying to do is get the light to come on below 10lux. Like a night light. So after the automation runs for the first time, the illuminance will be stuck at the high value (maybe 70lux) when the light was on and does not refresh until around a few minutes. When the second person enters the area during this time, the automation will not trigger as the motion is detected (but lux is still 70) and when the lux value updates to <10, the occupancy sensor is also already active and there is no change in state to trigger the automation. Hope it’s a bit clearer.