LogicMachine Forum
kWh meter, a ZIV E0090 P1 port - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: kWh meter, a ZIV E0090 P1 port (/showthread.php?tid=6411)



kWh meter, a ZIV E0090 P1 port - cheist - 01.05.2026

I received a new kWh meter, a ZIV E0090. I think it’s DSMR 5.0.

I’m currently using this script, which works, but can it be extended with real-time current values and such?

I’d actually like to use everything that can be read out in graphs.




-- P1 poort uitlezen (ultra-licht)
local LAST = '!'
local serial = require('serial')
local port = serial.open('/dev/ttyUSB0', {
  baudrate = 115200,  -- DSMR2/3: 9600, DSMR4: 115200
  databits = 8,    -- DSMR2/3: 7,    DSMR4: 8
  stopbits = 1,
  parity  = 'none',-- DSMR4: 'none'
  duplex  = 'full'
})

local function read_frame(p)
  local buf = {}
  while true do
    local c = p:read(1)
    if c == nil or c == LAST then break
    elseif c ~= '\r' then buf[#buf+1] = c end
  end
  return table.concat(buf)
end

local data = read_frame(port)
port:flush()
if not data then return end

-- Helper: parse getal met punt, return number of nil
local function num(pat)
  local s = data:match(pat)
  return s and tonumber(s) or nil
end

-- Verbruik kWh (T1,T2) en totaal
local t1 = num([[1%-0:1%.8%.1%((%d+%.%d+)]])
local t2 = num([[1%-0:1%.8%.2%((%d+%.%d+)]])
if t1 then grp.update('14/0/1', t1) end
if t2 then grp.update('14/0/2', t2) end
local v_tot = (t1 or 0) + (t2 or 0)
if t1 or t2 then grp.update('14/0/0', v_tot) end

-- Verbruik € (alleen als prijs aanwezig)
do
  local prijs = grp.getvalue('14/0/11')
  if type(prijs) == 'number' and (t1 or t2) then
    grp.update('14/0/13', v_tot * prijs)
  end
end

-- Retour kWh (T1,T2) en totaal
local r1 = num([[1%-0:2%.8%.1%((%d+%.%d+)]])
local r2 = num([[1%-0:2%.8%.2%((%d+%.%d+)]])
if r1 then grp.update('14/0/4', r1) end
if r2 then grp.update('14/0/5', r2) end
local r_tot = (r1 or 0) + (r2 or 0)
if r1 or r2 then grp.update('14/0/3', r_tot) end

-- Retour € (alleen als prijs aanwezig)
do
  local prijs = grp.getvalue('14/0/12')
  if type(prijs) == 'number' and (r1 or r2) then
    grp.update('14/0/14', r_tot * prijs)
  end
end

-- Actueel tarief (T1/T2 laatste cijfer)
do
  local t = data:match([[0%-0:96%.14%.0%(%d%d%d(%d)]])
  if t then grp.update('14/0/10', t) end
end

-- Actueel verbruik kW/W en €
do
  local p_kw = num([[1%-0:1%.7%.0%((%d+%.%d+)]])
  if p_kw then
    grp.update('14/0/6', p_kw)
    grp.update('14/0/7', p_kw * 1000)
    local prijs = grp.getvalue('14/0/11')
    if type(prijs) == 'number' then grp.update('14/0/15', p_kw * prijs) end
  end
end

-- Actueel retour kW/W
do
  local pr_kw = num([[1%-0:2%.7%.0%((%d+%.%d+)]])
  if pr_kw then
    grp.update('14/0/8', pr_kw)
    grp.update('14/0/9', pr_kw * 1000)
  end
end

-- Gas m³ en €
do
  local gas = num([[0%-1:24%.2%.1%(.+%)%((%d+%.%d+)]])
  if gas then
    grp.update('14/1/0', gas)
    local prijs = grp.getvalue('14/1/1')
    if type(prijs) == 'number' then grp.update('14/1/2', gas * prijs) end
  end
end