Page 1 of 1
LUA script set security status
Posted: Saturday 29 December 2018 10:20
by lusnie
Hello all,
I'm trying to set the security status trough LUA scripting.
It seems the Security change isn't activated.
When using the Security Panel all works fine.
Code: Select all
commandArray = {}
if (otherdevices[device1] == "Off") then --Security system to be armed if it's disarmed and no one is at home
commandArray['Domoticz Security Panel'] = 'Arm Away'
return commandArray
I have a second lua script to see if the Security Settings are changed.
This lua scripts only become active after changing the Security Panel not after the lua script above
Code: Select all
commandArray = {}
print('SecPanel: status changed to ' .. globalvariables['Security'])
return commandArray
Does anyone have an idea what i'm doing wrong?
Re: LUA script set security status
Posted: Saturday 29 December 2018 12:15
by jvdz
What is the value of the device1 variable as that is which status you are testing?
Jos
Re: LUA script set security status
Posted: Saturday 29 December 2018 12:25
by waaren
lusnie wrote: ↑Saturday 29 December 2018 10:20
Hello all,
I'm trying to set the security status trough LUA scripting.
It seems the Security change isn't activated.
When using the Security Panel all works fine.
Code: Select all
commandArray = {}
if (otherdevices[device1] == "Off") then --Security system to be armed if it's disarmed and no one is at home
commandArray['Domoticz Security Panel'] = 'Arm Away'
return commandArray
I have a second lua script to see if the Security Settings are changed.
This lua scripts only become active after changing the Security Panel not after the lua script above
Code: Select all
commandArray = {}
print('SecPanel: status changed to ' .. globalvariables['Security'])
return commandArray
Does anyone have an idea what i'm doing wrong?
Please have a look at the script and discussion in this
topic Maybe it will help.
Re: LUA script set security status
Posted: Saturday 29 December 2018 15:53
by lusnie
Hi,
Device1 is changed to off when i'm testing
When using a print in the code it appears in the log. So it seems that this is OK.
Re: LUA script set security status
Posted: Saturday 29 December 2018 17:13
by jvdz
lusnie wrote: ↑Saturday 29 December 2018 15:53
Hi,
Device1 is changed to off when i'm testing
When using a print in the code it appears in the log. So it seems that this is OK.
So you mean the actual device name is device1? in that case the test should be: if (otherdevices["device1"] == "Off")
Jos
Re: LUA script set security status
Posted: Saturday 29 December 2018 18:28
by lost
lusnie wrote: ↑Saturday 29 December 2018 15:53
Device1 is changed to off when i'm testing
When using a print in the code it appears in the log. So it seems that this is OK.
So, this must be the name of the switch linked to security panel status.
I have this kind of scripting to control sec panel from a global presence switch driven by phones BT detection and this works from this code snippet:
Code: Select all
devSecPanel = 'SecPanel'
-- Other stuff ...
-- Global user presence/Domoticz sec panel status management.
if (devicechanged['PresenceGlobal']) then
-- Force auto mode back to on if needed on known user presence.
if (otherdevices[devAlarmAutoSwitch] == 'Off') then
commandArray[devAlarmAutoSwitch] = 'On'
end
-- Update sec panel.
if (devicechanged['PresenceGlobal'] == 'On') then
print('Security : DISARM (Presence)')
commandArray[devSecPanel] = 'Disarm'
else
if (otherdevices[devAlarmAutoSwitch] == 'On') then
print('Security : ARM AWAY (Presence)')
commandArray[devSecPanel] = 'Arm Away'
end
end
end
And this works perfectly. On my side, in hardware, domoticz internal security panel switch is named (by me) "SecPanel" (as set in global variable devSecPanel).
So, that's just some:
commandArray[devSecPanel] = 'Disarm'
commandArray[devSecPanel] = 'Arm Away'
Commands... If your debug print is OK, IMO this is just a naming issue for the switch linked to domoticz security panel status.
Regards.
Re: LUA script set security status
Posted: Saturday 29 December 2018 20:54
by lusnie
Here is the complete code
Code: Select all
--------------------------------
------ Variables to edit ------
--------------------------------
device1 = "Phone: OnePlus 5" --Phone #1
device2 = "Phone: OnePlus" --Phone #2
device3 = "Phone: iPhone" --Phone #3
device4 = "Phone: OnePlus 2" --Phone #4
debug = false
--------------------------------
-- End of variables to edit --
--------------------------------
commandArray = {}
if (devicechanged[device1] or devicechanged[device2] or devicechanged[device3] or devicechanged[device4]) then
print("Aanwezigheids script gestart ...")
if (debug) then
print("State of security system:")
print(globalvariables["Security"])
end
-- Waardes van de devicechange tabel
print("Following values are coming in with device changed table: ")
deviceValue = ""
deviceName = ""
for name, value in pairs(devicechanged) do
print(name, value)
deviceValue = value --Store value of the device changed to deviceValue variable
deviceName = name --Store name of the device changed to deviceName variable
end
if (globalvariables["Security panel"] == "Disarmed" and otherdevices[device1] == "Off" and otherdevices[device2] == "Off" and otherdevices[device3] == "Off" and otherdevices[device4] == "Off") then --Security system to be armed if it's disarmed and no one is at home
print("Nobody home, activate Security System")
commandArray['Domoticz Security Panel'] = 'Arm Away'
commandArray["Away Mode"] = 'On' -- Zet trigger voor andere lua scripts
elseif (globalvariables["Security panel"] ~= "Disarmed" and (otherdevices[device1] == "On" or otherdevices[device2] == "On" or otherdevices[device3] == "On" or otherdevices[device4] == "On")) then --Security system to be disarmed if it's armed and someone has come back to home
print("Security system gaat uit omdat "..deviceName.." thuis komt")
commandArray['Domoticz Security panel']='Disarm'
commandArray["Away Mode"]= 'Off' -- Zet trigger voor andere lua scripts
end
end
return commandArray
The Switch ' Away Mode' is switched correctly. But the securitysystem is not changing to Arm Away or back to Disarm.
Re: LUA script set security status
Posted: Saturday 29 December 2018 21:19
by jvdz
Have you double-checked the device name for the secpanel as that seems to be the only remaining option that could be wrong?
The disarm name is different than the arm name, so at least one is wrong!
Jos
Re: LUA script set security status
Posted: Sunday 30 December 2018 9:35
by lusnie
Hi Jos,
Thanks, a problem with the name was my idea. So i was testing. But on both names no succes for switches the status of the Alarm.
In the browser the name of de SecPanel is ' Domiticz Security Panel'
All scripting examples in this forum and on the internet are the same.
I will give it a try to find the correct name.
Re: LUA script set security status
Posted: Wednesday 02 January 2019 10:45
by lusnie
Solved by using OpenURL
Code: Select all
commandArray['OpenURL']='http://localhost/json.htm?type=command¶m=setsecstatus&secstatus=2&seccode=SECCODE'
Re: LUA script set security status
Posted: Wednesday 02 January 2019 10:54
by waaren
lusnie wrote: ↑Wednesday 02 January 2019 10:45
Solved by using OpenURL
Code: Select all
commandArray['OpenURL']='http://localhost/json.htm?type=command¶m=setsecstatus&secstatus=2&seccode=SECCODE'
Great !
Where did you find this information ? Would be nice if the current API/JSON wiki is updated with this but I need to know more about possible values for secstatus and seccode before I can do that in a meaningful way.
Re: LUA script set security status
Posted: Wednesday 02 January 2019 22:10
by lusnie
Re: LUA script set security status
Posted: Wednesday 02 January 2019 22:16
by waaren
Thanks ! Will update the wiki page with this information.