ZHA - Use Philips Hue SML001 as Occupancy Sensor for light control

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 :slight_smile:

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.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

#
# 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: []
5 Likes

Is there any way to use this with multiple light entities?
At the moment, to my simple mind it looks like it only supports a single entity (Single light)
Thanks

Hi @pjmbarlick,
Currently you can only pick one entity for the lights, but you can put a number of lights into a group and then select the group entity.
That’s how I am using to for my garage, that has three separate lights in it e.g.

- platform: group
  name: Garage Light Group
  entities:
    - light.garage_ceiling_front
    - light.garage_ceiling_rear
    - light.garage_ceiling_middle

and then use light.garage_light_group for the light entity in the Blueprint.

Hello

I bought Ikea motion sensors and then realized about the 120s or more of refresh time. It is really annoying

So with this blueprint and a philips motion sensor I can use it properly like with no delays. So when I leave the motion sensor I receive that event instantly (or within few seconds) to turn off the light or whatever I want?

Is the luminance sensor required for this to work or I can ignore it?

@Rachdingue Yes. When used with the Philips motion sensor the occupancy will be detected immediately and you can program the occupied to unoccupied delay to be just a few seconds.

The blueprint requires a luminance sensor as it stands, but you can remove the sensor from the input: section and any references to it from the action: section if you do not want to use it.

1 Like

I just imported this, deleted the automation I had linked to the motion detector, created the automation from the blue print… and it doesn’t work for me. I am not sure what is what…

Hi @keithterrill,
Are you able to be a bit more specific about “doesn’t work for me”?
What doesn’t work? Have you used the automations trace view to see what is happening?
Can you post the entry that was created in your automations.yaml file (the one that uses this blueprint) or click the “Download trace” button and share the trace.
Maybe I can give some hints on what might not be working if I can see that.

I have many many years of computer hardware and software experience. However, I am a noob when it comes to Home Assistant having just picked it up around Thanksgiving time.

I set this up, I thought, to turn on the sink light when I entered the room. It doesn’t come on, except it did this morning when I went through the room… just the one time.

I am not even sure what I am looking at, nor if this is of any help to you.

Blueprint Config

id: '1640310369664'
alias: Occupancy Detection Response (SML001)
description: ''
use_blueprint:
  path: WizBangCrash/occupancy-response-sml001.yaml
  input:
    sensitivity: 2
    ieee_id: 00:17:88:01:09:19:4b:ad
    occupancy_entity: binary_sensor.philips_sml001_ad4b1909_occupancy
    illuminance_entity: sensor.philips_sml001_ad4b1909_illuminance
    light_entity: light.sink_light_level_light_color_on_off
    luminance_value: 4
    nighttime_brightness: 40

Automation Config

variables:
  ieee_id: 00:17:88:01:09:19:4b:ad
  disable_entity: {}
  media_entity: {}
mode: single
trigger:
  - platform: homeassistant
    event: start
  - platform: state
    entity_id: binary_sensor.philips_sml001_ad4b1909_occupancy
condition:
  - 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')
      }}
action:
  - alias: What caused the trigger?
    choose:
      - conditions:
          - condition: template
            value_template: '{{ trigger.platform == ''homeassistant'' }}'
        sequence:
          - service: zha.set_zigbee_cluster_attribute
            data:
              ieee: '{{ ieee_id }}'
              endpoint_id: 2
              cluster_id: 1030
              cluster_type: in
              attribute: 16
              value: 180
          - service: zha.set_zigbee_cluster_attribute
            data:
              ieee: '{{ ieee_id }}'
              endpoint_id: 2
              cluster_id: 1030
              cluster_type: in
              attribute: 48
              value: 2
      - conditions:
          - condition: template
            value_template: |
              {{
                trigger.platform == 'state'
                and trigger.to_state.state == 'on'
              }}
          - condition: numeric_state
            entity_id: sensor.philips_sml001_ad4b1909_illuminance
            below: 4
        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: light.sink_light_level_light_color_on_off
                    data:
                      brightness_pct: 40
                      kelvin: 3000
            default:
              - service: light.turn_on
                entity_id: light.sink_light_level_light_color_on_off
                data:
                  brightness_pct: 75
                  kelvin: 4500
      - conditions:
          - condition: template
            value_template: |
              {{
                trigger.platform == 'state'
                and trigger.to_state.state == 'off'
              }}
        sequence:
          - service: light.turn_off
            entity_id: light.sink_light_level_light_color_on_off
    default: []
id: '1640310369664'
alias: Occupancy Detection Response (SML001)
description: ''

@keithterrill It looks like the Blueprint Config is set up correctly, so we need to understand if the automation is ever being triggered and if it is, what is occurring.
Have you used the “Debug Automation” function before (the middle icon of the three icons shown to the right of the automation listed in the Automations View)?

Screenshot 2022-01-04 at 23.00.55

Click on this button and see if the automation has been triggered. Refer to the documentation on debugging automations here: Troubleshooting Automations - Home Assistant

Feel free to click the trace download button and send me a trace if it’s not making any sense.

1 Like

Hi, i have been using your Blueprint successfully for the past 3 weeks and it worked so far, flawlessly! Thanks for that!

Now i want to manually enable/disable the sensor. I want to enable/disable the sensor with a Hue Dimmer v2 (using this blueprint ZHA - Philips Hue v2 Smart Dimmer Switch and Remote - RWL022). I can already manually turn on&off the lights, but this automation keeps turning the lights off after the timeout i set (as it should to this point, so no problem thus far).

Now I created two helpers (Type - Toggle), one for enabling and one for disabling the sensor and added it to this automation like in your screenshot.
My problem is how to trigger this boolean correctly? In the dimmer blueprint i selected “Action Type - Condition → Condition Type - State → Entity - input_boolean.disable_sensor → State - on”. After saving the automation and pressing the power button two times (thats how i configured it for now) nothing changes, the occupancy sensor is still detecting occupancy.

Any help would be greatly appreciated and I hope my problem was appropiately described.

Hi, thanks for this blueprint. i was also stuck when trying to use the standard Hue motion one as it seems to be linked to the wrong entity in the SML001.

The issue i am having, that i don’t see anyone else reporting, is that the light only stays on for the time that occupancy is detected by the sensor. the 180s delay is ignored. i have changed other delay time periods but it always seems to go off after about 5-10s unless there is continuous movement.

No-one else seeing this?

I actually came back here because I have noticed the exact same issue, tried playing around with the settings and config a bit. But unfortunately I can’t get it to work myself.

i got this working fine in the end. My issues was that i had this automation and Adaptive Lighting fighting over the same lights. once i removed the adaptive lighting settings for this light it started working fine

are people still using this blueprint? does it work reliably like it would using a hue bridge? I just added a Phillips hue motion sensor using a conbee 2 with zha and it kind of seemed overly sensitive to triggering with occupancy I guess with this blueprint it can be fine tuned and work well? or has anyone switched over to zigbee2mqtt which i heard the hue sensor works well out of the box?

Hi there.
I recently added all my devices to ZHA instead of Philips bridge. And now trying the blueprint for the sensor. I am seeing the same issue as you where the light is only on while the occupancy is detected and turns off quickly after, the timeout 180 is not used. Did you ever find a fix for this.? Looks like there is not a lot of blueprints for the sensor or at least I can’t find them :grinning_face_with_smiling_eyes:

Now see you mention adaptive lighting was the cause. Here I just have a group of lights, mixed ikea / hue that turns on by the sensor and turn off again 10 seconds after instead of waiting the 180.

1 Like

yeah this is all working well for me still. Yes in my case i believe it was adaptive lighting that was conflicting with the timeout period. But for you and in general there must be something else that is also trying to control your bulbs and conflicting with the timeout settings

I haven’t used this Blueprint in a long while (I ended up going back to the Hue Bridge as ZHA is still not stable enough for my liking). Are you sure you have input the motion sensor Zigbee network id correctly? The default timeout 10s if I remember correctly, so if the 180s is not working it sounds like the unoccupied settings have not been programmed in the sensor.

Hi @wizbang :slight_smile:

you could get the Zigbee ieee device id as described here: Best way to get ZHA device ieee address?

best wishes :slight_smile:
Jesko

1 Like

Edit - just made my own blueprint instead. It automatically finds the ieee address and simplifies a few things.

Thanks for your blueprint which inspired mine.