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
LUA If then problem
Moderator: leecollings
- jvdz
- Posts: 2334
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: LUA If then problem
Maybe the extra brackets are required.
Jos
By the way: I did a quick format to make the source a little more readable and noticed you are missing an end statement in the posted code.
Jos
By the way: I did a quick format to make the source a little more readable and noticed you are missing an end statement in the posted code.
Code: Select all
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
end
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 2
- Joined: Friday 04 April 2014 17:17
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: LUA If then problem
Thank you, i will try it.
It works now with the extra brackets.
It works now with the extra brackets.
Who is online
Users browsing this forum: No registered users and 1 guest