Does anyone know why this SAJ solar script (which I found somewhere on this forum) runs several times in a row:
2021-01-12 11:57:30.636 Status: EventSystem: Script event triggered: SAJSolar
2021-01-12 11:57:30.777 Status: EventSystem: Script event triggered: SAJSolar
2021-01-12 11:57:30.847 Status: EventSystem: Script event triggered: SAJSolar
2021-01-12 11:57:30.925 Status: EventSystem: Script event triggered: SAJSolar
2021-01-12 11:57:30.982 Status: EventSystem: Script event triggered: SAJSolar
2021-01-12 11:57:31.038 Status: EventSystem: Script event triggered: SAJSolar
2021-01-12 11:57:31.168 Status: EventSystem: Script event triggered: SAJSolar
- Spoiler: show
- commandArray = {}
local now = 0
local bNowUpdated = false
local temp = 0
local bTempUpdated = false
local today = 0
local bTodayUpdated = false
local total = 0
local bTotalUpdated = false
local ip = '192.168.0.xxx' --customize this to your invertor IP
local i = 1
on = {
timer = {'every minute'}
}
function UpdateDevice(device, data)
idx = otherdevices_idx[device]
if (idx == nil) then
print('** Unknown device '..device)
else
commandArray = {['UpdateDevice'] = idx..'|0|'..data}
i = i+1
end
end
--Get the XML data from the inverter
local url = 'curl http://'..ip..'/real_time_data.xml'
local data = assert(io.popen(url))
--print(string.format("http request from SAJ: %s", data))
local LineNr = 0
-- print(tostring(data)) -- debugging
-- print(data) -- should show something like 'file (0x42e0f8)'
for line in data:lines() do
-- print(line) -- should print all lines of the return of the url
LineNr = LineNr + 1
if( string.find(line, 'temp') ~= nil)
then
--print(string.format("line %d: %s", LineNr, line))
temp = string.match(line, "%d+%.%d+")
bTempUpdated = true
elseif( string.find(line, 'e%-total') ~= nil)
then
--print(string.format("line %d: %s", LineNr, line))
total = string.match(line, "%d+%.%d+")
bTotalUpdated = true
elseif( string.find(line, 'e%-today') ~= nil)
then
--print(string.format("line %d: %s", LineNr, line))
today = string.match(line, "%d+%.%d+")
bTodayUpdated = true
elseif( string.find(line, 'p%-ac') ~= nil)
then
--print(string.format("line %d: %s", LineNr, line))
now = string.match(line, "%d+")
bNowUpdated = true
else
--print(string.format("line %d: %s", LineNr, line))
end
end
data:close()
-- Update the Domoticz GUI
if( bTempUpdated==true)
then
--print(string.format("updating SAJ temp:%4.1f",temp))
UpdateDevice('Temperatuur SAJ', temp) --customize the temperature sensor name
end
if( bNowUpdated==true and bTotalUpdated==true)
then
--print(string.format("updating SAJ energy:%d %d",now, total*1000))
UpdateDevice('SolarMain SAJ', now..";".. total*1000) --customize the energy sensor name
end
-- local ep = v1*i1
-- local wp = v2*i2
-- Upload the data to PVoutput every 10 mins
-- date = os.date("*t")
-- if (date.min % 10 == 0) then
-- baseURL="http://pvoutput.org/service/r2/addstatus.jsp?"
-- API="yourAPIkey"
-- PVO_URL= baseURL .. "sid=36263&key=" .. API .. "&d=" .. os.date("%Y%m%d") .. "&t=" .. os.date("%H:%M")
-- PVO_URL = PVO_URL .. "&v1=" .. (today*1000) .. "&v2=" .. now
-- commandArray['OpenURL'] = PVO_URL
-- end
return commandArray