Hue Motion sensor with illuminance condition

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.

Sure, please see below and thanks for your help in advance @Achronite !

I wonder though: You say the device_id and entity_id have to match the z2mqtt device, which is the hue motion sensor. For that, only the entity_id is set two times within the automation as far as I can see: First to capture the light level change and at the very end to make sure the new value is written into the helper. For the light in the condition on the other hand, there is both, the device_id and the entity_id.

When I hit traces, there are no traces found. I guess this is because the automation does not kick in by itself. Only when I execute it manually, the current value of the lux captured by the motion sensor is stored into the helper. A change in lux does not change the value of the helper. All of course while the target light mentioned within the condition is off.

I use illuminance_lux entity instead of illuminance as in your example because that is the one activated by default for that sensor. It works as I can see the lux value changing during the day. The illuminance entity (without _lux) is disabled. Might that be the reason? I thought these two entities are basically the same just a different conversion from raw value to lux value.

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

Got it working by deleting the attribute “light_level”. Sometimes things can be so easy. Now the automation works as expected and the light level is “copied” into the number helper as it should.

1 Like