Are you looking for a rolling average or just an average every five minutes?
For example, a rolling average would calculate a new average every time a new value is received on the MQTT topic. An average every five minutes would set a schedule to calculate the average every five minutes no matter how many values were received.
I would let persistence do most of the work for me and let it continue to store the “raw” values and use averageSince to calculate the average based on those stored values.
Create a new Item to represent the average and persist that to InfluxDB.
Rolling Average Implementation:
- Create a rule that triggers when the MQTT Item receives an average
MQTT_FiveMinAvg.postUpdate(MQTT_Value.averageSince(now.minusMinutes(5), "rrd4j") // assumes values are still in rrd4j
Every Five Minutes Implementation:
- Create a rule with a Time cron trigger to fire every five minutes
- Same line as above to calculate the 5 minute average and post it to the average Item.