S0 counter from power meter - how to get kwh?

Yesterday i forgot to remove the old rule, so i did only get my old values. The new rule wasn´t working. Today i removed the old rule but now i always get error messages about this rule:

2017-01-18 09:57:24.280 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Stromzaehler Waermepumpe Berechnung Watt': The name 'lastCount' cannot be resolved to an item or type.

Here is the top of my rule-file:

//
import org.openhab.core.library.types.*   
import org.openhab.core.types.Command
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*
import java.lang.Math
//
import java.util.concurrent.locks.ReentrantLock

// Variablen Waschmaschine + Trockner
val Number MODE_OFF = 0
val Number MODE_STANDBY = 1
val Number MODE_ACTIVE = 2
val Number MODE_FINISHED = 3
var java.util.concurrent.locks.ReentrantLock finishLock  = new java.util.concurrent.locks.ReentrantLock()

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

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
  /*
   * 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
  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

	  	// 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")
		Heatpump_Stromzaehler_Watt.postUpdate(average)
	} else {
		logInfo("Stromzaehler Waermepumpe Berechnung Watt", "Tick difference not what we expected: " + tickDiff)
	}
  }
  lastUpdate = now()
  lastCount = newCommand
end

Here is my items-file:

Number	HeatPump_Stromzaehler			"Wärmepumpe Stromzaehler [%d Impulse]"				<energy>		(gHeatpump_Strom,gMapDB)								{knx="12.001:4/3/1"}
Number	HeatPump_Stromzaehler_kwh		"Wärmepumpenzaehler [%.1f kWh]"						<energy>		(gMapDB)										//Calculated via rule
Number	HeatPump_Stromzaehler_Watt		"Wärmepumpe [%.3f kW]"								<energy>														//Calculated via rule
Number	HeatPump_Stromzaehler_kwh_today	"Wärmepumpenzaehler heute [%.1f kWh]"				<energy>		(gMapDB)										//Calculated via rule

Is there something missing???