View unanswered posts | View active topics It is currently Fri May 24, 2013 8:06 pm



Reply to topic  [ 3 posts ] 
 Global status variable for all DS10A Window Sensors 
Author Message

Joined: Jan 25, 2006
Posts: 26
Post Global status variable for all DS10A Window Sensors
I've been testing the DS10A Window Sensors with modified scripts and it's working fine. I've simplified the work of others to assign variables for just the DS10As. true = the window or door is closed, false = it is open. This working part of the script might be helpful to those of you who are just trying to get DS10As working without the complications of these other X10 Security devices.

Maybe someone could help me fix the end of this script to set a global variable (called "SecurityStatus") to true or false based on the status of all 12 DS10As. If any one of them is open (false state) then SecurityStatus will be false. Alternatively SecurityStatus can only be true if all DS10A states are true. As it's currently written, an open window would set the global variable SecruityStatus to false but closing one would set it to true even though there may still be an open window somewhere else. I have to fix this loophole in the logic.

My revised script follows:

-- Sample attachment script that illustrates how to listen to
-- commands from security devices. Only the W800RF32
-- interface receives these commands


property devName : {}
property sensStatus : {}
property sensType : {}
property devStatus : ""
property devType : {}

using terms from application "IndigoServer"

-- [BEGIN] SetVariable Subroutine -->

on setVariable(varName, varValue)
if (variable varName exists) then
set value of variable varName to varValue
else
make new variable with properties {name:varName, value:varValue}
end if
end setVariable

-- [END] SetVariable Subroutine <BEGIN>

on receive security event of eventType with code devID

-- DO NOT use spaces in the value of devName,
-- because this code will create variables in
-- Indigo with these names.
-- DS10A IS WINDOW SENSOR DEVICE

set devName to ""
set devType to "DS10A"

if devID = 151 then set devName to "SlidingDoor"
if devID = 102 then set devName to "BedroomWindow1"
if devID = 103 then set devName to "BedroomWindow2"
if devID = 104 then set devName to "BedroomWindow3"
if devID = 105 then set devName to "BathWindow"
if devID = 106 then set devName to "FrontDoor"
if devID = 107 then set devName to "DenWindow"
if devID = 108 then set devName to "LivingRoomWindow1"
if devID = 109 then set devName to "LivingRoomWindow2"
if devID = 110 then set devName to "KitchenWindow"
if devID = 111 then set devName to "BackDoor"
if devID = 112 then set devName to "ROOMBA"


if eventType is sec_SensorNormal_min then set sensStatus to true
if eventType is sec_SensorNormal_max then set sensStatus to true
if eventType is sec_SensorAlert_min then set sensStatus to false
if eventType is sec_SensorAlert_max then set sensStatus to false

-- Put the status in a variable for each device

setVariable(devName, sensStatus)

-- Put the status in a variable for last change for global status

setVariable("SecurityStatus", sensStatus)

end receive security event
end using terms from

-- [END] Receive Security Event <--


Fri Feb 23, 2007 12:11 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11698
Location: Texas
Post Re: Global status variable for all DS10A Window Sensors
Thanks for sharing your script.

For the desired behavior you described of the variable "SecurityStatus" you will need to loop through all of the variables ("SlidingDoor", "BedroomWindow1", etc.) to see if they are all set to false (or all set to true). I believe that will be the only way to get the logic you want, unless you add a method internal to the script that keeps track of all the states. The former technique will be a bit slower, but easier to implement. Based on the number of devices you have, speed shouldn't be a problem.

Regards,
Matt


Fri Feb 23, 2007 8:49 am
Profile WWW

Joined: Aug 22, 2006
Posts: 5
Location: Texas
Post Re: Global status variable for all DS10A Window Sensors
kalan wrote:...
Maybe someone could help me fix the end of this script to set a global variable (called "SecurityStatus") to true or false based on the status of all 12 DS10As. If any one of them is open (false state) then SecurityStatus will be false. Alternatively SecurityStatus can only be true if all DS10A states are true. As it's currently written, an open window would set the global variable SecruityStatus to false but closing one would set it to true even though there may still be an open window somewhere else. I have to fix this loophole in the logic.

...


If your variables are defined as booleans, could you not just AND them all together? If they are all 'true', the result would be 'true'. If one was 'false', the result would be 'false'.

Or if you put all your variables in a list, then maybe something like:

>> set varList to {SlidingDoor, SlidingDoor, BedRoomWindow1, BedRoomWindow2, BedRoomWindow3, BathWindow, FrontDoor, DenWindow, LivingRoomWindow1, LivingRoomWindow2, KitchenWindow, BackDoor, ROOMBA}

>> set SecurityStatus to not (varList contains {false})

Richard


Sat Feb 24, 2007 12:28 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.