Making a light blink....help

Goal…

I have a garage tilt switch. Once the garage opens, I’d like my light to blink for a period of 10 seconds, then turn off/on depending on it’s last state.

I stumbled across this code which does the blinking perfectly, but I am clueless how to do the rest. This code simply runs indefinitely until the scene is run again. I don’t comprehend how to make a scene run twice, is it simple as that? I’m a novice with scenes and code so please walk me through this. Thanks

------ SET THESE TWO VARIABLES to match needs of your system -----
Secs = 2 ---->> Secs: Number of seconds between “Blinks”
Device = 6 ---->> Device: Device# of Outlet or Light to “BLINK”

Call =‘urn:upnp-org:serviceId:SwitchPower1’;Do =‘SetTarget’;Nil =“”
function BlinkOn()
luup.call_action(Call,Do,{newTargetValue=1},Device) -->BlinksOn
if (Run == “1”) then luup.call_timer(“BlinkOff”,1,Secs,Nil,Nil) end
end
function BlinkOff()
luup.call_action(Call,Do,{newTargetValue=0},Device) -->BlinksOff
if (Run == “1”) then luup.call_timer(“BlinkOn”,1,Secs,Nil,Nil) end
end
if (Run == “1”) then Run = “0” → NewClick while running=Stop,i.e.Run=0
else Run = “1” luup.call_timer(“BlinkOff”,1,Secs,Nil,Nil) -->Else go on
end

I stumbled across this from another thread, should do what I am looking for.

Will test out this evening:

[quote=“biggsworld, post:26, topic:167189”]I wanted to update this thread since there didn’t seem to be any others that met my specific criteria - you can certainly use this for alarms or any purpose you need.
In my case I installed a door sensor in my mailbox so it would tell me when the mail had arrived. (I know - but it’s fun to tinker with!) My specific needs were to blink a light and then return that light to it’s original setting - this is for notification only.

I cleaned up the code a little from the early posts and made it a little easier to follow. I re-edited since I found a minor bug - If you have too many lights to blink, it fails because the previous z-wave command hasn’t completed before the next gets sent. I added a delay (adjustable - set to 1 second now) to wait between sending zwave commands. That seems to work much better in a busy zwave network.

Here’s my updated code for your use.

[CODE]
–Enter the device ID’s here in the array with your device id’s
– 4 - Stair lights
– 19 - kitchen pendant
– 60 - bedroom lamp
– 69 - LR lamp 3
local array_lights = {4,19,60,60}
local original_status={}
– loopspeed is the timeout between sending commands
local loopspeedms = 1000

– counter is the number of times to blink
local counter = 5

– delay is the number of seconds to wait between switching off-> on, and on->off
local delay = 1

– sleep() takes milliseconds not seconds - so we do the math here
local delayms = delay * 1000

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

– Turn all the switches in the array ON
function switch_on()
for i, device in ipairs(array_lights) do
set_switch(device,“1”)
luup.sleep(loopspeedms)
end
– Run a delay and then call switch_Off which turns them all back off.
– luup.call_delay( ‘switch_off’, delay )
end

– Turn off all the switches in the array
– This is only a stub - does not call switch_on
function switch_off()
for i, device in ipairs(array_lights) do
set_switch(device,“0”)
luup.sleep(loopspeedms)
end

end

– Main program
– Loop over the array “counter” times, with “delay” between loops.
function switch_run()

while counter > 0 do
	counter = counter-1
	switch_on()
	luup.sleep(delayms)
	switch_off()
	luup.sleep(delayms)

end



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

end

end


– Program run starts here


–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

switch_run()

[/CODE][/quote]

Your SWITCH_RUN will likely reload your system with an over run if anything else tries to run:

Your SHOULD NEVER call LUUP.SLEEP in a Loop and you should never call it with an argument more than 1000 (ms)

I use this code to blink 5 of my lights in a scene. Run the scene again and the lights will stop.

function DipOnPorchLight(stuff)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },124)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },130)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },302)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },144)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },146)
if (sBlink == “1”) then
luup.call_timer(“DipOffPorchLight”, 1, “3”, “”, “”)
end
end
function DipOffPorchLight(stuff)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },124)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },130)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },302)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },144)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },146)
if (sBlink == “1”) then
luup.call_timer(“DipOnPorchLight”, 1, “3”, “”, “”)
end
end
if (sBlink == “1”) then
sBlink = “0”
else
sBlink = “1”
luup.call_timer(“DipOffPorchLight”, 1, “3”, “”, “”)
end

Good job … You could even put a loop counter to flash multiple times.
Use of luup.call_timer or luup.call_delay is the correct solution to make an event driven routine.

[quote=“bucko, post:4, topic:198284”]I use this code to blink 5 of my lights in a scene. Run the scene again and the lights will stop.

function DipOnPorchLight(stuff)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },124)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },130)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },302)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },144)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },146)
if (sBlink == “1”) then
luup.call_timer(“DipOffPorchLight”, 1, “3”, “”, “”)
end
end
function DipOffPorchLight(stuff)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },124)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },130)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },302)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },144)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },146)
if (sBlink == “1”) then
luup.call_timer(“DipOnPorchLight”, 1, “3”, “”, “”)
end
end
if (sBlink == “1”) then
sBlink = “0”
else
sBlink = “1”
luup.call_timer(“DipOffPorchLight”, 1, “3”, “”, “”)
end[/quote]

Thanks but how do I run a scene again? That is what I am struggling with. I am noob to this stuff so please talk in “non-code” to me :wink:

[quote=“fmzip, post:6, topic:198284”][quote=“bucko, post:4, topic:198284”]I use this code to blink 5 of my lights in a scene. Run the scene again and the lights will stop.

function DipOnPorchLight(stuff)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },124)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },130)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },302)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },144)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },146)
if (sBlink == “1”) then
luup.call_timer(“DipOffPorchLight”, 1, “3”, “”, “”)
end
end
function DipOffPorchLight(stuff)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },124)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },130)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },302)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },144)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },146)
if (sBlink == “1”) then
luup.call_timer(“DipOnPorchLight”, 1, “3”, “”, “”)
end
end
if (sBlink == “1”) then
sBlink = “0”
else
sBlink = “1”
luup.call_timer(“DipOffPorchLight”, 1, “3”, “”, “”)
end[/quote]

Thanks but how do I run a scene again? That is what I am struggling with. I am noob to this stuff so please talk in “non-code” to me ;)[/quote]

I use PLEG to run my scenes. You can fire a scene, add a delay, and fire it again.

[quote=“bucko, post:7, topic:198284”][quote=“fmzip, post:6, topic:198284”][quote=“bucko, post:4, topic:198284”]I use this code to blink 5 of my lights in a scene. Run the scene again and the lights will stop.

function DipOnPorchLight(stuff)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },124)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },130)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },302)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },144)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },146)
if (sBlink == “1”) then
luup.call_timer(“DipOffPorchLight”, 1, “3”, “”, “”)
end
end
function DipOffPorchLight(stuff)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },124)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },130)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },302)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },144)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },146)
if (sBlink == “1”) then
luup.call_timer(“DipOnPorchLight”, 1, “3”, “”, “”)
end
end
if (sBlink == “1”) then
sBlink = “0”
else
sBlink = “1”
luup.call_timer(“DipOffPorchLight”, 1, “3”, “”, “”)
end[/quote]

Thanks but how do I run a scene again? That is what I am struggling with. I am noob to this stuff so please talk in “non-code” to me ;)[/quote]

I use PLEG to run my scenes. You can fire a scene, add a delay, and fire it again.[/quote]

I read this and I have no idea what PLEG is lol :slight_smile: I installed it but again, this is greek to me

https://www.automatiserar.se/wp-content/uploads/2015/03/PLEG-Basics.pdf

So if I create a scene, do I first choose PLEG as the device? Then it asks to select either
A Condition is satisfied
A Condition is satisfied with specified status

Stuck on step one if indeed this is step one

The scene you create is the lua code I listed. The scene is set to manually trigger. No scheds or triggers added. Just the lua code with your device id’s (instead of mine). I named my scene Blinking Lights (how creative!).

Then install the PLEG plugin. Form PLEG you fire the scene you just made based on the conditions and actions you create in PLEG. PLEG will take care of everything for you. PLEG should be in everyone’s VERA. It does all the heavy lifting that Vera itself just can’t handle.

You will find life with Vera so much better using PLEG.

[quote=“bucko, post:9, topic:198284”]The scene you create is the lua code I listed. The scene is set to manually trigger. No scheds or triggers added. Just the lua code with your device id’s (instead of mine). I named my scene Blinking Lights (how creative!).

Then install the PLEG plugin. Form PLEG you fire the scene you just made based on the conditions and actions you create in PLEG. PLEG will take care of everything for you. PLEG should be in everyone’s VERA. It does all the heavy lifting that Vera itself just can’t handle.

You will find life with Vera so much better using PLEG.[/quote]

Thanks but when I first use PLEG, the first thing it asks is to select either:

A Condition is satisfied
A Condition is satisfied with specified status

Trying to get a user guide for the latest version of PLEG but this is all I find

forum.micasaverde.com/index.php?action=dlattach;topic=21603.0;attach=22081

That is the key document. Play with PLEG and you will get the hang of it.

I have one issue. I am not a programmer. WIth all you people writing code wouldn’t Vera by now see a need and write a scene option. I simply want to be able to flash a light on and off every second or two for 15 seconds when my garage dooe is opened. My wfe is disabled so it will give her time to prepair herself in the event soneone comes in the door.