PDA

View Full Version : Speak all violated security zones



jwilson56
November 7th, 2008, 07:50 AM
Voice :Speak("The System will NOT be armed")

-- Change these to your zone names ['elk zone name']='spoken voice name'
local zones = {
['Front Door'] = 'Front Door',
['Back Door'] = 'Back Door',
['Kitchen Window E'] = 'Kitchen East Side Window',
['Kitchen Window S'] = 'Kitchen South Side Window',
['Living Room S'] = 'Living Room South Side Window',
['Guest Room E'] = 'Guest Room East Side Window',
['Bedroom E'] = 'Bedroom East Side Window',
['Den W'] = 'Den West Side Window',
['Den N'] = 'Den North Side Window',
}


-- builds device list control using filter list
-- filter = {location = ,name = , devicetype = )




local function BuildDeviceListControl (filterlist)
local changed = false


-- device list
local dl = {}

for _,filter in ipairs (filterlist) do
local list = DeviceManager:GetDevices (filter.Location,filter.Name,filter.DeviceType,fil ter.Abilities)

for _,device in ipairs (list) do
table.insert (dl,device)
end
end

table.sort (dl,function (a,b) return a:GetLocationName () < b:GetLocationName () end )

local locnamelist = {}
local devicesindextopath = {}


for i,d in ipairs (dl) do
table.insert (locnamelist, d:GetLocationName())
devicesindextopath [i-1] = d:GetPath () -- itemindex is 0 based
end

if table.getn (locnamelist) < 1 then -- no devices
table.insert (locnamelist,nodevices)
end

return locnamelist, devicesindextopath -- true if the any of the menus changed
end

local FilterList = {{DeviceType = 'Security\\Zone'}}
local Devices, Paths = BuildDeviceListControl (FilterList)

for k,v in ipairs(Paths) do
local device = DeviceManager:GetDeviceUsingPath (v)

if device then

if device:GetControl('Condition'):GetValue() == 'Violated' and zones[device:GetName()] then


print (zones[device:GetName()], device:GetName())
Voice :Speak(zones[device:GetName()]..' Violated')

end
end
end

Mike C
November 7th, 2008, 09:16 AM
John,

This looks more complicated then needed -> do you just want to speak all security zones that are not ready?

Also, it looks like the Elk is setting a security zone to "Violated" , not using G DM Convention "Not Ready".... this will break any code that expects a security zone to have Ready or Not Ready states.

jwilson56
November 7th, 2008, 09:57 AM
Well this is why the forum was created... some of us new to this. Complicated or not it does work.

I passed the Violated info to Rick.

Mike C
November 7th, 2008, 10:14 AM
local sz = DeviceManager:GetDevices (false,false,'Security\\Zone')

for _,device in ipairs (sz) do
if device:GetControlValue ('Condition') ~= 'Ready' then
print (device:GetLocationName (),' is not ready')
else
print (device:GetLocationName (),' is ready')
end
end



this shows the state of all security zones.....

to specify what to speak, you could use the DM pages to edit the device description field and speak that text.

if you want to sort the list do....







local sz = DeviceManager:GetDevices (false,false,'Security\\Zone')

table.sort (sz,
function (a,b)
return a:GetLocationName () < b:GetLocationName ()
end
)

for _,device in ipairs (sz) do
if device:GetControlValue ('Condition') ~= 'Ready' then
print (device:GetLocationName (),' is not ready')
else
print (device:GetLocationName (),' is ready')
end
end

harleydude
November 7th, 2008, 10:56 AM
Mike,

Your method will work just fine, if you wanted to cycle through all the Security\Zones. The original script was setup to just check a few specific zones. Could the original script be less complicated, yes. With that, I have modified the script to be less complicated.


Voice:Speak("The System will NOT be armed")

-- Change the path to match the devices you want announced,
-- The path names are available in the Device Manager Screen
-- TTSName is the text that will be spoken for each device
local zones = {
{ TTSName = 'Front Door', Path = [[ncc-1701\ElkM1EZ8\Zone 1]] },
{ TTSName = 'Back Door', Path = [[ncc-1701\ElkM1EZ8\Zone 2]] },
{ TTSName = 'Garage Door', Path = [[ncc-1701\ElkM1EZ8\Zone 3]] },
}

for k,v in ipairs(zones) do
local device = DeviceManager:GetDeviceUsingPath (v.Path)
if device then
if device:GetControlValue ('Condition') == 'Violated' then
print (v.TTSName..' Violated')
Voice:Speak(v.TTSName..' Violated')
end
end
end

I chose to have the TTSName in the script to keep things all in one place.

On the Violated/Normal vs Not Ready/Ready issue, I agree with you on that and will make that change. Once I make that change, I will modify the script in this post to reflect the changes.