Wind Average Over Time


#1

1) Give a description of the problem
I have a piston currently that turns on a switch when it is windy so that my motion lights get turned off outside so that the neighbors don’t get pissed. I live in New Mexico so we get a lot of wind in the spring. Currently, it pulls information from my Ambniant weather station every few minutes and if the gust is over X and the wind is over Y turn on the switch. We the wind could stop or slow down enough to turn off the switch and then gust enough to turn on the lights.

2) What is the expected behavior?
Instead of getting the current, I would like to run an average over 10 minutes and use those numbers, So as new reading comes in the last number drops off and you get a new average. I am not sure what the best way to do that. Anyone have anything like this or a recommendation.

3) What is happening/not happening?
Not a proper average

4) Post a Green Snapshot of the pistonimage
(UPLOAD YOUR IMAGE HERE)

5) Attach logs after turning logging level to Full
(PASTE YOUR LOGS HERE THEN HIGHLIGHT ALL OF THE LOGS AND CLICK ON THE </> ICON TO FORMAT THEM CORRECTLY)

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


#2

I’m not sure if this would give you what you need…

Have a piston run every min, and store the current speed in an array. (loop an index from 1 to 10 each time, and reset at 10 - it doesn’t matter where the current value is in teh array, it just over rights the oldest)
Then work out the average, and if above your threshold turn the switch on, otherwise turn off.


#3

Yea that is what I want to do kind of like a stack array but not sure how you would do it in WebCore


#4

You can create integer arrays
image
and use as in other languages e.g
image


#5

I am looking at doing the form of push/pop just like you would do in C++ or some other language. I know how to create arrays just need to figure out how to move values from index NEW VALUE—>10, 10–>9, … If you just move index to index-1 will it actually just take the new value and end up putting it in all array elements because you are not storing the other elements before overwriting them.


#6

webcore is a little less flexible than c++, so you cant say e.g
count_down[index] = count_down[indx] -1
You have to do the following
image

I think its the way it handles/expands expressions

However, do you need to implement a push stack? If you just need to average e.g 10 readings, just cycle indx e.g
stored-val[indx++] = current_val;
if indx == 10 then indx=0;


#7

Why would this not work. It just keeps putting the windspeed into the first position. It is early and my mind is not awake image


#9

I don’t think web core can Evaluate [ Indx -1] you need to create a new var indx2=indx - 1 then use indx2


#10

cool thx