S0 counter from power meter - how to get kwh?

I see no reason why you would be getting that error. lastCount is defined as a var where it is supposed to be.

Try giving a hint by defining lastUpdate as an int.

var int lastUpdate = 0

Similarly give the same hint when you define newCommand:

var int newCommand = ...

The imports look OH for OH 1.8

Persistence would neither solve nor explain this problem.

With this changes i get “pointer exception null …” very much lines of errors…

Has to do with lastUpdate i think.

When removing the “int” from lastUpdate, i get the single error like before… cannot resolve lastUpdate to item or type.

Does Designer highlight anything as an error?

I don’t use it, have first to learn how to install it.

http://www.openhab.org/getting-started/downloads.html

Download the version for your OS. Press the folder icon in the upper left and select your configurations folder.

It won’t run on a Pi. If you are running on a Pi you need to share your /etc/openhab/configurations folder via samba or copy that folder to some other machine, edit it there, then copy the edits back over.

I did this yesterday - but i got warnings/errors on nearly each line.

So i renamend the rulefile to *.txt and will test it again, when i make the update to OH2. I will wait the few days until final release and then start from the beginning with a new installation.

Thanks for your help.

I tried to get this rule running again…

But i get an error, i hope, someone can help me?

The error is because of the variable “average”.

// Variablen Stromzähler Wärmepumpe
var lastUpdate = null
var lastCount = 0
var ticksBetween = 5

var smoothingSamples = 2
var total = 0.0d
var average = 0.0d
val samples = newLinkedList()


rule "Stromzaehler Waermepumpe Berechnung Watt"
when
  Item HeatPump_Stromzaehler received command
then
	logInfo("Stromzaehler Waermepumpe Berechnung Watt", "Stromzähler received Update")
	/*
	* Take 2: React on every input, get the time inbetween and calculate power based
	* on time passed.
	* Very granular, calculation takes about 20ms on Raspi3B
	*/
	var newCommand = (receivedCommand as DecimalType).intValue 
	var tickDiff = newCommand - lastCount
	logInfo("Waermepumpe Berechnung Watt", "newCommand: " + newCommand)
	logInfo("Waermepumpe Berechnung Watt", "tickDiff: " + tickDiff)
	if (lastUpdate !== null && lastCount > 0) {
			if (tickDiff == ticksBetween) {
					var startMillis = now().millis
					var nowMillis = now().millis
					var lastUpdateMillis = (lastUpdate as DateTime).millis
					var diff = nowMillis - lastUpdateMillis
					var watt = ((1800.0 / diff) * 1000.0 * ticksBetween) as Double
					logInfo("Waermepumpe Berechnung Watt", "startMillis: " + startMillis)
					logInfo("Waermepumpe Berechnung Watt", "nowMillis: " + nowMillis)
					logInfo("Waermepumpe Berechnung Watt", "lastUpdateMillis: " + lastUpdateMillis)
					logInfo("Waermepumpe Berechnung Watt", "diff: " + diff)
					logInfo("Waermepumpe Berechnung Watt", "watt: " + watt)
      				// Calculate moving average
					if (samples.size == smoothingSamples) {
  							total -= (samples.first as Double).doubleValue
  							samples.removeFirst
  					}
  			total += watt
  			samples.addLast(watt)
  			average = total / samples.size
  	
  			var endMillis = now().millis
			logInfo("Stromzaehler Waermepumpe Berechnung Watt", "Timediff since last update: " + diff.toString() + " ms, posting average: " + average.toString() + " W, calculated "+ watt.toString() + " W")
			logInfo("Stromzaehler Waermepumpe Berechnung Watt", "Calculation took " + (endMillis - startMillis).toString() + " ms")
			logInfo("Waermepumpe Berechnung Watt", "average: " + average)
			Heatpump_Stromzaehler_Watt.postUpdate(average)
			}
			else {
					logInfo("Waermepumpe Berechnung Watt", "Tick difference not what we expected (" + ticksBetween + "): " + tickDiff)
			}
  	}
	lastUpdate = now()
	lastCount = newCommand
end

Error:

2018-02-16 11:09:03.222 [INFO ] [l.script.Waermepumpe Berechnung Watt] - average: 22.164758034724787

2018-02-16 11:09:03.223 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Stromzaehler Waermepumpe Berechnung Watt': The name 'Heatpump_Stromzaehler_Watt' cannot be resolved to an item or type; line 51, column 4, length 26

item:

Number	HeatPump_Stromzaehler_Watt    "Wärmepumpe [%.3f kW]"	<energy>    //Calculated via rule

Typo (=Tippfehler)?

Your Item has an capital “Pump” and your rule uses lowercase “pump”…

andreas

This was it… Thanks! I looked into my rules-file and items-file many times, but i didn´t see the typo.

I am using this one to monitor the whole house and it works great for me.


There are separate reports for instant power of each line in kW.