LUA script set security status to .. by remote

Moderator: leecollings

Post Reply
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

LUA script set security status to .. by remote

Post 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?
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

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

Post by AllesVanZelf »

Okay, I'll try that this evening. Thank you.
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

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

Post 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
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

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

Post 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.
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest