Light Sensor erratic - averaging flow?

Post your questions and help other users.

Moderator: Martin

Post Reply
Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Light Sensor erratic - averaging flow?

Post by Wibbly » 04 Oct 2015 19:15

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?

Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Re: Light Sensor erratic - averaging flow?

Post by Wibbly » 06 Oct 2015 18:25

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?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Light Sensor erratic - averaging flow?

Post by Martin » 07 Oct 2015 18:15

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?

Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Re: Light Sensor erratic - averaging flow?

Post by Wibbly » 07 Oct 2015 18:58

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....

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Light Sensor erratic - averaging flow?

Post by Martin » 08 Oct 2015 17:26

I see, then an average definitely makes sense. I add it to the todo-list.

Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Re: Light Sensor erratic - averaging flow?

Post by Wibbly » 08 Oct 2015 18:50

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?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Light Sensor erratic - averaging flow?

Post by Martin » 10 Oct 2015 08:33

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.

Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Re: Light Sensor erratic - averaging flow?

Post by Wibbly » 12 Oct 2015 08:00

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! :)

Post Reply