This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

script P1 poort voor homelynk
#3
Hi,

Please use EN next time so everyone understands the question..

Code:
--P1 poort van slimme meter uitlezen

lastchar = '!'

require('serial')
port = serial.open('/dev/ttyUSB0', { -- Let op type van de slimme meter voor de onderstaande instellingen.
  baudrate = 9600,         --DSMR 2/3 = 9600        DSMR 4 = 115200
  databits = 7,                --DSMR 2/3 = 7            DSMR 4 = 8
  stopbits = 1,                --DSMR 2/3 = 1            DSMR 4 = 1
  parity = 'even',        --DSMR 2/3 = even        DSMR 4 = none
  duplex = 'full'
})

function readdata(port)
  local char, buf
  buf = {}
  while true do
    char = port:read(1)
    -- error (timeout) or newline, stop
    if char == nil or char == lastchar then
      --table.insert(buf, char)
      break
    -- ignore cr char
    elseif char ~= '\r' then
      table.insert(buf, char)
    end
  end
  return table.concat(buf)
end

data = readdata(port)
port:flush()
--log(data)
---------------------------------------------------------------

if data then

   -- Totaal verbruik tarief 1 uitlezen kWh
  tarief_1 = data:match([[1-0:1.8.1%((%d+.%d+)]])
  if nil ~= tarief_1 then
    tarief_1 = tonumber(tarief_1)
    --log("Tarief 1: " .. tarief_1 .. " kWh")
    grp.checkupdate('32/0/1', tarief_1)
  end

  -- Totaal verbruik tarief 2 uitlezen kWh
  tarief_2 = data:match([[1-0:1.8.2%((%d+.%d+)]])
  if nil ~= tarief_2 then
    tarief_2 = tonumber(tarief_2)
    --log("Tarief 2: " .. tarief_2 .. " kWh")
    grp.checkupdate('32/0/2', tarief_2)
  end

  -- Totaal verbruik tarief 1 + 2
  if nil ~= tarief_1 or nil ~= tarief_2 then
    tarief_totaal = tarief_1 + tarief_2
    --log("Totaal verbruik: " .. tarief_totaal .. " kWh")
    grp.checkupdate('32/0/0', tarief_totaal)
    grp.checkupdate('32/0/9', tarief_totaal * 1000)
  end

  -- Totale retourlevering tarief 1 uitlezen kWh
  retour_1 = data:match([[1-0:2.8.1%((%d+.%d+)]])
  if nil ~= retour_1 then
    retour_1 = tonumber(retour_1)
    --log("Retour 1: " .. retour_1 .. " kWh")
    grp.checkupdate('32/0/4', retour_1)
  end

  -- Totale retourlevering tarief 2 uitlezen kWh
  retour_2 = data:match([[1-0:2.8.2%((%d+.%d+)]])
  if nil ~= retour_2 then
    retour_2 = tonumber(retour_2)
    --log("Retour 2: " .. retour_2 .. " kWh")
    grp.checkupdate('32/0/5', retour_2)
  end

  -- Totale retourlevering tarief 1 + 2
  if nil ~= retour_1 or nil ~= retour_2 then
    retour_totaal = retour_1 + retour_2
    --log("Totaal retour: " .. retour_totaal .. " kWh")
    grp.checkupdate('32/0/3', retour_totaal)
    grp.checkupdate('32/0/10', retour_totaal * 1000)
  end

  -- Actuele tariefstand uitlezen T1/T2
  actueel_tarief = data:match([[0-0:96.14.0%(%d%d%d(%d)]])
  if nil ~= actueel_tarief then
    --log("Actueel tarief: T" .. actueel_tarief)
    grp.checkupdate('32/0/6', tonumber(actueel_tarief))
  end

  -- Actueel verbruik uitlezen kW
  actueel_verbruik = data:match([[1-0:1.7.0%((%d+.%d+)]])
  if nil ~= actueel_verbruik then
    actueel_verbruik = tonumber(actueel_verbruik)
    --log("Actueel verbruik: " .. actueel_verbruik .. " kW")
    grp.checkupdate('32/0/7', actueel_verbruik)
    grp.checkupdate('32/0/11', actueel_verbruik * 1000)
  end

  -- Actuele retourlevering uitlezen kW
  actueel_retour = data:match([[1-0:2.7.0%((%d+.%d+)]])
  if nil ~= actueel_retour then
    actueel_retour = tonumber(actueel_retour)
    --log("Actueel retour: " .. actueel_retour .. " kW")
    grp.checkupdate('32/0/8', actueel_retour)
    grp.checkupdate('32/0/12', actueel_retour * 1000)
  end
 
end
Reply


Messages In This Thread
script P1 poort voor homelynk - by cheist - 26.01.2025, 10:42
RE: script P1 poort voor homelynk - by Erwin van der Zwart - 26.01.2025, 21:27
RE: script P1 poort voor homelynk - by cheist - 02.02.2025, 08:32

Forum Jump: