#7
Post
by Domosapiens » 15 Nov 2018, 01:06
Not a real moving average (FIFO), but an approximation.
Simplified (understandable) version of my hourly and daily temperature averaging.
(with thanks to my '80 teacher Digital Filtering, Prof. Dr. Hermann, of the University Twente)
Assumption:
1 sample per 10 min
Hour filter length=6
Define a Dummy task <x>, AV_hour
Val1: published Average
Val2: calculated Average
Val3: newest sample
Rule for hour filter:
On newest_sample Do
Taskvalueset,x,3,%eventvalue% //store newest 1/6th hour sample
Taskvalueset,x,2,(([AV_hour#Val3]*0.166)+([AV_hour#Val1]*0.833)) //take 1/6th of the new value plus 5/6th of the published hour value
Taskvalueset,x,1,[AV_hour#Val2] //promote the calculated Avarage to the published Average
EndOn
Day filter length=144
Define a Dummy task <y>, AV_day
Val1: published Average
Val2: calculated Average
Val3: newest sample
Rule for day filter:
On newest_sample Do
Taskvalueset,x,3,%eventvalue% //store newest 1/6th hour sample
Taskvalueset,x,2,(([AV_day#Val3]*0.0.006)+([AV_day#Val1]*0.0.993)) //take 1/6*1/24th of the new value plus 143/144*th of the published day value
Taskvalueset,x,1,[AV_day#Val2] //promote the calculated Avarage to the published Average
EndOn
For faster filter run-in give the published Average (Val1) a reasonable start value in the mid of the expected range.
For outside temperature .. say 10 degrees C.
On System#Boot Do
"initiate values"
EndOn
With the latest possibilities, you could use (I think):
On Time#Initialized Do
TaskRun <sensortask> //force first reading
"store first reading as published Average"
EndOn
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.