Page 1 of 1

LUA script set security status to .. by remote

Posted: Friday 07 December 2018 11:24
by AllesVanZelf
Hello,
I have an strange problem.
In my domoticz-system (rpi3B+ with raspbian) I wanted to use the remote control (Aeontec Keyfob gen5) to switch between security panel alarm status: Disable, Arm Away, Arm Home. With some puzzling this is working well now with the following script:

Code: Select all

commandArray = {}
 if (devicechanged['remote-1'] == 'On') then
    commandArray['Domoticz Security Panel'] = 'Arm Away'
     print('### SecPanel: status changed to ' .. globalvariables['Security'])
 end
 if (devicechanged['remote-2'] == 'On') then
    commandArray['Domoticz Security Panel'] = 'Arm Home'
     print('### SecPanel: status changed to ' .. globalvariables['Security'])
 end
 if (devicechanged['remote-3'] == 'On') then
    commandArray['Domoticz Security Panel'] = 'Disarm'
     print('### SecPanel: status changed to ' .. globalvariables['Security'])
 end
return commandArray

This script is saved as device Lua.
Changing the status of Alarm by buttons works. But the log is showing the last status of the security panel instead of the new one.
What can I change in this script to fix this? Any tips?

Re: LUA script set security status to .. by remote

Posted: Friday 07 December 2018 14:12
by jvdz
That is because the actual change of the secpanel is done bij domoticz after the LUA script handed the CommandArray back at termination time.
Just make a script called "script_security_panel-changes.lua" and put the print statement in there as this script is only fired when the secpanel changes.

Jos

Re: LUA script set security status to .. by remote

Posted: Saturday 08 December 2018 13:20
by AllesVanZelf
Okay, I'll try that this evening. Thank you.

Re: LUA script set security status to .. by remote

Posted: Monday 10 December 2018 15:46
by AllesVanZelf
Okay. I split the script in two parts. The code is as follows

Code: Select all

commandArray = {}
 if (devicechanged['remote-1'] == 'On') then
    commandArray['Domoticz Security Panel'] = 'Arm Away'
 end
 if (devicechanged['remote-2'] == 'On') then
    commandArray['Domoticz Security Panel'] = 'Arm Home'
 end
 if (devicechanged['remote-3'] == 'On') then
    commandArray['Domoticz Security Panel'] = 'Disarm'
 end

 if (devicechanged['Domoticz Security Panel'] == 'Arm Away') then
    print('### SecPanel: status changed to ' .. globalvariables['Security'])
 end
 if (devicechanged['Domoticz Security Panel'] == 'Arm Home') then
    print('### SecPanel: status changed to ' .. globalvariables['Security'])
 end
 if (devicechanged['Domoticz Security Panel'] == 'Normal') then
    print('### SecPanel: status changed to ' .. globalvariables['Security'])
 end
return commandArray

Is it possible to reduce this in one part? Something like this:

Code: Select all

if (devicechanged['Domoticz Security Panel'] == 'Arm Away|Arm Home|Normal') then
    print('### SecPanel: status changed to ' .. globalvariables['Security'])
 end

Re: LUA script set security status to .. by remote

Posted: Monday 10 December 2018 16:58
by jvdz
As I mentioned in my previous post: That second part needs to be done in the script_security_panel-changes.lua script as that is fired when the SecPanel changes.
So just create that file and add these lines:

Code: Select all

commandArray = {}
print('SecPanel: status changed to ' .. globalvariables['Security'])
return commandArray
Jos :D

Re: LUA script set security status to .. by remote

Posted: Monday 10 December 2018 18:27
by AllesVanZelf
Thank you! That was helping a lot.
With this separated script I could remove the "print('SecPanel: status changed to ' .. globalvariables['Security'])"
from my tag reader LUA script too. Very good.