Page 1 of 1

Error in LUA script event

Posted: Thursday 18 October 2018 15:44
by Erik10
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?

Re: Error in LUA script event

Posted: Thursday 18 October 2018 16:13
by Tonio16
Please use the code display </> to share your program.

Os.date. Is it not a string value? Try with a tonumber https://www.domoticz.com/wiki/User_variables

Antoine

Re: Error in LUA script event

Posted: Thursday 18 October 2018 17:02
by Erik10
Thx Tonio16,
Sorry, I will do that next time
I will try to use tonumber.

Re: Error in LUA script event

Posted: Thursday 18 October 2018 20:20
by Erik10
I think I have got it.
The LUA compiler is running on the PC (with a USB stick with the CSV file) So that works fine.
But... Domoticz is on a RPI and therefore Domoticz cannot find that file. :oops:

Re: Error in LUA script event

Posted: Saturday 08 June 2019 21:18
by Joost996me
Can you please specify how to use the data in the output.csv file to sensors in Domoticz?

Much appreciated!

Joost