LUA script set security status

Moderator: leecollings

Post Reply
lusnie
Posts: 6
Joined: Saturday 25 August 2018 10:49
Target OS: Linux
Domoticz version: V4.10353
Location: Arnhem
Contact:

LUA script set security status

Post 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?
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

Post by jvdz »

What is the value of the device1 variable as that is which status you are testing?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA script set security status

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
lusnie
Posts: 6
Joined: Saturday 25 August 2018 10:49
Target OS: Linux
Domoticz version: V4.10353
Location: Arnhem
Contact:

Re: LUA script set security status

Post 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.
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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
lost
Posts: 663
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LUA script set security status

Post 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.
lusnie
Posts: 6
Joined: Saturday 25 August 2018 10:49
Target OS: Linux
Domoticz version: V4.10353
Location: Arnhem
Contact:

Re: LUA script set security status

Post 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.
Last edited by lusnie on Sunday 30 December 2018 9:33, edited 1 time in total.
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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
lusnie
Posts: 6
Joined: Saturday 25 August 2018 10:49
Target OS: Linux
Domoticz version: V4.10353
Location: Arnhem
Contact:

Re: LUA script set security status

Post 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.
lusnie
Posts: 6
Joined: Saturday 25 August 2018 10:49
Target OS: Linux
Domoticz version: V4.10353
Location: Arnhem
Contact:

Re: LUA script set security status

Post by lusnie »

Solved by using OpenURL

Code: Select all

commandArray['OpenURL']='http://localhost/json.htm?type=command&param=setsecstatus&secstatus=2&seccode=SECCODE' 
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA script set security status

Post 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&param=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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
lusnie
Posts: 6
Joined: Saturday 25 August 2018 10:49
Target OS: Linux
Domoticz version: V4.10353
Location: Arnhem
Contact:

Re: LUA script set security status

Post by lusnie »

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: LUA script set security status

Post by waaren »

lusnie wrote: Wednesday 02 January 2019 22:10 viewtopic.php?t=9747 :D
Thanks ! Will update the wiki page with this information.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest