[RELEASE] Running Average 1.0

I needed to get an average over time of a sensor value, and was having trouble figuring out how to do it. So I ended up making an app to do it for me! Unlike other apps that average values of two or more devices, I wanted something that tracks the value over time and reports the average value.

Setting up
This uses two hub variables: a string to contain a list of recorded values, and a number/decimal to save the average value to (number probably makes more sense when you're averaging something that's on a scale of 0-100). These must be created prior to creating a Running Average instance.


How to use
First, set up a periodic rule in Rule Machine, at the desired interval. You can either have it append your numeric sensor value directly to a list variable, or—as shown below—if the sensor has different states, record them as numeric values (like here, my acceleration sensor is either "active" or "inactive"):

Create a new instance of Running Average; specify your input variable name (the list variable your rule saves to), and then an output variable to save the average to. You can also specify a maximum list length: this, times your interval in your Rule Machine rule, dictates how long the average is taken of (e.g. 3 seconds × maximum length 40 = 120 second running average).

To use it, just make another rule based on the output variable, like so:


Tip: The ideal process is probably:

  1. Create your list variable and output variable
  2. Create your Running Average instance
  3. Create the rule that builds the list
  4. Create any rule(s) to that are based on the average

Running Average keeps the list truncated to the specified number of values, which is why I recommend creating the Running Average instance before creating the rule that builds the list (especially if it runs on a short interval).


It's simple, it's probably a bit silly and inefficient, but it accomplishes what I need. Hopefully someone else finds it useful, or finds some other creative use for it!

It's on GitHub, and also published in HPM:
Running Average in HPM

6 Likes