changing security via LUA

Moderator: leecollings

Post Reply
harrykausl
Posts: 184
Joined: Sunday 13 November 2016 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Germany
Contact:

changing security via LUA

Post 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
User avatar
jvdz
Posts: 2332
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: changing security via LUA

Post by jvdz »

This should work fine:

Code: Select all

commandArray['SecPanel']='Arm Home'
commandArray['SecPanel']='Arm Away'
commandArray['SecPanel']='Disarm'
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
harrykausl
Posts: 184
Joined: Sunday 13 November 2016 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Germany
Contact:

Re: changing security via LUA

Post 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.
harrykausl
Posts: 184
Joined: Sunday 13 November 2016 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Germany
Contact:

Re: changing security via LUA

Post 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.
User avatar
jvdz
Posts: 2332
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: changing security via LUA

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
jvdz
Posts: 2332
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: changing security via LUA

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
harrykausl
Posts: 184
Joined: Sunday 13 November 2016 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Germany
Contact:

Re: changing security via LUA

Post by harrykausl »

@Jos: Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest