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?
Light Sensor erratic - averaging flow?
Moderator: Martin
Re: Light Sensor erratic - averaging flow?
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?
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?
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?
What does erratic values mean? Does the sensor return an extremely high value at times?
Re: Light Sensor erratic - averaging flow?
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....
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?
I see, then an average definitely makes sense. I add it to the todo-list.
Re: Light Sensor erratic - averaging flow?
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?
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?
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?
Thanks!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.
