Last active
August 4, 2016 19:50
-
-
Save primeinc/da658014d50e9a07aff048935decdc4e to your computer and use it in GitHub Desktop.
Blink the lights on a dimmer switch quickly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--> Configuration Variables | |
local Device = 16; local Secs = 1; local count = 0 | |
local targetCount = 4; local targetLoadHigh = 100; local targetLoadLow = 10 | |
--> End Configuration Variables | |
local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", Device); | |
local lightLevel = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", Device); | |
local Call ='urn:upnp-org:serviceId:Dimming1';Do ='SetLoadLevelTarget';Nil ="" | |
local BlinkOn, BlinkOff, restoreLevel | |
if Run == nil then Run = 0 end | |
function BlinkOn(Call) | |
luup.sleep(100) | |
count = count %2B 1 --> %2B is a plus symbol because the vera dev's suck | |
luup.call_action(Call,Do,{newLoadlevelTarget=targetLoadHigh},Device) -->BlinksOnlight on | |
luup.log("count:" .. count .. " run:" .. Run .. " light load @ " .. targetLoadHigh) | |
if (count >= targetCount) then restoreLevel(Call) end | |
if (Run == "1") then BlinkOff(Call) end | |
end | |
function BlinkOff(Call) | |
luup.sleep(100) | |
count = count %2B 1 --> %2B is a plus symbol because the vera dev's suck | |
luup.call_action(Call,Do,{newLoadlevelTarget=targetLoadLow},Device) -->BlinksOff | |
luup.log("count:" .. count .. " run:" .. Run .. " light load @ " .. targetLoadLow) | |
if (count >= targetCount) then restoreLevel(Call) end | |
if (Run == "1") then BlinkOn(Call) end | |
end | |
function restoreLevel(Call) | |
luup.sleep(100) | |
Run = "0" | |
luup.call_action(Call,Do,{newLoadlevelTarget=lightLevel},Device) -->Restore | |
luup.log("count:" .. count .. " run:" .. Run .. " light load restored @ " .. lightLevel) | |
end | |
luup.log("count:" .. count .. " run:" .. Run .. " lightLevel:" .. lightLevel .. " starting") | |
if (switchOnOff == "1") then | |
luup.log("count:" .. count .. " run:" .. Run .. " light on, continuting") | |
if (Run == "1") then Run = "0" --> If run again, while already running stop | |
luup.log("count:" .. count .. " run:" .. Run .. " we're quitting because we're already running") | |
else Run = "1" | |
if(targetLoadHigh >= tonumber(lightLevel)) then BlinkOff(Call) else BlinkOn(Call) end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
original way using
luup.call_timer("BlinkOff",1,Secs,Nil,Nil)
instead of calling the function directly but 1 second seemed far too long