Can't figure out "Electric (Instant+Counter)"

Moderator: leecollings

Post Reply
NiklasO
Posts: 67
Joined: Friday 16 August 2013 18:34
Target OS: -
Domoticz version:
Location: Stockholm, Sweden
Contact:

Can't figure out "Electric (Instant+Counter)"

Post by NiklasO »

I don't really know how to use the virtual Electric (Instant+Counter).

My counter counts 10 000 pulses per kWh. Getting the value from 1-wire/OWFS.

This is my script:

Code: Select all

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

-- 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=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

  -- Instant read, total counter value
   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

--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}

   --update user variables
   commandArray[2] = {['Variable:'..userVariableTimestamp] = tostring(os.time())}
   commandArray[3] = {['Variable:'..userVariableLastCount] = tostring(currval)}

   print("DummyEnergy: " .. f*actual .. " W, " .. currval/10000 .. " kWh, " .. "currval: " .. currval)
end

return commandArray
The print line in the end is for debugging..

I know this could be better written but i don't know Lua at all.

This is correct:
Domoticz_-_Google_Chrome_2016-02-11_20-27-21_37758323.png
Domoticz_-_Google_Chrome_2016-02-11_20-27-21_37758323.png (176.93 KiB) Viewed 871 times
Domoticz_-_Google_Chrome_2016-02-11_20-27-51_15162342.png
Domoticz_-_Google_Chrome_2016-02-11_20-27-51_15162342.png (239.29 KiB) Viewed 871 times
This is not (same device), wattage is correct:
Domoticz_-_Google_Chrome_2016-02-11_20-26-34_13845170.png
Domoticz_-_Google_Chrome_2016-02-11_20-26-34_13845170.png (28.75 KiB) Viewed 871 times
Why the big difference in kWh? I have never used 3412kWh with this new counter. 341,2 is more true.
I understand the big difference from 0 to where the counter is today but it does not change. The "Today:" part in the last picture will show the same high values tomorrow. I have removed and re-added the same device several times trying to figure out how it works.

Edit:
If I divide currval with 10 i should get Wh. When doing that it becomes the other way around. The last picture will show the right numbers but the usage per day becomes way lower then actual usage.... I can however add another device that the first information is correct and the second one incorrect and one the other way around.. seems lik a bad solution..
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest