Logic of adjusting shutters to lightlevel [more complicated than it seems]

Hi

I tried to make what seemed to me a pretty straight-forward automation, but turned out to be more complicated than I thought.

I want that my shutter will be half-closed during the day, and fully opened during the night.

So I did two simple automations: (1) if lightlevel goes below 25,000 and stays like this for more than 2 minutes - open shutter; (2) if lightlevel goes above 25,000 and stays like this for more than 2 minutes - close shutter.

Simple, isn’t it? Not exactly.

The thing is, that when lightlevel is close to the 25,000 threshold, sometimes there suddenly may be a cloud in the sky (or other software glitch), which decreases lightlevel to 24,500, and after 30 seconds or so, it goes back 26,000. At this moment, when it goes above 25,000 - the shutter is being closed, which is not good, because the lightlevel was not changed, except those 30 seconds glitch.

I described the issue in the following chart:

My question is - how can I tell to Home Assistant to ignore those short glitches?

Hope I was able to explain my issue…

(Note - this is by far the post for which I invested the most since I’m in the HA business :grinning:)

Many thanks!!!

You could trigger on the sun’s elevation rather than light level. Less than 0 close the shutters. Greater than 0 open the shutters.

Thanks Tom. That’s what I had until now.
But I wanted to go a step further.
Say if it is a rainy day, I don’t want the shutters to be closed during the day.
I want the shutters to be synced with the actual light outside.

Also, my next step is to adjust the lighting in my house according to the light level outside, and then I will encounter the same issue - lights will go on and off repeatedly and I don’t want this to happen.

Where’s your light sensor?

Inside or outside?

Putting it outside is the way to solve the issues with internal lighting.

As for the cloud “glitches” your options are to increase the delay and/or decrease the trigger level.

My light sensor is outside of course.
What do you mean by increasing the delay or decreasing the trigger level?

e.g. 8 minutes and 18,000.

It won’t solve the problem.
Say my current lightlevel is 20,000. There’s a cloud and then it decreases to 17,000, and after 30 seconds it goes back to 20,000 and stays like this for half an hour. The shutters will still be closed, where in actual they’re not supposed to do any action.

Use average illumination over 30 or 60 minutes. And run an automation or NodeRed flow every 15 minutes for example and not more.

1 Like

Thanks Shaad. How do I use average illumination?

You could use the statistics sensor.

Or two of them.

Trigger when a two minute average is whatever percent below the 30 minute average you deem is needed.

I would not recommand using Statistics sensor. Or maybe it has changed. But I tested it one year ago the computed average value was not a temporal value !!!
For exemple : let’s say illumination is 0 for 9 minutes and then 10 for 1 minute, the output average over the last 10 minutes would be “5” with Statistics !!

Average Sensor is much more recommanded :
Average Sensor - Share your Projects! / Custom Components - Home Assistant Community (home-assistant.io)
From the previous example, the output average over 10 minutes would close be “1” with this component.

Or was at least… Maybe Statistics has evolved.

2 Likes

2 things :

  • Use average over 20 minutes for example and not current live value
  • Use 2 different thresholds : for example, open over 23 000, close under 17 000 instead of using 20 000 for both.

This way you will get way more hysterisis.

For which there is a binary sensor:

Thank you guys!
I installed the average sensor, and it seems to work fine. It’s already night time where I live, so I can’t test it right now.
Shaad - on Git it says - “when calculating the average, it does not take into account how much time the temperature value was kept” - Isn’t it what we wanted to avoid that occurs in the statistics sensor?

That’s talking about the disadvantages of the core statistics sensor. Which the custom average sensor overcomes.

Oh, ok then…
Great. So if it will work (and I have a good feeling it will), I will mark this thread as solved tomorrow.
Thank you very much!!

BTW, this is how the average sensor looks like on sunset, considering a 5 minutes average -

sensor

I think it looks great. Not volatile as with the original light sensor.

1 Like

Hi

One thing is not clear to me - which attribute should I take when creating an automation? What represents the light level?

Just the actual state, don’t select an attribute for what you want

Great, it works well.
Thank you everyone! This is much appreciated.