Detection of irregular (high) consumer on a common line

Some kind of SmartMeter (in my case a 3Phase Rail Mounted Device up to 65A)
More than one consumer at that rail (otherwise detection against zero-Level is trivial)

Analysing History:
(In my case a wasching machine)

As can be seen we have peak at beginning, where the heating starts.
Depending on the load and water temperature the initial presented time never stays over the process (±30min) and sometimes even fail, when my wife or tenant put in to much cleaner.
Even measuring the level much before first peak and comparing during runtime might not be best, cause switching any light will distort.

Given Rule:

var waschingMaschine, maxWatt, deviationW, ttsFertig;

var dtf = Java.type("java.time.format.DateTimeFormatter");

var zdt = Java.type("java.time.ZonedDateTime");

function getZonedDateTime (datetime) {
  return zdt.parse(datetime + ' 00:00:00 +00:00', dtf.ofPattern('yyyy-MM-dd HH:mm:ss z'))

var persistence = Java.type('org.openhab.core.persistence.extensions.PersistenceExtensions');

if (typeof this.storedValues === 'undefined') {
  this.storedValues = [];

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);

waschingMaschine = 'ZWaveNode017ZMNHXDQubino3PhaseSmartMeter_Electricmeterwatts3';
maxWatt = (persistence.maximumSince(itemRegistry.getItem(waschingMaschine),;
deviationW = (persistence.deviationSince(itemRegistry.getItem(waschingMaschine),;
if (!(this.storedValues['done']) && maxWatt > 1500 && deviationW < 30) {
  ttsFertig = 'Die Waschmaschine ist fertig!';
  events.sendCommand('DavidsEchoFlex', ttsFertig);
  this.storedValues['done'] = true;
if (maxWatt < 100) {
  this.storedValues['done'] = false;

So the idea is to detect the consumer with its peak and send any alert when is comes steady.
This rule will be triggered every 5min from 6 AM to 12 PM.
The optional boolen is to prevent alerting all the time and will be resettet in a meaningful period (or optional with an adintional trigger, if I start a wasching-marathon without chance for reset.

I tested the Rule sucessfully over 3 weeks and will paste snipped of “deviation” and “variance” :wink:

1 Like


double total = 0;
int quantity = 0;
DecimalType histValue = null;
while(it.hasNext()) {
	State state =;
	if (state instanceof DecimalType) {
		histValue = (DecimalType) state;
		total += Math.pow(histValue.doubleValue()- average.doubleValue(), 2);
double variance = total / quantity;
deviation = Math.sqrt(variance.doubleValue());

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.