Flashing Lights When Alarm Sounds

Hi All,

I’m a bit new to this so I’m probably missing something simple. I snagged mysticjay’s code from http://forum.micasaverde.com/index.php/topic,5127.0.html and used it as part of my scene. The scene works as follows:

Step #1) Device Trigger Alarm State: Alarm is active
Step #2) (Nothing)
Step #3) Run the following code:

[code]–Enter the device ID’s here in the array with your device id’s
local array_lights = {72,74}
local original_status={}
local counter = 10
local delay = 3

function set_switch(device,value)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=value },device)
end

function tree_on()
for i, device in ipairs(array_lights) do
set_switch(device,“1”)
end
luup.call_delay( ‘tree_off’, delay )
end

function tree_off()
counter = counter-1

if (luup.variable_get("urn:schemas-micasaverde-com:device:AlarmPartition:2","Alarm", 42) == None) then	

	--Set to original status
	for i, device in ipairs(array_lights) do
			set_switch(device,original_status[i])
	end

elseif counter > 0 then
	
	for i, device in ipairs(array_lights) do
			set_switch(device,"0")
	end
	luup.call_delay( 'tree_on', delay )

else

	--Set to original status
	for i, device in ipairs(array_lights) do
			set_switch(device,original_status[i])
	end

end

end

–Save Original status
for i, device in ipairs(array_lights) do
original_status[i] = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”, device)
end

tree_off()[/code]

I changed the code a bit so that when function tree_off is firing it is checking the alarm state first and if it sees that the alarm is turned off (“None” value?) then it changes the lights back to their original state and stops the flashing.

My goal is to flash the lights if the alarm sounds and return the lights to their previous state when the alarm stops. The code, I wrote, unfortunately doesn’t seem to be working and I could use some help debugging it. Am checking the wrong service?

Thanks in advance.

Replying to my own post to simply my question. Is the following code how I test to see if my alarm currently tripped?

if (luup.variable_get("urn:schemas-micasaverde-com:device:AlarmPartition:2","Alarm", 42) == Active) then

And is this how I test to see if it is currently not tripped?

if (luup.variable_get("urn:schemas-micasaverde-com:device:AlarmPartition:2","Alarm", 42) == None) then

They don’t seem to be working and it didn’t seem to matter whether I put quotes around the “Active” and “None”. Any ideas?

Thanks!

Figured it out. The code below will flash the lights when an the alarm sounds (use “Device Trigger Alarm State: Alarm is active” built into Vera to start the code when the alarm sounds) and return the lights to their original state when the alarm is stopped.

[code]–Enter the device ID’s here in the array with your device id’s
local array_lights = {deviceID1, deviceID2}
local original_status={}
local counter = 10
– set the counter value higher since you’ll probably want the light to flash for a while if the alarm is triggered
local delay = 3

function set_switch(device,value)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=value },device)
end

function tree_on()
for i, device in ipairs(array_lights) do
set_switch(device,“1”)
end
luup.call_delay( ‘tree_off’, delay )
end

function tree_off()
counter = counter-1

if (luup.variable_get("urn:micasaverde-com:serviceId:AlarmPartition2", "Alarm", deviceID) == "None") then

	--Set to original status
	for i, device in ipairs(array_lights) do
			set_switch(device,original_status[i])
	end

elseif counter > 0 then
	
	for i, device in ipairs(array_lights) do
			set_switch(device,"0")
	end
	luup.call_delay( 'tree_on', delay )

else

	--Set to original status
	for i, device in ipairs(array_lights) do
			set_switch(device,original_status[i])
	end

end

end

–Save Original status
for i, device in ipairs(array_lights) do
original_status[i] = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”, device)
end

tree_off()[/code]

This was very helpful for me when added to water sensors to quickly identify which one was set off.
Thanks!

I would love to do this however there isn’t a device trigger “Device Trigger Alarm State: Alarm is active” available when I create a scene. How do you get it to show up?