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.

Photovoltaik Visu
#1
Hi,

I want to visualize my PV system. I use a Schneider IEM3155 for the measurement. Unfortunately I only get the total value in Kwh, but I would like to have the daily value. Here is my script and the error:

---------------- Objektadressen ---------------------
-- Hier die Adressen der jeweiligen Objekten einfügen
-- Wo der PV-Energiewert gespeichert wird (Objekt)
adr_PVEnergie = "1/2/3"

-- Wo der PV-Tageswert gespeichert wird (zur Visu)
adr_PVTageswert = "1/2/4"

-- Wann der Tageswert zurückgesetzt werden soll
hour_reset = 23
min_reset = 59

---- Logik ----
now = os.date(t)

if (now.hour == hour_reset and now.min == min_reset) then

    PVEnergie = grp.getvalue(adr_PVEnergie)

  storage.set('vortageswert', PVEnergie)

    grp.write(adr_PVTageswert, 0)

else

    PVEnergie = grp.getvalue(adr_PVEnergie)

  vortageswert = storage.get('vortageswert')

  PVTageswert = PVEnergie - vortageswert

    grp.write(adr_PVTageswert, PVTageswert)
   
end


Error:

Resident script:30: attempt to perform arithmetic on global 'vortageswert' (a nil value)

stack traceback:
Reply
#2
Hi,

The error is probably because the storage is never saved yet due to your condition, then you fetch 'nil' and you cant perform a calculation. 

Change your code like this
Code:
else
  PVEnergie = grp.getvalue(adr_PVEnergie)
  vortageswert = storage.get('vortageswert')
  if vortageswert == nil then
    storage.set('vortageswert', 0)
    vortageswert = 0
  end
  PVTageswert = PVEnergie - vortageswert
Easiest way to do this is to use the partial energy registers from the iEM3155, make sure to disable the "com protection" (enabled by default) on the meter by using the display and create a virtual object and attach a scheduler to it with a event at 00:00 and attach this script to the object and adjust connection details and slave id as needed
Code:
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485', 19200, 'E', 8, 1, 'H')
mb:connect()
mb:setslave(1)
mb:writeregisters(5249, 2020, '')
mb:close()
The partial energy registers are now receiving a reset command by the command interface every day at 0:00

Add a trend to your partial registers and you are good to go..

BR,

Erwin
Reply
#3
(10.05.2020, 17:02)Erwin van der Zwart Wrote: Hi,

The error is probably because the storage is never saved yet due to your condition, then you fetch 'nil' and you cant perform a calculation. 

Change your code like this
Code:
else
  PVEnergie = grp.getvalue(adr_PVEnergie)
  vortageswert = storage.get('vortageswert')
  if vortageswert == nil then
    storage.set('vortageswert', 0)
    vortageswert = 0
  end
  PVTageswert = PVEnergie - vortageswert
Easiest way to do this is to use the partial energy registers from the iEM3155, make sure to disable the "com protection" (enabled by default) on the meter by using the display and create a virtual object and attach a scheduler to it with a event at 00:00 and attach this script to the object and adjust connection details and slave id as needed
Code:
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485', 19200, 'E', 8, 1, 'H')
mb:connect()
mb:setslave(1)
mb:writeregisters(5249, 2020, '')
mb:close()
The partial energy registers are now receiving a reset command by the command interface every day at 0:00

Add a trend to your partial registers and you are good to go..

BR,

Erwin

thanks for your help, the first script does not work ... the second only works, unfortunately I do not have the Total Active Energy Export modbus register ... and I do not know how to write it into the Modbus register
Reply


Forum Jump: