Edit: do not use os.exit()

Code: Select all
-- Get Solivia inverter counters
-- Change weburl and inverter device name
return {
on = { timer = { "every 5 minutes"}},
execute = function(dz)
local inverter = dz.devices("Solivia invertername")
weburl='http://<IP_ADRES_OF_GATEWAY>/ID_<ID_OF_INVERTER>'
local f = assert(io.popen("curl -s " .. weburl, 'r'))
local s = assert(f:read('*a'))
f:close()
-- Exit script if inverter is offline or unavailable
if s:match('Operation failed') then return end
power=s:match('Actual Power.-<td width="190">(.-)</td>') -- in W
energy=s:match('Total Energy.-<td width="190">(.-)</td>') -- in kWh
-- Exit script if inverter returns no data available value
if power == "no data available" or energy == "no data available" then return end
-- print("Power= " .. power .. " W | Energy = " .. energy .. " kWh")
-- Solivia returns Total energy in kWh but Domoticz expects energy in Wh so multiply by 1000
inverter.updateElectricity(power,energy*1000)
end
}