Hi, I need help with a simple lua script. I wan't to do a script that turn off all lights (scene) when I turn on Security panel (arm away) and turn on one light when I deactivated security panel.
The first works fine but when I turn off the security panel doesn't happen.
this is the script:
commandArray = {}
local encendido
if (otherdevices['Security Panel'] == 'Arm Away') then
commandArray['Scene:ApagarLuces'] = 'On'
encendido = "Off"
print ("encendido: " .. encendido)
elseif (encendido == "Off") and (otherdevices['Security Panel'] == 'Normal') then
commandArray['Hab3 - Luz'] = 'On'
encendido = "On"
print ("encendido: " .. encendido)
end
return commandArray
On the other hand, I wan't to turn off light once time but with this script don't let me turn on any light when panel security is Arm Away, automatically turn off light.
Thank you very much
Regards
Can anybody help me?
Moderator: leecollings
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Can anybody help me?
Local variables aren't saved as the script's life ends when done so you can't test encendido in that way.
Just create a script called: script_security_panel-changes.lua looking something like this:
Jos
Just create a script called: script_security_panel-changes.lua looking something like this:
Code: Select all
commandArray = {}
--
printlog('###', 'SecPanel: status changed to ' .. globalvariables['Security'])
if globalvariables['Security'] == 'Disarmed' then
commandArray['Hab3 - Luz'] = 'On'
elseif globalvariables['Security'] == 'Armed Home' then
elseif globalvariables['Security'] == 'Armed Away' then
commandArray['Scene:ApagarLuces'] = 'On'
end
return commandArray
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 2
- Joined: Wednesday 24 February 2016 22:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Can anybody help me?
Thank you very much, now I have this error:
script_security_panel-changes.lua:3: attempt to call global 'printlog' (a nil value)
If I comment printlog line, works fine.
script_security_panel-changes.lua:3: attempt to call global 'printlog' (a nil value)
If I comment printlog line, works fine.
-
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: Can anybody help me?
Change to .
Code: Select all
printlog
Code: Select all
print
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Can anybody help me?
Yea sorry, I use a standard library with some extra functions and printlog is one of them.
So changing it to print() should fix the error like dannybloe indicated.
Jos
So changing it to print() should fix the error like dannybloe indicated.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Re: Can anybody help me?
This puts my system into a endless loop.
jvdz wrote:Local variables aren't saved as the script's life ends when done so you can't test encendido in that way.
Just create a script called: script_security_panel-changes.lua looking something like this:JosCode: Select all
commandArray = {} -- printlog('###', 'SecPanel: status changed to ' .. globalvariables['Security']) if globalvariables['Security'] == 'Disarmed' then commandArray['Hab3 - Luz'] = 'On' elseif globalvariables['Security'] == 'Armed Home' then elseif globalvariables['Security'] == 'Armed Away' then commandArray['Scene:ApagarLuces'] = 'On' end return commandArray
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Can anybody help me?
Doubt that my posted script makes an endless loop unless you have made modifications.seansco wrote:This puts my system into a endless loop.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Who is online
Users browsing this forum: No registered users and 1 guest