There was a thread back in the old forums that discussed this, but to save everyone the formatting that didn’t make it over (and thus makes unusable code), in scene Lua:
device = 8 -- device number to blink
count = 10 -- number of times to blink
rate = 2 -- number of seconds between blinks
function blink_on()
luup.call_action( "urn:upnp-org:serviceId:SwitchPower1", "SetTarget", { newTargetValue="1" }, device )
luup.call_delay( 'blink_off', rate )
end
function blink_off()
luup.call_action( "urn:upnp-org:serviceId:SwitchPower1", "SetTarget", { newTargetValue="0" }, device )
count = count - 1
if count > 0 then
luup.call_delay( 'blink_on', rate )
end
end
-- Start blinking
blink_on()
Keep in mind that the blink rate has two limiting factors:
The delay is an integer;
Luup’s ZWave implementation probably can’t reliably handle it any faster than #1 allows anyway.
I’m trying to blink a Philips Hue bulb in a lamp, I’m using the AltHue plugin.
I had to change the URN to SwitchPower1 as BinaryLight1 didn’t seem to work.
This code does blink the lamp on and off but I don’t think the count is working fully it doesn’t blink 10 times. The lamp goes on and off about 4 times. The rate is much slower than 2 seconds also.
But its good enough for what I need.
Patrick do you think it would be possible to take in to account the starting status of the lamp if it was on or off to begin with? And after the blink code return that lamp to its prior on or off status?
With the code as is, if the lamp was already ON to begin with after the blinking the lamp then remains OFF.
If the lamp was OFF to begin with after the blinking it is still OFF.
Or is it just chance on how many blinks you have set and what the starting state of the lamp was.
device = 379 -- device number to blink
count = 10 -- number of times to blink
rate = 2 -- number of seconds between blinks
function blink_on()
luup.call_action( "urn:upnp-org:serviceId:SwitchPower1", "SetTarget", { newTargetValue="1" }, device )
luup.call_delay( 'blink_off', rate )
end
function blink_off()
luup.call_action( "urn:upnp-org:serviceId:SwitchPower1", "SetTarget", { newTargetValue="0" }, device )
count = count - 1
if count > 0 then
luup.call_delay( 'blink_on', rate )
end
end
-- Start blinking
blink_on()
My bad! Your change is correct, and I changed mine as well to avoid confusion.
Yeah, although the easiest way to do that would be to use the ToggleState action (in service urn:micasaverde-com:serviceId:HaDevice1, although that isn’t always supported by all devices, apparently (e.g. the Fibaro device referred to elsewhere today… always Fibaro. What the heck?).
If ToggleState works, you only need one function; just blink an even number of times and you’ll end up back where you started…
device = 379 -- device number to blink
count = 10 -- number of times to blink
rate = 2 -- number of seconds between blinks
function blink()
luup.call_action( "urn:micasaverde-com:serviceId:HaDevice1", "ToggleState", {}, device )
count = count - 1
if count > 0 then
luup.call_delay( 'blink', rate )
end
end
-- Start blinking
blink()
OK thanks, I will try the new code on some other lights tomorrow, that might be useful for the doorbell scene, to have some lights blink but go back to their original state afterwards.
That’s what I was using the Hue blink for on IFTTT with my doorbell scene but it stopped working.
I have all Fibaro Dimmer 2’s for my ceiling lights, they support ToggleState OK.
Certain versions of the Fibaro Roller Shutter module don’t work with ToggleState however. I have one Roller Shutter that works with ToggleState and another Roller Shutter that does not.
For others reading this thread, for devices that don’t support ToggleState like the just mentioned Fibaro Roller Shutter module, I have used this LUA code for a toggle:
local device=75
local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", device)
if (switchOnOff == "1") then
-- Switch is on
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "0"}, device)
else
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "100"}, device)
end
I think I also had to use similar code for my Philips Hue bulbs in the side lamps to have a toggle scene for them.
I mainly use toggle scenes so you can use just one button on a scene controller device such as my Aeotec Minimotes.
The variables can be local, but the function cannot. The way that luup.delay() works, you pass it a function name, and it can only look for that function in global scope. This was a poor implementation choice on their part, and something they could probably easily fix without breaking any existing code, but it hasn’t happened. Ideally, anything that uses a callback would take a function reference, which would allow you to use a global or local function, or even a closure (like an anonymous function in other languages).
Yep, AltHue is not very fast to detect changes. Since it’s polling, it will detect the off after some time.
I have a scene controller in my office for some hue lights and I fail to turn one off, I have to wait a couple of seconds to turn it on again (I’m using toggle estate). So, definitely reproducible on my part too.
local device=75
local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", device)
local on_off = (switchOnOff == "1") and "0" or "100"
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = on_off}, device)
function light_Toggle(data)
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = string.sub(data,1,1)}, string.sub(data,2))
end
local blinks = 2
local device = 10008
local rate = 1
local swStatus = '0'
local onOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", device)
for i = 1,(blinks*2),1 do
if (i + tonumber(onOff)) % 2 == 0 then swStatus = '0' else swStatus ='1' end
luup.call_delay('light_Toggle', ((i-1)*rate), (swStatus .. tostring(device)))
--print(i*rate, swStatus)
end
return true
Best Home Automation shopping experience. Shop at Ezlo!