Hue Motion sensor with illuminance condition

Hi,

I’m using a hue motion sensor with a yeelight that shall be turned on when a motion is detected.

I have the following automation rule:

 - id: '1563820549062'
   alias: Turn on lights in living room
   trigger:
   - entity_id: binary_sensor.living_room_hue_motion_movement
     platform: state
     to: 'on'
  condition:
  - below: '8000'
    condition: numeric_state
    entity_id: sensor.living_room_hue_motion_illuminance
  action:
  - data:
      entity_id: light.living_room_light
    service: homeassistant.turn_on
  - data:
      entity_id: timer.turn_off_living_room_lights
    service: timer.cancel
  - data:
      entity_id: timer.turn_off_living_room_lights
    service: timer.start

It works in general, but sometimes when the light goes off and I start moving again, I see that the hue motion sensor reacts, but it doesn’t trigger the lights.

I’m using zigbee2mqtt to communicate with the hue motion sensor and no other components.

I checked the zigbee logs and found the following:

  zigbee2mqtt:info 7/25/2019, 9:30:15 PM MQTT publish: topic 'zigbee2mqtt/living_room_hue_movement_sensor', payload '{"battery":100,"linkquality":0,"illuminance":11142,"temperature":27.78,"occupancy":true}'
  zigbee2mqtt:info 7/25/2019, 9:30:15 PM MQTT publish: topic 'zigbee2mqtt/living_room_hue_movement_sensor', payload '{"battery":100,"linkquality":0,"illuminance":0,"temperature":27.78,"occupancy":true}'
  zigbee2mqtt:info 7/25/2019, 9:30:17 PM MQTT publish: topic 'zigbee2mqtt/living_room_hue_movement_sensor', payload '{"battery":100,"linkquality":0,"illuminance":0,"temperature":27.78,"occupancy":true}'

So, I think the problem is that if it detects a movement it still has the old illuminance value (when the light was on) and then the condition fails. Any ideas how to work around that?

@ZzetT

I’m currently trying to solve this problem, but I’ve got a solution that works 90% of the time. The Hue Motion Sensor only updates the light level when it detects motion, or every 3 or so minutes. This is surely a battery saving measure.

Therefore if you add a small delay between detecting motion and evaluating the light level condition, it should give it enough time to detect the updated light level.

I did something like this:

trigger:
- entity_id: binary_sensor.motion_sensor
  platform: state
  to: 'on'
  for:
    seconds: 1

Usually 1 second is enough for my setup to update the light level, but it’s not always firing, I might experiment with longer delays, but I’m currently looking for a better way to do it.

2 Likes

Hi @Sabellwind
That’s exactly what I’m having to do but I’m hoping to get rid of the delay because I want the lights turning on instantly

Did you find a way to make them work instantly and with illuminance detection?

Nah, I didn’t. Ultimately, I think it’s because of the design of ZigBee being such a battery efficient protocol. You’d have to change the way the sensor behaves, which I have no idea how to, or if that would even be practical from a battery life standpoint.

Yeah I timed my motion sensors, they send an update every 5 mins.
So made my automation last a little over 5 mins keeping my lights on and being accurate when using the illumination condition

Now I don’t have to use the for:00:00:01

Post your code? Would love to see how you went about it

This is my turn on lights automation

  alias: Office Lights on (zigbee hue)
  description: ''
  trigger:
  - entity_id: binary_sensor.motion_hue_office
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: template
    value_template: '{{ states.binary_sensor.motion_hue_office.attributes.illuminance
      < 12000 }}'
  action:
  - data:
      brightness: 255
    entity_id: light.office_lights
    service: light.turn_on

This is the turn off lights automation

  alias: Z Office Lights Motion OFF
  trigger:
  - entity_id: binary_sensor.motion_hue_office
    for: 00:05:10
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      entity_id: light.office_lights
    service: light.turn_off

So the lights don’t turn off for 5 minutes after the last motion is detected, therefore there would have been at least one update of the sensor
Hope that makes sense

Hey mate, it’s a better way to do it. Just wish the turn off delay was less.

I recently bought a bunch of aqara motion sensors and they have an in built delay of 2 minutes before updating the detected attribute AND Lux value, so you can get the same effect but for less time better intervals.

They’re also way cheaper and smaller. Just found that the temperature sensor isn’t as accurate.

1 Like

I found a way to have shorter delay.

Turns out we can use milliseconds as well
This is what I’ve been using for the past 2 minutes :slight_smile:


Give that a try
  trigger:
  - entity_id: binary_sensor.motion_office_occupancy
    for:
      milliseconds: 200
    platform: state
    to: 'on'

Give that a go

1 Like

Hi, im trying what you do but dont want any motion needed, just the illuminance to be “sunshine” then drop my curtains, but im testing with a lamp still. Is that not possible, is motion always needed? If not maybe you can tell whats wrong in the logic?

`- id: ‘158592xxxxxx0’
alias: Ljus på när det blir ljust ute
description: Testar om Shelly kan funka
trigger:

  • entity_id: sensor.hue_motion_sensor_1_light_level
    from: <30000
    platform: state
    condition: []
    action:
  • brightness_pct: 78
    device_id: f3795bf1d88a4fxxxxxxxxxxxxxxxx58
    domain: light
    entity_id: light.hallway_amb_spot_3
    type: turn_on`
1 Like

This is still such an annoying issue… Did someone find a better solution for this issue, I’ll be using time for now I guess instead of illuminance which sucks. I did find https://flows.nodered.org/node/node-red-contrib-huemagic but that requires you to have an actual bridge which I don’t have.

I am using a node-red delay node, 200ms seems to be working indeed, might trying some lower values later on :smiley: Update: 100ms seems to work as well.

2 Likes

I’m facing this issue as well… I tried the 200ms (without node-red) but did not made any difference… Sometimes my sensor does not even update when there’s movement.

I’ve solved the issue by storing the ‘ambient’ illumination in a helper, ignoring any change in values when the light is on. This, for me, was what was the main reason for causing the light level to go up and stop my automation working.

alias: "Store background lux"
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.hue_motion_sensor_1_illuminance
    attribute: light_level
condition:
  - condition: device
    type: is_off
    device_id: XXXXXXXXXXXXXXXX
    entity_id: light.landing
    domain: light
action:
  - service: input_number.set_value
    data:
      value: "{{ states('sensor.hue_motion_sensor_1_illuminance') | int}}"
    target:
      entity_id: input_number.ambient_lux
mode: single

I then only switch if ambient.lux is below a set value.

1 Like

Awesome solution, thanks! :star_struck:

@Achronite @JIK I am trying to use the mentioned automation as well to store the illuminance value of a hue motion sensor before the brigthness of a lamp that is being turned on changes the illuminance value and thereby does not let the conditional automation turn on the light anymore after being turned off because the illumance reading of the motion sensor would be too high at that point (at least for 5min until the motion sensor updates to real illuminance again).

I would like to use the ambient_lux helper in combination with this blueprint which lets me define a cutoff value, which would be the ambient_lux value: Turn on light, switch, scene, script or group based on motion, illuminance, sun (+ more conditions).

So I changed the entity and device ids from your automation to my setup and also created a number helper with the name ambient_lux. However, the illuminance value is not stored in that helper at all. I bet I am doing something wrong but I cannot figure out what.

Would you be so kind to elaborate on the whole automation you are using?

Thanks a lot for your support!
arne

My use case is simple, I didn’t need all the extras that blueprint gives you. This is my ‘turn-on’ routine:

alias: Hallway-lights-during-day
description: ""
trigger:
  - type: occupied
    platform: device
    device_id: xxxx
    entity_id: binary_sensor.hue_landing_pir_occupancy
    domain: binary_sensor
condition:
  - condition: or
    conditions:
      - condition: sun
        after: sunset
        before: sunrise
        after_offset: "-01:00"
      - condition: numeric_state
        entity_id: input_number.landing_ambient_lux
        below: 3
action:
  - service: light.turn_on
    data:
      brightness_pct: 100
    target:
      area_id: hallway
mode: single

My lux threshold is stored in the automation, but you could substitute it for a ‘Number’ helper here if you want it configurable.

The turn off routine does not use the lux at all (as there is no harm turning a light off when it is already off!).

However, the illuminance value is not stored in that helper at all

Do you still have the automation (in my original post) running? Check if that is being executed first. If it is then maybe the blueprint is changing it, or deals with the original lux issue a different way?

Thank you for your quick answer!

I just re-created the automation from your original post. I changed the motions sensor ID and its entity, as well as the light that is supposed to be off. In addition, I also created the helper input_number with the name ambient_lux, resulting in the same entity that you have in your automation. When I created that ambient_lux helper, the value is 0 of course. As far as I understand the automation, once the illuminance changes while the light in that room is still off, the value of the ambient_lux helper should change to whatever new illuminance there is.

As I did not want to wait, I tried simulating the change in illuminance by setting the value of the ambient_lux helper manually to 50, turning the light on by motion, so the illuminance in that room changed to 237, then after some seconds the light turned off again (= 0 lux), which resulted in the motion sensor reading and showing the new illuminance of 0.

However, the ambient_lux helper did not change to 0 but stayed at 50. Is by any chance my manual input somehow overriding the service to write the change in lux into the helper within the automation?

Hi @Achronite ,

I tried it again under real circumstances by closing the automatic blinds in that room during the day and thereby simulating the lux change at dusk.

Unfortunately, the automation to store the ambient lux value is not executed when the lux value changes. I can execute the automation manually which results in the lux value being stored in the number helper as it should, but regular lux changes do not trigger the automation at all.

Do you have any clue as of why? I use a Philipps Hue motion sensor connected via Zigbee2mqtt and in general I can see the lux value changing when I look at the sensor‘s illuminance entity.

Can you please paste the yaml for your automation that captures the ambient_lux?

Also, check that the device_id & entity_id exactly match that of your z2mqtt device. You can also check the automation runs using the ‘TRACES’ button on the automation.