I can share my lua script "as is" and it has some debugging prints.
Thanks louisl for updating the code in GIT for the new server.
Code: Select all
-- Script to pull GoodWe power generation data into Domoticz
-- Based on script from M Grimwade 2015
-- Modified by Wanegedoe
script_version = 6
--------------------------------------------------------------------------
-- stationID of GoodWe and the sensors Idx in domoticz
stationID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
idx_vpv1 = 143
idx_vpv2 = 144
idx_ipv1 = 145
idx_ipv2 = 146
idx_ppv1 = 155
idx_ppv2 = 156
idx_epvac = 149
idx_vac = 152
--------------------------------------------------------------------------
-- Function to update a Domoticz sensor object
function update_device(id, value1, value2)
if value2 == nil then
commandArray[id] = {['UpdateDevice'] = id .. "|0|" .. value1}
else
commandArray[id] = {['UpdateDevice'] = id .. "|0|" .. value1 .. ";" .. value2}
end
return
end
-- script starts here
print("goodwe script version " .. script_version)
-- Load the JSON Lua module
-- Load module to print tables from: https://github.com/kikito/inspect.lua
JSON = (loadfile "/src/domoticz/scripts/lua/JSON.lua")()
-- inspect = (loadfile "/src/domoticz/scripts/lua/inspect.lua")()
-- Command array to populate with Domoticz instructions
commandArray = {}
-- Perform an HTTP request to get the raw string from the REST endpoint
local config=assert(io.popen('curl https://eu.goodwe-power.com/Mobile/GetMyDeviceListById_V3?stationId=' .. stationID))
local json_string = config:read('*all')
config:close()
--print(json_string)
-- Decode the JSON formatted string to a Lua table
local t = JSON:decode(json_string)
local t_goodwe = t.result[1]
--print(inspect(t_goodwe))
-- get the data from the tables
update_device(idx_vpv1, t_goodwe.vpv1)
update_device(idx_vpv2, t_goodwe.vpv2)
update_device(idx_ipv1, t_goodwe.ipv1)
update_device(idx_ipv2, t_goodwe.ipv2)
update_device(idx_vac, t_goodwe.vac1)
update_device(idx_epvac, t_goodwe.power, tonumber(t_goodwe.etotal) *1000)
local p_pv1 = tonumber(t_goodwe.vpv1) * tonumber(t_goodwe.ipv1)
local p_pv2 = tonumber(t_goodwe.vpv2) * tonumber(t_goodwe.ipv2)
update_device(idx_ppv1, p_pv1,0)
update_device(idx_ppv2, p_pv2,0)
return commandArray