Page 1 of 1

Looking for help on a script.

Posted: Friday 27 July 2018 22:25
by Melotron
HIya.

I'am trying to learn lua, but failing in my normal rate (everytime)
I've tried to get my normal status blocky to lua, but its telling me tht I dont know what I'am doing.

Whats wrong here ??

Code: Select all

commandArray = {}
if (devicechanged['Virt_Dusk'] == 'On' and 
     otherdevices['Virt_Dark'] == 'Off' and 
	 otherdevices['Hemma'] == 'On' and
	 otherdevices['Virt_Sleep'] == 'Off' and 
	 otherdevices['Virt_TV'] == 'Off' and 
	 otherdevices['Virt_Manuell'] == 'Off') then
commandArray['Scene:Dusk']='On'
print('Scene Dusk')
end
if (devicechanged['Virt_Dusk'] == 'Off' and 
     otherdevices['Virt_Dark'] == 'On' and 
	 otherdevices['Hemma'] == 'On' and
	 otherdevices['Virt_Sleep'] == 'Off' and 
	 otherdevices['Virt_TV'] == 'Off' and 
	 otherdevices['Virt_Manuell'] == 'Off') then
	 commandArray['Scene:Dark']='On'
print('Scene Dark')
end
if (devicechanged['Virt_Dag'] == 'On' and 
     otherdevices['Hemma'] == 'On' ) then
commandArray['Scene:Day']='On'
print('Scene Day')
end
return commandArray
The error code are :
Error: EventSystem: in LUA Hemma Vanligt: [string "commandArray = {} ..."]:2: attempt to index global 'devicechanged' (a nil value)

I'am even failing on a even simpler script.

Code: Select all

commandArray = {}
if (devicechanged['Idiot'] == 'On') then
print ('IDIOT=ON')
end
if (devicechanged['Idiot'] == 'Off') then
print ('IDIOT=Off')
end
return commandArray 
Error: EventSystem: in IDIOT: [string "commandArray = {} ..."]:2: attempt to index global 'devicechanged' (a nil value)

What are I'am doing wrong here, besides not understanding what Domo are trying to tell me.

Regards Magnus Svensson

Re: Looking for help on a script.

Posted: Saturday 28 July 2018 0:10
by waaren
Melotron wrote: Friday 27 July 2018 22:25 HIya.

I'am trying to learn lua, .....

I'am even failing on a even simpler script.

Code: Select all

commandArray = {}
if (devicechanged['Idiot'] == 'On') then
print ('IDIOT=ON')
end
if (devicechanged['Idiot'] == 'Off') then
print ('IDIOT=Off')
end
return commandArray 
Error: EventSystem: in IDIOT: [string "commandArray = {} ..."]:2: attempt to index global 'devicechanged' (a nil value)

What are I'am doing wrong here, besides not understanding what Domo are trying to tell me.

Regards Magnus Svensson
I am by no means a domoticz LUA expert but I played a little bit with your second script and it looks like you did not save it as a device type script.
Like
Idiot.PNG
Idiot.PNG (40.47 KiB) Viewed 538 times

Re: Looking for help on a script.

Posted: Saturday 28 July 2018 0:22
by Melotron
waaren wrote: Saturday 28 July 2018 0:10 I am by no means a domoticz LUA expert but I played a little bit with your seconds script and it looks like you did not save it as a device type script.
Like
Idiot.PNG
Thanks, your better then me lol
But why aren't my main script working.
Its saved as device. I'm going to try and save it as a .lua file tomorrow. See if that's working better.

Re: Looking for help on a script.

Posted: Saturday 28 July 2018 15:23
by Melotron
Iam trying to run this as an enviromental script, thats starting every 5th minute.
But its runing every minute, but only the Day scene.
Its set to dusk now but its still going on as the day switch are set.

I have a LUX meter on the outside thats sending the lux to a utility swith and a lux bloky thats setting the Day, Dusk and Dark switch.

Code: Select all

---------------------------------------------
-- Run enviromental scene every 5th minute --
---------------------------------------------
commandArray = {}

local m = os.date('%M')
if (m % 5 == 0) then
	print("The 5th minute")
	-- Code here will run every 5th minute
end
if (otherdevices['Virt_Dusk'] == 'On' and 
	 otherdevices['Hemma'] == 'On' and
	 otherdevices['Virt_Sleep'] == 'Off' and 
	 otherdevices['Virt_Manuell'] == 'Off') then
commandArray['Scene:Dusk']='On'
print('Scene Dusk')
end

if (otherdevices['Virt_Dark'] == 'On' and 
	 otherdevices['Hemma'] == 'On' and
	 otherdevices['Virt_Sleep'] == 'Off' and 
	 otherdevices['Virt_Manuell'] == 'Off') then
	 commandArray['Scene:Dark']='On'
print('Scene Dark')
end

if (otherdevices['Virt_Dag'] == 'On' and 
     otherdevices['Hemma'] == 'On' ) then
commandArray['Scene:Day']='On'
print('Scene Day')
end

return commandArray
2018-07-28 15:15:00.674 dzVents: The 5th minute
2018-07-28 15:15:00.676 dzVents: Scene Day
2018-07-28 15:15:00.678 EventSystem: Script event triggered: LUA 5th enviroment

2018-07-28 15:16:00.560 dzVents: Scene Day
2018-07-28 15:16:00.563 EventSystem: Script event triggered: LUA 5th enviroment

Whats wrong with my script??