Handling sunset and low light conditions question

According the the HA docs using the sun’s elevation in a trigger or condition is preferable to using sunset. I just found out about the elevation option today! Anyway, I was going to only use elevation, but then it occurred to me that occasionally when it is stormy, cloudy, and dark, I want the lights turned on when my porch motion sensor detects motion. So I wound up with the automation below which uses elevation AND illuminance. Does this seem like a good approach or am I missing something?

-Thanks

alias: Porch Motion Sensor New
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.motion_sensor_gen2_motion_detection
    to: "on"
    enabled: true
conditions:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.porch_motion_sensor_illuminance
        below: 10
      - condition: numeric_state
        entity_id: sun.sun
        attribute: elevation
        below: 4
    enabled: false
actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id:
        - switch.porch_light
  - action: light.turn_on
    metadata: {}
    target:
      entity_id:
        - light.office_lamp_3
        - light.living_room_lamp
    data: {}
mode: single

I am not sure on the calibration of your illuminance sensor, specifically does it ever occur that:

  • The sun is below 4 degrees of elevation. (and)
  • Illuminance is still bright (>= 10)

If that doesn’t, happen then the sun elevation is irrelevant you could just use the Illuminance check.

The corner case I thought of would be a car approaching at night where the headlights were bright enough to raise the luminance at the same time as the motion sensor tripped - in which case you may still want both conditions.

Illuminance sensors built into motion sensors generally do not update until after motion is detected. This is done to preserve battery.

This will result in a race condition where your lights won’t turn on because the condition is checked before the illuminance is updated.

Add a slight delay to your trigger (for: 00:00:01 or less) if you’re running a battery motion sensor.

I should have mentioned that it is the Phillips Hue outdoor motion sensor. I’ve read it updates every 5 minutes (without motion detection). Which seems more than adequate. I don’t have the sensor yet, but when I do I plan on tweaking the elevation and illuminance values. I’ll certainly keep your delay advice in mind.

-Thanks

It is the Phillips Hue outdoor motion sensor. I’ve read it updates every 5 minutes without motion detection. I was also thinking I might just need to use illuminance but wanted to get other’s advice.

-Thanks

Yeah, if it’s half as reliable as you read, then you don’t really need the sunset condition unless there’s light pollution (neighbours, streetlight, headlights).

The only way you’re gonna figure it out is to install the motion sensor & monitor the illuminance for a week before starting on the automation.

I had a similar thought, how the neighbors lights (and mine) would affect the illuminance at night. It will be interesting finding out!

-Thanks

Alternative solution is to use template that calculate light level out of sun elevation and weather conditions. You can find it here: Outdoor illuminance template sensor. The good thing is that is independent from any ‘light pollution’ factors. Bad… it can only estimate illumination level and might be as good as your wether integration.

Thanks, that does look interesting!

I would also note that is sometimes it is worth asking: Is it “Good Enough”?

Say you go with the just Sun Elevation + Motion, but you tweak it a bit: 6 degrees above the horizon instead of 4

There will be a few times every year when there is motion (on a bright day) where the light wasn’t really needed.

Is that really a problem - or is it good enough?


I have found that accepting “Good Enough” can save a bunch of time on trying to “fix” very occasional problems - or to put that another way give you back time to work on problems that are actually really annoying.

Oh, I thought that using an elevation of 6 degrees would always result in the same lighting outside. I used 6 to turn off my front porch light, which seemed like a good time to turn it on.

-Thanks