Light level automation

Hi! I’m using Home Assistant on Rpi4. I cant get my light level dependant automation to work properly.

I want some lights to turn on when my Philips Hue Motion Sensor detects light below 350 lux for 10 minutes.
As an example: I go to bed at night, light level is 1 lux. A car drives by and it’s lights bring light level over 350 lux, just for a second or two. Now the automation should not go off. It has to to be over 350 lux for 10 minutes. But no!
After 10 minutes the automation will go off and turn on my lights.

I have created a binary_sensor wich turns off below 350 lux to trig the automation. Earlier I had the automation to trig from numeric_state direct from the Hue sensor. Same result though.
Automation made from front end.

I must be doing some simple beginners mistake?

`

alias: Tänd lampor skymning
  trigger:
  - platform: state
    entity_id: binary_sensor.over_350_lux
    to: 'off'
    for: 00:10:00
  condition: []
  action:
  - entity_id: light.tv_rum_flatad_lampa,light.tv_rum_lampa,light.ytterdorr,light.golvlampa,light.tv_rum_fonsterlampa,switch.koket_fonster,switch.kontor_fonsterlampa,switch.julias_fonsterlampa,light.lilla_fonsterlampan,light.vita_bollenlampa
    service: homeassistant.turn_on
  mode: restart
- platform: template
  sensors:
    over_350_lux:
      friendly_name: "Dagsljus"
      device_class: light
      value_template: "{{ states('sensor.lightlevel_22')|float > 350 }}"
      icon_template: >-
          {% if is_state("binary_sensor.over_350_lux", "on") %}
            mdi-weather-sunny
          {% else %}
            mdi:weather-sunset-down
          {% endif %}

`

The scenario you describe does this…

The light is off and the lux is 1.

A car drives past and the headlights bump the lux to 350 or more.

The sensor changes to on.

The car goes out of sight, the lux level drops back to 1.

The sensor changes state to off.

The automation triggers ten minutes later, exactly as you programmed it to.

The problem is with your logic :slightly_smiling_face:

Your’e exactly right! But how can I avoid that? I want to turn on the lights if my light level has been under 350 lux for 10 minutes.
I don’t won’t them to go off just by a car at night or some cloud passing by obscuring the sun.

From what I understand you want the trigger ‘on’ for 10 min then turn on the light. The issue is your trigger.

You may need a condition for sun so that it would only do this at night, otherwise it will do it during the day after 10 mins of light above 350 also.

My issue appears at night. When the surrounding light level is below 350 lux.
I belive the issue is ”for 10 minutes”! What I have read, ”for” is how long time a certain criteria is fullfilled. In my case the light level.
If the light level has been under 350 lux ”for” 10 minutes, then the automation will go off.
I may very well have misunderstod that! In that case, can somebody tell me the correct way to do this?
If light levels go under 350 lux for 10 minutes, then turn on the lights. I’m sure it must be an easy way to do it. Or?

No, you don’t, because then every time a car drives past your light will come on 10 minutes later. You’ve got yourself mentally stuck in the wrong logic here and need to think about it differently.

I agree with Marc, we could just write the automation for you but that way you won’t learn from it.
Try writing it out, line by line as if you were explaining it to a child.
And at each step, write the real world conditions you expect to happen, in order for your automation to happen, bearing in mind what you don’t want to happen.
Once you have that, use it to explain to someone else.
Pick holes in it, kick it around, make sure it’s right.
Then you can look at code for that written description.

Another question, 350 lux is quite a lot of light, so when the sun is not bright enough you want the light on.?
That continuous light, that energy inefficient.

Ok so I have reread what you are asking, as has been stated already, what you are asking it to do, it is doing. What you need to do now is work out under what conditions it should do it. If you don’t want it going off randomly during the night either a time condition or an input_boolean to switch it off may be an idea, or just turn off the automation via another automation. Or perhaps you need a condition to only turn on if the light was above 350 for a minimum period of time before dropping below 350.

You have the beginning of your idea sorted, now you need to refine it.

This all very confusing, and I think if you express it clearly, the answer will emerge.

Or get better curtains :slight_smile: