Kod: Markera allt
commandArray = {}
-- Scriptname script_device_kwcount_ny.lua
-- Factor to calculate actual effect consumption
-- For 800 blinks per kW f=1.25, 1000 blinks per kW f=1, 10000 blinks per kW f=0.1
f=1
-- Dummy counter Idx value
kwCounterIndex = 131
local function readFile(sPath)
  local file = io.open(sPath, "r")
  if file then
    local tLine = file:read()
    file.close()
    return tLine
  end
  return nil
end
local function writeFile(sPath, sLine)
  local file = io.open(sPath, "w")
  if file then
    io.output(file);
    io.write(sLine)
    io.close()
  end
end
if (devicechanged['kW1']) then
   -- Läs ut värden och countervärde
   kW1String = otherdevices_svalues['kW1']
   new_counter_kW1 = tonumber(string.sub(kW1String,string.find(kW1String,';')+1,string.find(kW1String,';',-3)-1))
   newValue=f*10*tonumber(string.sub(kW1String,1,string.find(kW1String,';',1,true)-1))
 
   -- Läs senaste värdet på counter från fil
   local aLine=readFile("/home/pi/kW1-last.txt")
      if aLine then
         old_from_file=tostring(aLine)
         old_counter_kW1 = tonumber(string.sub(old_from_file,string.find(old_from_file,';')+1,string.find(old_from_file,';',-3)-1))
      end
   -- Läs in totalräknare från fil
   lastValue = 0
   local aLine=readFile("/home/pi/effect-counter.txt")
      if aLine then
         lastValue=tonumber(aLine)
      end
   
   -- Om räknare stämmer med +1 från förra skriv till filer och avsluta
   if (new_counter_kW1-1 == old_counter_kW1) then
      lastValue=lastValue+newValue
      writeFile("/home/pi/effect-counter.txt",tostring(lastValue))
      writeFile("/home/pi/kW1-last.txt", tostring(kW1String))
      
   -- Om annat uppdatera fel med +1, uppdatera senaste lästa värde och använd senaste avläsning till totalen.
   else
      errorValue = 0
      local aLine=readFile("/home/pi/error_counter.txt")
      if aLine then
         errorValue=tonumber(aLine)
      end
      errorValue=errorValue+1
      writeFile("/home/pi/error_counter.txt",tostring(errorValue))
      lastValue=lastValue+newValue+newValue
      writeFile("/home/pi/effect-counter.txt",tostring(lastValue))
      writeFile("/home/pi/kW1-last.txt", tostring(kW1String))
   end
   -- Banka ihop en sträng att uppdater med
   effectString=tostring(kwCounterIndex) .. "|0|" .. tostring(newValue*(60/55)*60) .. ";" .. tostring(lastValue)
   -- Uppdatera dummy
   commandArray = {}
   commandArray['UpdateDevice']=effectString
end
return commandArray
 Försökte läsa mig på din sida NiclasF men fick inte ihop ett LUA script av detta som jag kan köra.
 Försökte läsa mig på din sida NiclasF men fick inte ihop ett LUA script av detta som jag kan köra.Kod: Markera allt
commandArray = {}
-- Scriptname script_device_kwcount_201405.lua
-- Factor to calculate actual effect consumption
-- For 800 blinks per kW f=1.25, 1000 blinks per kW f=1, 10000 blinks per kW f=0.1
f=1
-- Dummy counter Idx value
kwCounterIndex = 131
-- File functions used to keep track of updated total value
-- The file effect-counter is saved to /
local function readFile(sPath)
  local file = io.open(sPath, "r")
  if file then
    local tLine = file:read()
    file.close()
    return tLine
  end
  return nil
end
local function writeFile(sPath, sLine)
  local file = io.open(sPath, "w")
  if file then
    io.output(file);
    io.write(sLine)
    io.close()
  end
end
-- My temperature device is kW1 and kW2. Where kW1 is the primary and kW2 is secondary
-- I do not use the secondary one (kW2) in this script.
if (devicechanged['kW1']) then
   -- Läs ut värden och countervärde
   kW1String = otherdevices_svalues['kW1']
   kW2String = otherdevices_svalues['kW2']
   new_counter_kW2 = tonumber(string.sub(kW2String,string.find(kW2String,';')+1,string.find(kW2String,';',-3)-1))
   new_counter_kW1 = tonumber(string.sub(kW1String,string.find(kW1String,';')+1,string.find(kW1String,';',-3)-1))
   newValue_kW1=f*10*tonumber(string.sub(kW1String,1,string.find(kW1String,';',1,true)-1))
   newValue_kW2=f*10*tonumber(string.sub(kW2String,1,string.find(kW2String,';',1,true)-1))
 
   -- Läs senaste värdet på counter från fil
   local aLine=readFile("/home/pi/kW1-last.txt")
      if aLine then
         old_from_file=tostring(aLine)
         old_counter_kW1 = tonumber(string.sub(old_from_file,string.find(old_from_file,';')+1,string.find(old_from_file,';',-3)-1))
      end
   -- Läs in totalräknare från fil
   lastValue = 0
   local aLine=readFile("/home/pi/effect-counter.txt")
      if aLine then
         lastValue=tonumber(aLine)
      end
   
   -- Om räknare stämmer med +1 från förra skriv till filer och avsluta eller om räknare är 0
   if (new_counter_kW1-1 == old_counter_kW1 or new_counter_kW1 == 0) then
      lastValue=lastValue+newValue_kW1
      writeFile("/home/pi/effect-counter.txt",tostring(lastValue))
      writeFile("/home/pi/kW1-last.txt", tostring(kW1String))
	  
   elseif (new_counter_kW2-1 == old_counter_kW1) then
      kW2_errorValue = 0
      local aLine=readFile("/home/pi/kW2-counter.txt")
      if aLine then
         kW2_errorValue=tonumber(aLine)
      end
	  kW2_errorValue=kW2_errorValue+1
	  lastValue=lastValue+newValue_kW1+newValue_kW2
      writeFile("/home/pi/effect-counter.txt",tostring(lastValue))
      writeFile("/home/pi/test.txt", "kW1 " .. tostring(new_counter_kW1) .. "\n" .. "kW2 " .. tostring(new_counter_kW2) .. "\n" .. "Old counter from file " .. tostring(old_counter_kW1))
	  writeFile("/home/pi/kW2-counter.txt",tostring(kW2_errorValue))
	  writeFile("/home/pi/kW1-last.txt", tostring(kW1String))
	  
   -- Om annat uppdatera fel med +1, uppdatera senaste lästa värde och använd senaste avläsning till totalen.
   else
      errorValue = 0
      local aLine=readFile("/home/pi/error-counter.txt")
      if aLine then
         errorValue=tonumber(aLine)
      end
      errorValue=errorValue+1
      writeFile("/home/pi/error-counter.txt",tostring(errorValue))
      lastValue=lastValue+newValue_kW1+newValue_kW1
      writeFile("/home/pi/effect-counter.txt",tostring(lastValue))
      writeFile("/home/pi/kW1-last.txt", tostring(kW1String))
   end
   -- Banka ihop en sträng att uppdater med
   effectString=tostring(kwCounterIndex) .. "|0|" .. tostring(newValue_kW1*(60/58)*60) .. ";" .. tostring(lastValue)
   -- now use this counter for our virtual effect sensor
   commandArray = {}
   commandArray['UpdateDevice']=effectString
end
return commandArray
Kod: Markera allt
-- Scriptname script_device_wpc_1.lua
sensorName = “WPC1”
-- Dummy counter Idx value
kwCounterIndex = 131
-- Factor to calculate actual energy consumption
-- 800 blinks per kWh => 1000/800 => f=1.25
-- 1000 blinks per kWh => 1000/1000 => f=1
-- 10000 blinks per kWh => 1000/10000 => f=0.1
f = 1
-- File paths
baseDirPath = "/tmp/"
humFilePath = baseDirPath .. sensorName .. "-old-humidity.txt"
wrapFilePath = baseDirPath .. sensorName .. "-wrap-counter.txt"
energyFilePath = baseDirPath .. sensorName .. "-old-energy-wh.txt"
-- END OF CONFIGURATION PARAMETERS. CONFIGURATIONS ABOVE THIS LINE --
t1 = os.time()
s = otherdevices_lastupdate[sensorName]
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
deltaT = os.difftime (t1, t2)
-- File function definitions
local function readFile(sPath)
  local file = io.open(sPath, "r")
  if file then
    local tLine = file:read()
    file.close()
    return tLine
  end
  return nil
end
local function writeFile(sPath, sLine)
  local file = io.open(sPath, "w")
  if file then
    io.output(file)
    io.write(sLine)
    io.close()
  end
end
-- Wireless Pulse Counter device sensorName is WPC.
if (devicechanged[sensorName]) then
   -- Read temperature and humidity value
   WPCString = otherdevices_svalues[sensorName]
   humidity = tonumber(string.sub(WPCString,string.find(WPCString,';')+1,string.find(WPCString,';',-3)-1))
   temperature = tonumber(string.sub(WPCString,1,string.find(WPCString,';',1,true)-1))
   if (temperature < 0) then
      Counts = humidity*4096 - 10*temperature + 2048
   else
      Counts = humidity*4096 + 10*temperature
   end
   -- Read total amount of wrapp-arounds into "wrapCounter"
   -- wrapCounter = 0
   local aLine = readFile(wrapFilePath)
   if aLine then
	wrapCounter = tonumber(aLine)
   end
   if (humidity==0) then
      -- Read the latest value into "oldHumidity"
      oldHumidity = 0
      local aLine = readFile(humFilePath)
      if aLine then
	oldHumidity = tonumber(aLine)
      end
      if (oldHumidity==100) then
	wrapCounter = wrapCounter + 1
	writeFile(wrapFilePath, tostring(wrapCounter))
      end
   end
	  
   writeFile(humFilePath, tostring(humidity))
   
   -- Read total previous energy consumption into "oldTotalEnergyWh"
   oldTotalEnergyWh = 0
   local aLine = readFile(energyFilePath)
   if aLine then
	oldTotalEnergyWh = tonumber(aLine)
   end
	  
   totalEnergyWh = f*(Counts + wrapCounter*413696)
   deltaEnergy = totalEnergyWh - oldTotalEnergyWh
   writeFile(energyFilePath, tostring(energyWh))
   -- Concatinate a string to present ...
   -- The Current Power usage in kW and the total energy consumption in kWh
   outputString = tostring(kwCounterIndex) .. "|0|" .. tostring(deltaEnergy*60*(60/deltaT)/1000) .. ";" .. tostring(totalEnergyWh/1000)
   -- now use this counter for our virtual effect sensor
   commandArray = {}
   commandArray['UpdateDevice'] = outputString
end
return commandArray
Kod: Markera allt
-- Scriptname script_device_wpc_1.lua
sensorName = “El2”
-- Dummy counter Idx value
kwCounterIndex = 37
-- Factor to calculate actual energy consumption
-- 800 blinks per kWh => 1000/800 => f=1.25
-- 1000 blinks per kWh => 1000/1000 => f=1
-- 10000 blinks per kWh => 1000/10000 => f=0.1
f = 1
-- File paths
baseDirPath = "/tmp/"
humFilePath = baseDirPath .. sensorName .. "-old-humidity.txt"
wrapFilePath = baseDirPath .. sensorName .. "-wrap-counter.txt"
energyFilePath = baseDirPath .. sensorName .. "-old-energy-wh.txt"
-- END OF CONFIGURATION PARAMETERS. CONFIGURATIONS ABOVE THIS LINE --
t1 = os.time()
s = otherdevices_lastupdate[sensorName]
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
deltaT = os.difftime (t1, t2)
-- File function definitions
local function readFile(sPath)
  local file = io.open(sPath, "r")
  if file then
    local tLine = file:read()
    file.close()
    return tLine
  end
  return nil
end
local function writeFile(sPath, sLine)
  local file = io.open(sPath, "w")
  if file then
    io.output(file)
    io.write(sLine)
    io.close()
  end
end
-- Wireless Pulse Counter device sensorName is WPC.
if (devicechanged[sensorName]) then
   -- Read temperature and humidity value
   WPCString = otherdevices_svalues[sensorName]
   humidity = tonumber(string.sub(WPCString,string.find(WPCString,';')+1,string.find(WPCString,';',-3)-1))
   temperature = tonumber(string.sub(WPCString,1,string.find(WPCString,';',1,true)-1))
   if (temperature < 0) then
      Counts = humidity*4096 - 10*temperature + 2048
   else
      Counts = humidity*4096 + 10*temperature
   end
   -- Read total amount of wrapp-arounds into "wrapCounter"
   -- wrapCounter = 0
   local aLine = readFile(wrapFilePath)
   if aLine then
   wrapCounter = tonumber(aLine)
   end
   if (humidity==0) then
      -- Read the latest value into "oldHumidity"
      oldHumidity = 0
      local aLine = readFile(humFilePath)
      if aLine then
   oldHumidity = tonumber(aLine)
      end
      if (oldHumidity==100) then
   wrapCounter = wrapCounter + 1
   writeFile(wrapFilePath, tostring(wrapCounter))
      end
   end
     
   writeFile(humFilePath, tostring(humidity))
   
   -- Read total previous energy consumption into "oldTotalEnergyWh"
   oldTotalEnergyWh = 0
   local aLine = readFile(energyFilePath)
   if aLine then
   oldTotalEnergyWh = tonumber(aLine)
   end
     
   totalEnergyWh = f*(Counts + wrapCounter*413696)
   deltaEnergy = totalEnergyWh - oldTotalEnergyWh
   writeFile(energyFilePath, tostring(energyWh))
   -- Concatinate a string to present ...
   -- The Current Power usage in kW and the total energy consumption in kWh
   outputString = tostring(kwCounterIndex) .. "|0|" .. tostring(deltaEnergy*60*(60/deltaT)/1000) .. ";" .. tostring(totalEnergyWh/1000)
   -- now use this counter for our virtual effect sensor
   commandArray = {}
   commandArray['UpdateDevice'] = outputString
end
return commandArrayKod: Markera allt
-- Scriptname script_device_wpc_1.lua
print("Enter Scriptname script_device_wpc_1.lua")
sensorName = "kW1"
-- Dummy counter Idx value
kwCounterIndex = 59
-- Factor to calculate actual energy consumption
-- 800 blinks per kWh => 1000/800 => f=1.25
-- 1000 blinks per kWh => 1000/1000 => f=1
-- 10000 blinks per kWh => 1000/10000 => f=0.1
f = 1
-- File paths
baseDirPath = "/tmp/"
humFilePath = baseDirPath .. sensorName .. "-old-humidity.txt"
wrapFilePath = baseDirPath .. sensorName .. "-wrap-counter.txt"
energyFilePath = baseDirPath .. sensorName .. "-old-energy-wh.txt"
lastUpdateFilePath = baseDirPath .. sensorName .. "-last-update.txt"
logFilePath = baseDirPath .. sensorName .. "-log.txt"
-- END OF CONFIGURATION PARAMETERS. CONFIGURATIONS ABOVE THIS LINE --
commandArray = {}
-- File function definitions
local function readFile(sPath)
  print ("Läser fil " .. sPath)
  local file = io.open(sPath, "r")
  if file then
    local tLine = file:read()
    io.close(file)
    return tLine
  end
  return nil
end
local function writeFile(sPath, sLine)
  print ("Skriver fil " .. sPath .. " med data: " .. sLine)
  local file = io.open(sPath, "w")
  if file then
    io.output(file)
    io.write(sLine)
    io.close(file)
  end
end
local function appendFile(sPath, sLine)
  print ("Skriver fil " .. sPath .. " med data: " .. sLine)
  local file = io.open(sPath, "a")
  if file then
    io.output(file)
    io.write(sLine)
    io.close(file)
  end
end
-- Wireless Pulse Counter device sensorName is WPC.
if (devicechanged[sensorName]) then
   
	print("Sensor " .. sensorName .. " Change")
   
	t1 = os.time()
	-- Read total previous time when get sensor value
	oldTime = t1 - 60 -- init if this is the first time
	local aLine = readFile(lastUpdateFilePath)
	if aLine then
		oldTime = tonumber(aLine)
	end
	-- write new time
	writeFile(lastUpdateFilePath, t1)
	
	deltaT = os.difftime (t1, oldTime)
	if(deltaT == 0) then
		-- We don't wont div by zero
		deltaT = t1 - 60
	end
	print("deltaT: " .. deltaT)
	print("osTime: " .. t1)
	print("lastUpdateTime: " .. oldTime)
   
   -- Read temperature and humidity value
   WPCString = otherdevices_svalues[sensorName]
   humidity = tonumber(string.sub(WPCString,string.find(WPCString,';')+1,string.find(WPCString,';',-3)-1))
   temperature = tonumber(string.sub(WPCString,1,string.find(WPCString,';',1,true)-1))
   print("WPCString: " .. WPCString)
   print("humidity: " .. humidity)
   print("temperature: " .. temperature)
   
   if (temperature < 0) then
      Counts = humidity*4096 - 10*temperature + 2048
   else
      Counts = humidity*4096 + 10*temperature
   end
	-- Read total amount of wrap-arounds into "wrapCounter"
	wrapCounter = 1
	local aLine = readFile(wrapFilePath)
	if aLine then
		wrapCounter = tonumber(aLine)
	end
	local aLine = readFile(humFilePath)
	if aLine then
		oldHumidity = tonumber(aLine)
	else
		oldHumidity = 0
	end
	-- Check if start over in humidity counter
	if (humidity < oldHumidity) then
		wrapCounter = wrapCounter + 1
		writeFile(wrapFilePath, tostring(wrapCounter))
	end
	writeFile(humFilePath, tostring(humidity))
	-- Read total previous energy consumption into "oldTotalEnergyWh"
	oldTotalEnergyWh = 0 -- init if this is the first time
	local aLine = readFile(energyFilePath)
	if aLine then
		oldTotalEnergyWh = tonumber(aLine)
	end
	totalEnergyWh = f*(Counts + wrapCounter*413696)
	deltaEnergy = totalEnergyWh - oldTotalEnergyWh
	print("deltaEnergy: " .. deltaEnergy)
	
	writeFile(energyFilePath, tostring(totalEnergyWh))
	-- Concatenate a string to present ...
	-- The Current Power usage in kW and the total energy consumption in kWh
	outputString = tostring(kwCounterIndex) .. "|0|" .. tostring(deltaEnergy*60*(60/deltaT)/1000) .. ";" .. tostring(totalEnergyWh/1000)
   
	print("--> wpc: " .. outputString)
   
	-- now use this counter for our virtual effect sensor
	commandArray['UpdateDevice'] = outputString
	logData = tostring(os.date()) .. ":WPCString:" .. WPCString .. ":wrapCounter:" .. wrapCounter .. ":oldTotalEnergyWh:" .. oldTotalEnergyWh .. ":totalEnergyWh:" .. totalEnergyWh .. "\n"
	appendFile(logFilePath, logData)
   
	print("No errors :)")
end
return commandArray
The X10-protocol need to be enabled to make the WPC from foogadgets to show up as an RFXmeter.G-man skrev: ...
Edit: http://foogadgets.blogspot.se/2014/05/t ... unter.html native support as an RFXmeter in domotics... Den kom ju upp som tempmätare och fuktmätare nu iallafall
This issue was resolved by enabling the X10-protocol so that the WPC shows up as an RFXmeter.redina skrev:Har hållit på att fixa till det skriptet för PWS. Nu kompilerar det utan fel (tror jag). Detta skript innehåller en massa print och en loggning till fil. Detta kan tas bort om man vill. Har även ändrat lite i hur det funkar när hum går runt till 0 igen, (lite säkrare om man missar en sändning vi fel tidpunkt).
Fråga hur fungerar värdena i redundanssändningen, förstår inte riktigt?
...

Kod: Markera allt
--Domoticz Script to get medium actual energy between energy counter readings and puts it on a dummy device
--First create a dummy energy meter and two user variables as numbers.
--Then enter the details below
--Name of the real energy counter
energyCounter = 'Elräknare'
--ID of the created dummy energy meter with the new actual value
dummyEnergyMeterid = 319
--The names of two user variables to keep track of previous value due to wrong values from dummy in otherdevices_lastupdate and otherdevices_svalues
userVariableTimestamp = 'LastEnergyTimestamp'
userVariableLastCount = 'LastEnergyCount'
commandArray = {}
if devicechanged[energyCounter] then
	--calculate new actual value
	actual = ((tonumber(otherdevices_svalues[energyCounter]) - tonumber(uservariables[userVariableLastCount])))/((os.time()-uservariables[userVariableTimestamp])/3600)
	
	--update dummy energy meter
	commandArray[1] = {['UpdateDevice'] = dummyEnergyMeterid .. "|0|" .. actual .. ";" .. otherdevices_svalues[energyCounter]}
	
	--update user variables
	commandArray[2] = {['Variable:'..userVariableTimestamp] = tostring(os.time())}
	commandArray[3] = {['Variable:'..userVariableLastCount] = otherdevices_svalues[energyCounter]}
	
	print("DummyEnergy: " .. actual .. " W, " .. otherdevices_svalues[energyCounter] .. " kWh")
end
return commandArray Den uppdaterar så snart elmätaren får en uppdatering från 1-wirenätet och då läser den värdet direkt från räknaren.
 Den uppdaterar så snart elmätaren får en uppdatering från 1-wirenätet och då läser den värdet direkt från räknaren.
Kod: Markera allt
--Domoticz Script to get medium actual energy between energy counter readings and puts it on a dummy device
--First create a dummy energy meter and two user variables as numbers.
--Then enter the details below
f=0.1
local function readFile(sPath)
  local file = io.open(sPath, "r")
  if file then
    local tLine = file:read()
    file.close()
    return tLine
  end
  return nil
end
  -- Läs in totalräknare från fil
   currval = 0
   local aLine=readFile("/mnt/1wire/uncached/1D.B4090D000000/counter.A")
      if aLine then
         currval=tonumber(aLine)
      end
--Name of the real energy counter
energyCounter = 'Elmätare'
--ID of the created dummy energy meter with the new actual value
dummyEnergyMeterid = 321
dummyEnergyMeterid2 = 320
--The names of two user variables to keep track of previous value due to wrong values from dummy in otherdevices_lastupdate and otherdevices_svalues
userVariableTimestamp = 'LastEnergyTimestamp'
userVariableLastCount = 'LastEnergyCount'
commandArray = {}
if devicechanged[energyCounter] then
   --calculate new actual value
   actual = ((tonumber(currval) - tonumber(uservariables[userVariableLastCount])))/((os.time()-uservariables[userVariableTimestamp])/3600)
   --update dummy energy meters
   commandArray[1] = {['UpdateDevice'] = dummyEnergyMeterid .. "|0|" .. f*actual .. ";" .. currval/10}
   commandArray[2] = {['UpdateDevice'] = dummyEnergyMeterid2 .. "|0|" .. f*actual}
   --update user variables
   commandArray[3] = {['Variable:'..userVariableTimestamp] = tostring(os.time())}
   commandArray[4] = {['Variable:'..userVariableLastCount] = tostring(currval)}
   print("DummyEnergy: " .. f*actual .. " W, " .. currval/10 .. " Wh, " .. "currval: " .. currval)
end
return commandArray

Kod: Markera allt
--Domoticz Script to get medium actual energy between energy counter readings and puts it on a dummy device etc
f=0.1
--Name of the real energy counter
energyCounter = 'Elmätare'
--ID of the created dummy energy meter with the new actual value
dummyEnergyMeterid = 344
p1smart = 342
dummyEnergyWatt = 343
--The names of two user variables to keep track of previous value due to wrong values from dummy in otherdevices_lastupdate and otherdevices_svalues
userVariableTimestamp = 'LastEnergyTimestamp'
userVariableLastCount = 'LastEnergyCount'
commandArray = {}
if devicechanged[energyCounter] then
current_counter_value=tonumber(otherdevices_svalues[energyCounter])
time_diff = ((tonumber(current_counter_value) - tonumber(uservariables[userVariableLastCount])))/((os.time()-uservariables[userVariableTimestamp])/3600)
counts_since_last_read = tonumber(current_counter_value)-tonumber(uservariables[userVariableLastCount])
use_now_watt = f*time_diff
use_now_watt_rounded = math.floor(use_now_watt+0.5)
total_wh_used=current_counter_value*f
total_wh_used_rounded= math.floor(total_wh_used+0.5)
wh_used_since_last_read=counts_since_last_read*f
wh_used_since_last_read_rounded=math.floor(wh_used_since_last_read+0.5)
total_kwh_used=total_wh_used/1000
total_kwh_used_rounded=math.floor(total_kwh_used+0.5)
kwh_used_since_last_read=wh_used_since_last_read/1000
kwh_used_since_last_read_rounded=math.floor(kwh_used_since_last_read+0.5)
initial=current_counter_value-5537396
print("current_counter_value: " .. current_counter_value)
print("counts_since_last_read: " .. counts_since_last_read)
print("use_now_watt: " .. use_now_watt .. " (" .. use_now_watt_rounded .. ") W")
print("total_wh_used: " .. total_wh_used .. " (" .. total_wh_used_rounded .. ") Wh")
print("wh_used_since_last_read: " .. wh_used_since_last_read .. " (" .. wh_used_since_last_read_rounded .. ") Wh")
print("Used kWh since start: " .. total_kwh_used .. " (" .. total_kwh_used_rounded .. ") kWh")
print("Used kWh since last read: " .. kwh_used_since_last_read .. " (" .. kwh_used_since_last_read_rounded .. ") kWh")
   --calculate new actual value
   --update dummy energy meters
   commandArray[1] = {['UpdateDevice'] = dummyEnergyMeterid .. "|0|" .. use_now_watt .. ";" .. initial}
   commandArray[2] = {['UpdateDevice'] = p1smart .. "|0|" .. current_counter_value .. ";0;0;0;" .. use_now_watt .. ";0"}
   commandArray[3] = {['UpdateDevice'] = dummyEnergyWatt .. "|0|" .. use_now_watt}
   --update user variables
   commandArray[4] = {['Variable:'..userVariableTimestamp] = tostring(os.time())}
   commandArray[5] = {['Variable:'..userVariableLastCount] = tostring(current_counter_value)}
end
return commandArray