Meter Reading II [4.3.0.0;5.9.9.9]

This is a simple rule that works with an accumulating sensor reading that can be reset unpredictably. For example, a sensor that keeps track of the total kWh used but resets back to zero when the sensor loses power.

The rule will add the delta from the previous reading to the current reading to the Item holding the total. However, when the sensor Item gets reset the rule treats the current reading as the delta. Therefore, this rule only works for an accumulating sensor where the reported reading is always increasing.

If the total Item is NULL or UNDEF, it’s initialized to 0 and the delta becomes the first value.

If the Items have units, all operations are done within those units. The base unit is the unit of the meter Item.

Managing the total Item (e.g. resetting it once a day, adding up the sum for the week or month, etc.) are not handled by this rule.

Language: JavaScript

Dependencies:

  • JS Scripting add-on

Changelog

Version 1.1

  • fixed bug where one of the Items remained hard coded in the code for quantity types.

Version 1.0

  • initial rewrite from the OH 3.0 version of the template

Resources

https://raw.githubusercontent.com/rkoshak/openhab-rules-tools/refs/heads/main/rule-templates/counting/counting2.yaml

4 Likes

The URL must end with .yaml or .json or the link won’t register. It doesn’t help that the actual content is a YAML file, it is never processed.

Thanks, I missed the . between the file name and the extension when I created the file apparently.