Page 1 of 1

Light Sensor erratic - averaging flow?

Posted: 04 Oct 2015 19:15
by Wibbly
My tablet has quite eratic values returned from the Light Sensor. This causes eratic behaviour in flows that rely on the Light Sensor condition.

I can build in a little hysteresis in my flows but I also need this based on an average value of the Light Sensor reading rather than an instantaneous value.

Has anyone developed a flow that would do the averaging function? Say, taking continuous readings once a second (so long as the screen is on) and setting a global variable to the average value of the last 10 readings (so it would a moving average)? Not sure how best to implement it.

Anyone else found a solution they can share?

Re: Light Sensor erratic - averaging flow?

Posted: 06 Oct 2015 18:25
by Wibbly
Ok, so the only way I can get a script to see the light value is to run the Light Sensor condition outside of the script, right?

And the script should use an array to implement the moving average, but needs to run in loop implemented outside of the script so the script can see updated light values as it populates successive values in the the array...

Does this sound right? And there is no averaging function, or smoothing option in the Light Sensor condition, right?

Re: Light Sensor erratic - averaging flow?

Posted: 07 Oct 2015 18:15
by Martin
There's no averaging function built into the condition so you would have to execute the condition in a loop, fill a list in each iteration and then build the average.
What does erratic values mean? Does the sensor return an extremely high value at times?

Re: Light Sensor erratic - averaging flow?

Posted: 07 Oct 2015 18:58
by Wibbly
Use case is to detect night/near 0 lux to trigger night-mode brightness. I have threshold at 5 lux which seems about right but I can see in the condition settings it's very noisy/hunting at these low levels.

In total darkness it stays at zero lux most of the time, but occasionally blips to a few lux....

Re: Light Sensor erratic - averaging flow?

Posted: 08 Oct 2015 17:26
by Martin
I see, then an average definitely makes sense. I add it to the todo-list.

Re: Light Sensor erratic - averaging flow?

Posted: 08 Oct 2015 18:50
by Wibbly
Thanks!

I think it's the moving average that's key, so maybe this requires a condition that retains n previous Light Sensor values, and each execution removes the oldest value and adds the current value, testing and setting a variable for the new average?

Re: Light Sensor erratic - averaging flow?

Posted: 10 Oct 2015 08:33
by Martin
I will probably include an option directly within the trigger and condition, probably the same way as I have done for trigger/condition Sound Level.

Re: Light Sensor erratic - averaging flow?

Posted: 12 Oct 2015 08:00
by Wibbly
Martin wrote:I will probably include an option directly within the trigger and condition, probably the same way as I have done for trigger/condition Sound Level.
Thanks! :)