SAJ solar script fired multiple times

Moderator: leecollings

Post Reply
JPSke
Posts: 33
Joined: Wednesday 11 November 2020 11:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Sint-Gillis-Waas, Belgium
Contact:

SAJ solar script fired multiple times

Post by JPSke »

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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: SAJ solar script fired multiple times

Post by waaren »

JPSke wrote: Tuesday 12 January 2021 12:02 Does anyone know why this SAJ solar script (which I found somewhere on this forum) runs several times in a row:
This is not a working dzVents script. It has parts of a dzVents but majority of the code is Classic Lua. You probably saved it as Lua All or Lua device triggered script.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JPSke
Posts: 33
Joined: Wednesday 11 November 2020 11:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Sint-Gillis-Waas, Belgium
Contact:

Re: SAJ solar script fired multiple times

Post by JPSke »

As I wrote, I did not compose this script but found it on the forum (https://domoticz.com/forum/viewtopic.ph ... d8#p228445). Last post of this thread.
You are probably right about not being a Dzvents script, but sort of lua. I'm not experienced enough in this matter to tell.
The question remains: why is it triggered so often en what can be done about it?
The trigger says 'every minute' and that is what it does allright, but in between minutes there's something else that starts the script.
Thanks in advance.
JPSke
Posts: 33
Joined: Wednesday 11 November 2020 11:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Sint-Gillis-Waas, Belgium
Contact:

Re: SAJ solar script fired multiple times

Post by JPSke »

Sorry, my limited knowledge of scripting prevented me from noticing the answer was in your reply.
I changed the value in the "trigger" field from 'All' to 'Time' and everything is working now as it should.
Thanks and sorry to have bothered you.
JP
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest