Looking for help on a script.

Moderator: leecollings

Post Reply
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Looking for help on a script.

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

Re: Looking for help on a script.

Post 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 534 times
Last edited by waaren on Saturday 28 July 2018 10:24, edited 1 time in total.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Re: Looking for help on a script.

Post 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.
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Re: Looking for help on a script.

Post 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??
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest