Repeating Commands in a Scene

I want to code a Scene to Flash and LED on for 1 second and off for 1 second and repeat 10 times.

I’ve read some posts using call.delay and I’m not sure if I need another parameter. Also, is a while loop OK to use in this application? Does this look like a good way to do this? Should I approach it differently. Thx.

local i = 0

while a(i) do

local socket = require(“socket”)
host = “192.168.1.74”
c = assert(socket.connect(host, 4998))
c:send(“set_LED_LIGHTING,1:1,50,5\013”) Turn RED LED ON
c:close()

luup.call_delay(1)

local socket = require(“socket”)
host = “192.168.1.74”
c = assert(socket.connect(host, 4998))
c:send(“set_LED_LIGHTING,1:1,0,5\013”) Turn RED LED Off
c:close()

luup.call_delay(1)

i=i+1

end

you can check this thread.

http://forum.micasaverde.com/index.php/topic,3015.msg48234.html#msg48234

OK, I got my but kicked for a while but I almost have it. The first commands turn off the RGB channels if they were on. Then the flashing program starts and cycles Red On@ 90% and Off. The program terminates fine when the scene is run a second time. However, I want all channels to be at 30% when the program terminates but the red channel overrides to 90%. Any ideas on how to fix this. Can the program be terminated after running the sBlink=0 commands are run?

local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:1,0,0\013”) – Turn Off Red
c:close()

local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:2,0,0\013”) – Turn Off Green
c:close()

local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:3,0,0\013”) – Turn Off Blue
c:close()

function LowAlcoholOn(stuff)
local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:1,90,0\013”) – Turn Red On 90%
c:close()
if (sBlink == “1”) then
luup.call_timer(“LowAlcoholOff”,1,“1”, “”, “”)
end
end
function LowAlcoholOff(stuff)
local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:1,0,0\013”) – Turn Off Red
c:close()
if (sBlink == “1”) then
luup.call_timer(“LowAlcoholOn”,1,“1”, “”, “”)
end
end
if (sBlink == “1”) then
sBlink = “0”
local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:1,30,0\013”) – Turn On Red 30%
c:close()
local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:2,30,0\013”) – Turn On Green 30%
c:close()
local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:3,30,0\013”) – Turn On Blue 30%
c:close()
else
sBlink = “1”
luup.call_timer(“LowAlcoholOff”,1,“1”, “”, “”)
end

I got it I added an else with code (bold) and it works great.

local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:1,0,0\013”) – Turn Off Red
c:close()

local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:2,0,0\013”) – Turn Off Green
c:close()

local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:3,0,0\013”) – Turn Off Blue
c:close()

function LowAlcoholOn(stuff)
local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:1,90,0\013”) – Turn Off On
c:close()
if (sBlink == “1”) then
luup.call_timer(“LowAlcoholOff”,1,“1”, “”, “”)
else
local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:1,30,0\013”) – Turn On Red
c:close()
end

end
function LowAlcoholOff(stuff)
local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:1,0,0\013”) – Turn Off Red
c:close()
if (sBlink == “1”) then
luup.call_timer(“LowAlcoholOn”,1,“1”, “”, “”)
end
end
if (sBlink == “1”) then
sBlink = “0”
local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:2,30,0\013”) – Turn On Green
c:close()
local socket = require(“socket”)
host = “192.168.1.74” – Set Device
c = assert(socket.connect(host, 4998)) – Set Port
c:send(“set_LED_LIGHTING,1:3,30,0\013”) – Turn On Blue
c:close()
else
sBlink = “1”
luup.call_timer(“LowAlcoholOff”,1,“1”, “”, “”)
end