LUA If then problem
Posted: Monday 04 April 2016 0:31
Hello,
I'm using 3.4834 running on Ubuntu 14.04 and this script was working before 3.4834.
The script is looking for a device change and if this device is an Door/Window contact (starting with DC in the device name) the alarm variable is set to 1.
commandArray = {}
Sound = uservariables["Sound"]
SMS = uservariables["SMS"]
Zwave_siren = uservariables["Zwave_siren"]
Ring = uservariables["Ring"]
local alarm = 0
Logging = true
d = otherdevices
device = ""
for i, v in pairs(devicechanged) do
if (#device == 0 or #i < #device) then device = i end
end
if (Logging) then print("*** Triggered by " .. device .. " now " .. d[device]) end
--
-- Main -------------------------------------
--
sm = device:sub(1,2)
if (sm == 'DC' or sm == 'MD') then
-- Check for Bell ring
if (globalvariables['Security'] == 'Disarmed') then
if ((d[device] == 'Open') or (d[device] == 'Alarm') and Ring == 1) then
print ('*** Ring the bell on contact *** '.. d[device])
os.execute('play /sounds/sound_doorbell.wav')
end
end
-- The problem starts inside this If then below , even when the d[device] = normal the alarm is set to 1
if (sm == 'DC') then
if ((d[device] == 'Open') and (globalvariables['Security'] == 'Armed Away') or (globalvariables['Security'] == 'Armed Home')) then
alarm = 1
print ('*** Attention : Alarm detected on Door/Window *** '.. device)
end
if ((d[device] == 'Alarm') and (globalvariables['Security'] == 'Armed Away') or (globalvariables['Security'] == 'Armed Home')) then
alarm = 1
print ('*** Attention : Alarm detected on Door/Window *** '.. device)
end
end
Thank you in advance for your help.
Regards Henri
I'm using 3.4834 running on Ubuntu 14.04 and this script was working before 3.4834.
The script is looking for a device change and if this device is an Door/Window contact (starting with DC in the device name) the alarm variable is set to 1.
commandArray = {}
Sound = uservariables["Sound"]
SMS = uservariables["SMS"]
Zwave_siren = uservariables["Zwave_siren"]
Ring = uservariables["Ring"]
local alarm = 0
Logging = true
d = otherdevices
device = ""
for i, v in pairs(devicechanged) do
if (#device == 0 or #i < #device) then device = i end
end
if (Logging) then print("*** Triggered by " .. device .. " now " .. d[device]) end
--
-- Main -------------------------------------
--
sm = device:sub(1,2)
if (sm == 'DC' or sm == 'MD') then
-- Check for Bell ring
if (globalvariables['Security'] == 'Disarmed') then
if ((d[device] == 'Open') or (d[device] == 'Alarm') and Ring == 1) then
print ('*** Ring the bell on contact *** '.. d[device])
os.execute('play /sounds/sound_doorbell.wav')
end
end
-- The problem starts inside this If then below , even when the d[device] = normal the alarm is set to 1
if (sm == 'DC') then
if ((d[device] == 'Open') and (globalvariables['Security'] == 'Armed Away') or (globalvariables['Security'] == 'Armed Home')) then
alarm = 1
print ('*** Attention : Alarm detected on Door/Window *** '.. device)
end
if ((d[device] == 'Alarm') and (globalvariables['Security'] == 'Armed Away') or (globalvariables['Security'] == 'Armed Home')) then
alarm = 1
print ('*** Attention : Alarm detected on Door/Window *** '.. device)
end
end
Thank you in advance for your help.
Regards Henri