Security Script for W800RF32 & Indigo

Here’s a revision of the Indigo security script sample, that adds GROWL support, X10 Chime support, and the data is stored in a array/matrix.

Please be Kind… This is the first major Applescript that I have done… So any suggestions on improving it, are welcome…

The key to customizing this script, is as follows:

1) Use_Growl, if true, Growl notifications will be broadcast for any Opened / Closed events. If False, no Growl notifications will be sent.

2) The X10 Chime support is activated on a Alarm by Alarm Basis… (See Alarm_Matrix)

3) The Chime can be set to only be activated on a OPEN status change
4) The Chime can be set to not activate until xx minutes have past since the last chime.
(For example, I trigger the chime by opening the door to take the trash out… I don’t
want the chime to go off again until 3 minutes later… That way when I come back in
the chime won’t go off… The Growl notifications & log entries are still created,
the chime just doesn’t go off..)

5) The Alarm’s to monitor are stored in a array…
The array stores the Alarm ID, the English name that you want to use in the
log & growl notifications (NO SPACES IN THE English name!). The Growl notification
flag for each sensor, the chime flag for each sensor, and the Indigo label for the chime module.

– 1 - Device ID
– 2 - English Name,
– 3 - Growl flag
– 4 - Chime flag
– 5 - Indigo Chime Device ID (Label)

Example:

property Alarm_Matrix : {¬
{9, “Test_Sensor”, true, true, “G01 = Remote Chime”}, ¬
}

- Benjamin

Here’s the code ZIPPED…new security sample 2.scpt.zip

And in plain text…

-- 153 is Kitchen Door
--  45 is Garage Door
-- 217 is Dinning Room
property Use_Growl : true
property Growl_Notifications_List : {"Opened", "Closed"}
property Growl_Enabled_Notifications : {"Opened"}

property Chime_Only_On_Open : true
property Chime_Min_delay : 3
-- 1 - Device ID
-- 2 - English Name,
--  3 - Growl Enabled
--  4 - Chime
--  5 - Chime Device ID (Label)

property Alarm_Matrix : {¬
	{9, "Test_Sensor", true, true, "G01 = Remote Chime"}, ¬
	{153, "Kitchen_Door", true, true, "G01 = Remote Chime"}, ¬
	{45, "Garage_Door", true, true, "G01 = Remote Chime"}, ¬
	{217, "Dining_Room", true, true, "G01 = Remote Chime"} ¬
		}

-- Send Growl Notification
on Send_to_Growl(door, action)
	tell application "GrowlHelperApp"
		-- Make a list of all the notification types
		-- that this script will ever send:
		set the allNotificationsList to Growl_Notifications_List
		set the enabledNotificationsList to Growl_Enabled_Notifications

		register as application ¬
			"Indigo Security" all notifications allNotificationsList ¬
			default notifications enabledNotificationsList ¬
			icon of application "Script Editor"

		notify with name ¬
			action title ¬
			door & " " & action description ¬
			door & " " & action application name "Indigo Security"
	end tell
end Send_to_Growl

using terms from application "IndigoServer"
	on Set_Variable(variable_name, variable_value)
		if not (variable (variable_name) exists) then
			make new variable with properties {name:variable_name, value:variable_value}
		else
			set value of (variable (variable_name)) to variable_value
		end if
	end Set_Variable
end using terms from

using terms from application "IndigoServer"
	on decode_security(eventType, device_ID)
		set door to ""
		set action to ""
		set alarm_detected to false
		set growling to false
		set chiming to false
		set chime_device to ""

		repeat with alarmdata in Alarm_Matrix
			if device_ID is item 1 in alarmdata then
				set door to item 2 in alarmdata
				if eventType is sec_SensorNormal_min then set action to "Closed"
				if eventType is sec_SensorAlert_min then set action to "Opened"
				set alarm_detected to true
				set growling to item 3 in alarmdata
				set chiming to item 4 in alarmdata
				set chime_device to item 5 in alarmdata
			end if
		end repeat
		return {door, action, alarm_detected, growling, chiming, chime_device}
	end decode_security
end using terms from

using terms from application "IndigoServer"
	on receive security event of eventType with code devID
		--		if eventType is sec_ArmHome_min then log "arm home (min)" using type "Security Sample"
		--		if eventType is sec_ArmHome_max then log "arm home (max)" using type "Security Sample"
		--		if eventType is sec_ArmAway_min then log "arm away (min)" using type "Security Sample"
		--		if eventType is sec_ArmAway_max then log "arm away (max)" using type "Security Sample"
		--		if eventType is sec_Disarm then log "disarm" using type "Security Sample"
		--		if eventType is sec_Panic then log "panic" using type "Security Sample"
		--		if eventType is sec_LightsOn then log "security lights on" using type "Security Sample"
		--		if eventType is sec_LightsOff then log "security lights off" using type "Security Sample"
		--		if eventType is sec_SensorNormal_min then log "sensor normal (min delay)" using type "Security Sample"
		--		if eventType is sec_SensorNormal_max then log "sensor normal (max delay)" using type "Security Sample"
		--		if eventType is sec_SensorAlert_min then log "sensor alert (min delay)" using type "Security Sample"
		--		if eventType is sec_SensorAlert_max then log "sensor alert (max delay)" using type "Security Sample"

		set alarm_detected to false

		set decoded_data to decode_security(eventType, devID)
		-- door, action, alarm_detected

		set chime_device to item 6 of decoded_data
		set chime_enabled to item 5 of decoded_data
		set growl_enabled to item 4 of decoded_data
		set alarm_detected to item 3 of decoded_data
		set action to item 2 of decoded_data
		set door to item 1 of decoded_data
		if alarm_detected is false then
			-- Unknown Security Device
			log "(device ID " & devID & ")" using type "Security Sample"
		else if alarm_detected is true then
			log (time string of (current date) as string) & " " & door & " " & action
			if action is "Opened" then beep

			-- Send Growl Notification
			if Use_Growl then
				if growl_enabled then Send_to_Growl(door, action)
			end if

			if chime_enabled then
				set last_chimed_ms to value of variable "Chime_Last_Sounded_ms"
				if (time of (current date) ≥ last_chimed_ms + (Chime_Min_delay * 60)) then
					if Chime_Only_On_Open is false then
						turn on chime_device for 1
						Set_Variable(("Chime_Last_Sounded_ms"), time of (current date) as string)
						Set_Variable(("Chime_Last_Sounded_ms"), time string of (current date) as string)

					else
						if action is "Opened" then
							Set_Variable(("Chime_Last_Sounded_ms"), time of (current date) as string)
							Set_Variable(("Chime_Last_Sounded"), time string of (current date) as string)
							turn on chime_device for 1
						end if
					end if
				end if
			end if

			Set_Variable((door & "_last_update"), time string of (current date) as string)
			Set_Variable((door & "_last_status") as string, action as string)

			--log value of variable "SoundChime" as string

		end if
		--log "(device ID " & devID & ")" using type "Security Sample"

	end receive security event
end using terms from

Leave a Reply

You must be logged in to post a comment.