Page 1 of 1

Can anybody help me?

Posted: Wednesday 24 February 2016 22:33
by nalayh
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

Re: Can anybody help me?

Posted: Wednesday 24 February 2016 22:45
by jvdz
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:

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
Jos

Re: Can anybody help me?

Posted: Wednesday 24 February 2016 23:43
by nalayh
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.

Re: Can anybody help me?

Posted: Thursday 25 February 2016 8:08
by dannybloe
Change

Code: Select all

printlog
to

Code: Select all

print
.

Re: Can anybody help me?

Posted: Thursday 25 February 2016 19:26
by jvdz
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

Re: Can anybody help me?

Posted: Thursday 07 April 2016 17:41
by seansco
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:

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
Jos

Re: Can anybody help me?

Posted: Thursday 07 April 2016 19:09
by jvdz
seansco wrote:This puts my system into a endless loop.
Doubt that my posted script makes an endless loop unless you have made modifications.

Jos