Page 1 of 1

changing security via LUA

Posted: Saturday 28 January 2017 11:34
by harrykausl
Hello,
I want to change the globalvariable security to "Arm away" in a lua script. But it seems not to work. Perhaps it is impossible, or I don't know the correct syntax. Can anybody help me?

commandArray['Security']='Arm Away'
commandArray['globalvariables:Security']='Arm Away'

What is correct? Thanks

Re: changing security via LUA

Posted: Saturday 28 January 2017 11:53
by jvdz
This should work fine:

Code: Select all

commandArray['SecPanel']='Arm Home'
commandArray['SecPanel']='Arm Away'
commandArray['SecPanel']='Disarm'
Jos

Re: changing security via LUA

Posted: Saturday 28 January 2017 13:35
by harrykausl
Hello Jos,
thanks for the reply. I include it in my script (it is a device-based-lua script) but it seems not to work.


if (devicechanged['Sicherheit'] == 'On') then

print ( globalvariables['Security'] )
commandArray['SecPanel']='Arm Away'
print ( globalvariables['Security'] )


end

For the print statmements I see the following in the log:

2017-01-28 13:29:48.042 User: Admin initiated a switch command (94/Sicherheit/On)
2017-01-28 13:29:48.050 LUA: Disarmed
2017-01-28 13:29:48.050 LUA: Disarmed

So security hasn't changed. I also see it, because I have a security script which doesn't start. When I change security status via the security panel the script starts.

Re: changing security via LUA

Posted: Saturday 28 January 2017 13:54
by harrykausl
I could fix it myself. I had to set a password for the security panel, arm it and then I saw it as a switch. Then it worked.

Re: changing security via LUA

Posted: Saturday 28 January 2017 13:56
by jvdz
That is because it isn't change at the time you fill the TAble, but rather processed after the LUA script ends.
Look at the domoticz.log to see if the security setting changed after the script completed.
You could also create a LUA script called: script_security_panel-changes.lua and add this into it:

Code: Select all

commandArray = {}
printlog('###', 'SecPanel: status changed to ' .. globalvariables['Security'])
return commandArray
Jos

Re: changing security via LUA

Posted: Saturday 28 January 2017 13:57
by jvdz
harrykausl wrote:I could fix it myself. I had to set a password for the security panel, arm it and then I saw it as a switch. Then it worked.
I see I was answering while you posted this.
Good to hear it worked now!

Jos

Re: changing security via LUA

Posted: Saturday 28 January 2017 14:57
by harrykausl
@Jos: Thanks!