Jump to content

V5 - averaging using only the best values


larryllix

Recommended Posts

This is a program I created to stabilise inputs from more than one source. Any "wild" sensor inputs get cut out of the calculation.

 

Operation

  •  the last known working average is kept for comparison purposes during the next iteration.
  • a constant $cAVERAGE.DEV.MAX variable is set to the allowable deviation limits for a sensor to be considered "bad".  I have set mine to 2.0 degrees for this purpose
  • each input is compared to the last known average and the absolute value compared to the allowable deviation factor.
  • good sensor readings are tallied and used to calculate the new average
  • if all values are outside the maximum deviation then a completely new average is created from all sensors.

 

Benefits

  •  gives a more stable resultant
  •  detects and isolates any sensors gone bad or "out-of-range of the crowd" readings.
  •  gives a contributor count that can be used for other purposes. eg: Temperature variance detection for circulation. fan operation from indoor temperature sensors
  •  I have a temperature sensor mounted up under a PV array and the oven effect gets disallowed every late morning with this program.
  • this can use as many sensors as available to further stabilise the resultant output. Just add more lines of program code.
  • ISY is fast. No delays can be noticed and lots of repeats allows other processing to occur during the calculations.

 

Negatives

  • based on slow changing sensor values like temperature readings from thermostats and probes. Sudden value jumps may disrupt the process.
  • all three sensors outside the past average results in including all three sensors to start. This may not be the best algorithm for some cases.
  •  
  • we sure could use an inline If/Then construct in v5. :)

 

-----------------------------------------

Sync.outTemp.average - [iD 00FE][Parent 0101]

If
        $sTag3.temp < 40
     Or 'Gathering Room / GathRm VenStat' Sensor < 45.0°
     Or $sWC8.outTemp.raw < 450
 
Then
        $Average.sum  = 0
        $Average.contrib.cnt  = 0
       
        // sum inputs within dev.max of past average and keep count
 
        $Average.deviation  = $sWC8.outTemp.raw             <--WC8 board ships to ISY x 10 integers only
        $Average.deviation /= 10
        $Average.deviation -= $sHouse.outTemp
        Repeat While $Average.deviation < 0                        <----- calculate the absolute value 2 lines
           $Average.deviation *= -1                                         <----- make a negative, positive
        Repeat While $Average.deviation <= $cAVERAGE.DEV.MAX
           $Average.sum += $sWC8.outTemp.raw
           $Average.sum /= 10
           $Average.contrib.cnt += 1
           $Average.deviation  = 999                                       <-----terminate the Repeat loop
        Repeat 1 times
           $Average.deviation  = 'Gathering Room / GathRm VenStat' Sensor °
           $Average.deviation -= $sHouse.outTemp
        Repeat While $Average.deviation < 0
           $Average.deviation *= -1
        Repeat While $Average.deviation <= $cAVERAGE.DEV.MAX
           $Average.sum += 'Gathering Room / GathRm VenStat' Sensor °
           $Average.contrib.cnt += 1
           $Average.deviation  = 999
        Repeat 1 times
           $Average.deviation  = $sTag3.temp
           $Average.deviation -= $sHouse.outTemp
        Repeat While $Average.deviation < 0
           $Average.deviation *= -1
        Repeat While $Average.deviation <= $cAVERAGE.DEV.MAX
           $Average.sum += $sTag3.temp
           $Average.contrib.cnt += 1
           $Average.deviation  = 999
          
        // none worked, get all new
 
        Repeat While $Average.contrib.cnt is 0
           $Average.sum  = $sWC8.outTemp.raw
           $Average.sum /= 10
           $Average.sum += $sTag3.temp
           $Average.sum += 'Gathering Room / GathRm VenStat' Sensor °
           $Average.contrib.cnt  = 3
        Repeat 1 times
          
        // finish calcs with what we got
 
           $Average.sum /= $Average.contrib.cnt
           $sHouse.outTemp Init To $Average.sum
           $sHouse.outTemp  = $Average.sum
 
Else
   - No Actions - (To add one, press 'Action')
 

Link to comment

Hi larryllix,

 

This is more than fantastic. Thanks so very much!

 

With kind regards,

Michel

Thanks Michel!

 

After monitoring it for a few weeks I have substituted it into my official outdoor temperature now.

It works well and cuts one sensor out of the formula when the sub shines intensely as it gets affected.

 

If one ever fails things should just carry on without it.

Link to comment
  • 1 year later...

Somehow this program got deleted and I had to recreate it.

 

This is my latest using NodeLink input from the Ecobee current  weather reporting.

Sync.Temp.out.average - [ID 00FE][Parent 0101]

If
        $sTag3.temp < 45
     Or 'Dining Room / GathRm Stat / Current Weather' Temperature <= 45.0°
     Or $sWC8.outTemp.raw < 450
 
Then
        $TempAvg.sum  = 0
        $TempAvg.contrib.cnt  = 0
        
        // sum inputs within dev.max of past average and keep count
 
        
        // start with sensor 1, if within deviation allowed
 
        $TempAvg.deviation  = $sWC8.outTemp.raw
        $TempAvg.deviation /= 10
        $TempAvg.deviation -= $sHouse.outTemp
        Repeat While $TempAvg.deviation < 0
           $TempAvg.deviation *= -1
        Repeat While $TempAvg.deviation <= $cTEMPAVG.DEV.ALLOWED
           $TempAvg.sum += $sWC8.outTemp.raw
           $TempAvg.sum /= 10
           $TempAvg.contrib.cnt += 1
           $TempAvg.deviation  = 999
        Repeat 1 times
           
        // add in sensor 2, if within deviation allowed
 
           $TempAvg.deviation  = 'Dining Room / GathRm Stat / Current Weather' Temperature °
           $TempAvg.deviation -= $sHouse.outTemp
        Repeat While $TempAvg.deviation < 0
           $TempAvg.deviation *= -1
        Repeat While $TempAvg.deviation <= $cTEMPAVG.DEV.ALLOWED
           $TempAvg.sum += 'Dining Room / GathRm Stat / Current Weather' Temperature °
           $TempAvg.contrib.cnt += 1
           $TempAvg.deviation  = 999
        Repeat 1 times
           
        // add in sensor 3, if wihin deviation allowed
 
           $TempAvg.deviation  = $sTag3.temp
           $TempAvg.deviation -= $sHouse.outTemp
        Repeat While $TempAvg.deviation < 0
           $TempAvg.deviation *= -1
        Repeat While $TempAvg.deviation <= $cTEMPAVG.DEV.ALLOWED
           $TempAvg.sum += $sTag3.temp
           $TempAvg.contrib.cnt += 1
           $TempAvg.deviation  = 999
        Repeat 1 times
           
        // none worked, get all new
 
        Repeat While $TempAvg.contrib.cnt is 0
           $TempAvg.sum  = $sWC8.outTemp.raw
           $TempAvg.sum /= 10
           $TempAvg.sum += $sTag3.temp
           $TempAvg.sum += 'Dining Room / GathRm Stat / Current Weather' Temperature °
           $TempAvg.contrib.cnt  = 3
        Repeat 1 times
           
        // finish calcs with what we got
 
           $TempAvg.sum /= $TempAvg.contrib.cnt
           $sHouse.outTemp  = $TempAvg.sum
           $sHouse.outTemp Init To $TempAvg.sum
 
Else
   - No Actions - (To add one, press 'Action')
 


Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...