Error in LUA script event
Posted: Thursday 18 October 2018 15:44
Hi,
I try to retrieve some values from a CSV file of my Resol solar boiler. I use a script to read from the file each minute. I checked the code within Zero Brain Studio and it is working fine.
When I try to run the code in Domoticz Events I get this error:
Error: EventSystem: in Update RESOL: [string "local m = os.date('%M')
..."]:10: attempt to index global 'bestand' (a nil value)
This is the code:
local m = os.date('%M')
if (m % 1 == 0) then
--print("The minute script interval reached")
-- Put your script code here that shall run every 5 minutes
local regel = {}
mijnarray = {}
bestand = io.open("L://Output.csv","r")
i = 1
for line in bestand:lines() do
regel=line
i=i+1
-- print(i)
end
--print(regel[3]) -- dit is de juiste regel
j = 0
for token in string.gmatch(regel[3], "[^%s]+") do
--print(token)
j= j+1
mijnarray[j] = token
end
mijnarray[15] = mijnarray[15]/1000 -- in kWh ipv Wh
--print("temp buiten",mijnarray[4])
--print("temp binnen",mijnarray[5])
--print("pomp",mijnarray[12])
--print("totaal opwek",mijnarray[15])
commandArray = {}
commandArray['UpdateDevice']='42|0|mijnarray[4]'
commandArray['UpdateDevice']='43|0|mijnarray[5]'
commandArray['UpdateDevice']='44|0|mijnarray[12]'
commandArray['UpdateDevice']='45|0|mijnarray[15]'
print("waarde",mijnarray[15])
return commandArray
end
I used the Time tab.
Any thoughts?
I try to retrieve some values from a CSV file of my Resol solar boiler. I use a script to read from the file each minute. I checked the code within Zero Brain Studio and it is working fine.
When I try to run the code in Domoticz Events I get this error:
Error: EventSystem: in Update RESOL: [string "local m = os.date('%M')
..."]:10: attempt to index global 'bestand' (a nil value)
This is the code:
local m = os.date('%M')
if (m % 1 == 0) then
--print("The minute script interval reached")
-- Put your script code here that shall run every 5 minutes
local regel = {}
mijnarray = {}
bestand = io.open("L://Output.csv","r")
i = 1
for line in bestand:lines() do
regel=line
i=i+1
-- print(i)
end
--print(regel[3]) -- dit is de juiste regel
j = 0
for token in string.gmatch(regel[3], "[^%s]+") do
--print(token)
j= j+1
mijnarray[j] = token
end
mijnarray[15] = mijnarray[15]/1000 -- in kWh ipv Wh
--print("temp buiten",mijnarray[4])
--print("temp binnen",mijnarray[5])
--print("pomp",mijnarray[12])
--print("totaal opwek",mijnarray[15])
commandArray = {}
commandArray['UpdateDevice']='42|0|mijnarray[4]'
commandArray['UpdateDevice']='43|0|mijnarray[5]'
commandArray['UpdateDevice']='44|0|mijnarray[12]'
commandArray['UpdateDevice']='45|0|mijnarray[15]'
print("waarde",mijnarray[15])
return commandArray
end
I used the Time tab.
Any thoughts?