If you are using ZHA to control your Philips Hue SML001 Motion Sensor then this Blueprint can be used to configure the Occupied to Unoccupied Delay & Sensitivity ZigBee Cluster attributes.
The attributes are set whenever Home Assistant starts allowing your SML001 to behave as an occupancy sensor and not a bad motion sensor (as it does when using the defaults).
The Blueprint takes a number of parameters to use the occupancy sensor to control a light or group of lights. Different brightness and colour settings can be used for between 22:00 and 07:00, so if you get up to take leak in the middle of the night you are not blinded by bright lights as you walk out onto the landing
The light level to trigger switching on a light can also be set.
There are also two entities that can be used to enable/disable the sensor. I use an Input Boolean to disable some sensors during the night (to stop the cats trigger them) and a media player entity to disable the sensor when Iâm watching TV (I donât like the lights going on and off while watching TV).
At the moment you will need to paste in the Zigbee ieee device id as I havenât found a way to get to this value from a template using the occupancy or illuminance entities (if anyone knows how then please share). It can be found in the Devices Page under Zigbee info.
#
# 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: []