Automated lux check loop


#1

1) Give a description of the problem
Issue with second half of piston executing. Light will turn off too fast, or not turn off at all.

2) What is the expected behaviour?
Piston is meant to run every 20 minutes. If the time falls between noon and sunset, and the relative light value drops below the ‘5 lux’ threshold, I want lights x,y to turn on. If on the next check-loop it shows the lux value has climbed back above 5 lux, I would like the same lights to turn back off.

3) What is happening/not happening?
The first part runs just fine and the lights turn on if the ‘below’ threshold is crossed. However it seems to turn the lights back off 2-3 minutes later, or not turn them back off at all, even if the lux value climbs back up above 5.

**4) Post a Green Snapshot of the piston!

5) Attach logs after turning logging level to Full
Don’t have logs currently, just looking for help to see if I made a coding error.

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

Two immediate thoughts:

  1. You want ‘if’ not ‘while’. A ‘while’ loop will repeat continously while it is true. Were it not for a twenty second limit on execution time, those loops could run for several hours.
  2. Your second ‘while’ is nested inside the first one. It needs to come after it.

So you want a structure like

Every 20 minutes
If …
End if
If
End if
End Every

A third thought, is that you could remove the ‘every’ timer completely and let the piston fire whenever the lux changes. If you did do that you might want a bit of space between the on and off levels e.g. turn on when less than 5 but turn off when greater than 10. Depends on what sort of readings you get.


#3

I totally agree with @orangebucket’s first two points, but I would encourage that you do not trigger on lux changes. That number bounces around nearly every second all day long!


#4

Thank you, I made the changes and made the ‘while’ loops into if blocks. The reason I want it to run every 20 minutes is the sensor only reports a relative lux value every 15 minutes (that is more of a relative number rather than an accurate measurement) I also would not want the lighting to keep changing every few minutes on a lux change, rather 20 minutes on if it gets overcast or cloudy/stormy, then it can turn back off if the light increases again. I’ve needed something like this for awhile, as setting the standard sunset/sunrise lighting doesn’t always cut it if the weather goes to crap. the 5 lux threshold is based on monitoring the sensor over the past few weeks. The number reported is too low, but it’s not really relevant if its serves the purpose needed.


#5

Wow… I have seen bottlenecks inserted before, but I’ve never one so severe before…


#6

Fair comment. My readings only update with motion so I’ve never seen a ‘proper’ one working.


#7

Smart.

I think lux works well as a condition, but not so good as a trigger:+1:


#8

It’s actually been working great. I agree a specific lux value would be a ridiculous trigger, however if it’s a relative example such as ‘if lux goes below this value’ then (trigger) I have had it running a few days now and it just seems to run naturally if there is low ambient light in the house. I’ll be setting up one outside soon that runs with a solar charge module to report values that will eventually be set for triggering the outdoor lights in lousy weather.


#9

Yes, an indoor lux sensor (if placed properly) can be real helpful.

It is the outside one that you can expect to have a lot of ‘fun’ with… LOL
(even a 5 mph wind blowing a branch can trigger many sensors)