-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscript_device_presencedetection.lua
47 lines (39 loc) · 2.1 KB
/
script_device_presencedetection.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
--[[Intention of this script is to arm security system if all mobile devices are out of home (= no one is at home).
The script also disarms the security system, if armed, when at least one of the mobile device is detected.
Device detection is based on Presence detection script which can be found from the Domoticz wiki (https://www.domoticz.com/wiki/Presence_detection).]]
--------------------------------
------ Variables to edit ------
--------------------------------
device1 = "device1" --Name of the mobile device
device2 = "device2" --Name of the mobile device
device3 = "device3" --Name of the mobile device
securitySystem = "Security system" --Name of the security system
debug = false
--------------------------------
-- End of variables to edit --
--------------------------------
commandArray = {}
if (devicechanged[device1] or devicechanged[device2] or devicechanged[device3]) then
print("Presence detection script running...")
if (debug) then
print("State of security system:")
print(globalvariables["Security"])
end
-- Value of devicechanged table is stored to deviceValue variable
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"] == "Disarmed" and otherdevices[device1] == "Off" and otherdevices[device2] == "Off" and otherdevices[device3] == "Off") then --Security system to be armed if it's disarmed and no one is at home
print("No one is at home, security system to be armed")
commandArray["Varashälytin"] = "Arm Away" -- Security system armed
elseif (globalvariables["Security"] ~= "Disarmed" and deviceValue == "On") then --Security system to be disarmed if it's armed and someone has come back to home
print("Security system disarmed because "..deviceName.." came back home")
commandArray["Varashälytin"] = "Disarm" -- Security system disarmed
end
end
return commandArray