Error in LUA script event

Moderator: leecollings

Post Reply
Erik10
Posts: 11
Joined: Wednesday 03 October 2018 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.97
Contact:

Error in LUA script event

Post 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?
Tonio16
Posts: 45
Joined: Friday 23 February 2018 20:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: France
Contact:

Re: Error in LUA script event

Post 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
Erik10
Posts: 11
Joined: Wednesday 03 October 2018 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.97
Contact:

Re: Error in LUA script event

Post by Erik10 »

Thx Tonio16,
Sorry, I will do that next time
I will try to use tonumber.
Erik10
Posts: 11
Joined: Wednesday 03 October 2018 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.97
Contact:

Re: Error in LUA script event

Post 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:
Joost996me
Posts: 18
Joined: Sunday 12 February 2017 15:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Error in LUA script event

Post by Joost996me »

Can you please specify how to use the data in the output.csv file to sensors in Domoticz?

Much appreciated!

Joost
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest