LUA script set security status to .. by remote

Post Reply
AllesVanZelf
Posts: 21
Joined: Monday 05 February 2018 9:42
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

LUA script set security status to .. by remote

Post by AllesVanZelf » Friday 07 December 2018 12:24

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?

User avatar
jvdz
Posts: 1465
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

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

Post by jvdz » Friday 07 December 2018 15:12

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

AllesVanZelf
Posts: 21
Joined: Monday 05 February 2018 9:42
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

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

Post by AllesVanZelf » Saturday 08 December 2018 14:20

Okay, I'll try that this evening. Thank you.

AllesVanZelf
Posts: 21
Joined: Monday 05 February 2018 9:42
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

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

Post by AllesVanZelf » Monday 10 December 2018 16:46

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

User avatar
jvdz
Posts: 1465
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

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

Post by jvdz » Monday 10 December 2018 17:58

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

AllesVanZelf
Posts: 21
Joined: Monday 05 February 2018 9:42
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

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

Post by AllesVanZelf » Monday 10 December 2018 19:27

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests