Being a newcomer to Lua scripting I was fortunate to find code in the wiki and these forums that helped a great deal. I created a scene that blinks many of the lights in my house when the siren is turned on. It works, mostly, but the blinking rate of the individual lights varies quite a bit even though I’ve specified 2 sec intervals between on and off. When tripped, the actual intervals seem to vary between ~2 and ~10 secs. Am I asking Vera to do too much?
Also, to tidy things up a bit, I would like to introduce a for loop in this code but am unsure how? Here’s my scene code:
[code]function SwOndinette(stuff)
if (FLASH_ENABLE) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },37)
luup.call_timer(“SwOffdinette”, 1, “2”, “”, “”)
end
end
function SwOffdinette(stuff)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },37)
if (FLASH_ENABLE) then
luup.call_timer(“SwOndinette”, 1, “2”, “”, “”)
end
end
–< 17 more segments that look just like the above except with different devices and room names >
FLASH_ENABLE = true
SwOnBRhall()
–< 17 more lines just like the one above >[/code]
Pretty sure you’re asking zwave to carry too much information in too short a time. zwave isn’t exactly a speedy protocol like wifi; it’s more intended for distance and (eventual) reliability. I think you’re buffering the heck out of your zwave network asking it to turn on/off eighteen devices every second.
If you really have to have that many devices blink that rapidly, I think your best bet would be to screw around with the zwave all on / all off commands. Idea would be to configure all devices that you don’t want to blink to ignore zwave all on/all off commands, then go to town. See http://forum.micasaverde.com/index.php/topic,9034.0.html .
Thinking about this more, I think you’d do well to refactor quite a bit of this. Right now you’re launching 36 individual recurring timers via call_timer. Worse, vera doesn’t guarantee any ordering of events set by call_timer, so basically you have a (possibly changing!) random order of events happening every two seconds:
turn light 1 off!
turn light 5 on!
turn light 5 off!
turn light 3 off!
turn light 4 off!
turn light 2 on!
turn light 4 on!
turn light 6 on!
etc.
I think in this case you’d do much better to take a more hands on approach and use call_delay instead of call_timer. Call_timer is repeating, while call_delay is a one shot.
The pseudocode would look something like this…
function GO_MAKE_ON()
if (flash_enabled)
light one on!
light two on!
light three on!
light four on!
call_delay (GO_MAKE_OFF, 2)
end
end
function GO_MAKE_OFF()
if (flash_enabled)
light one off!
light two off!
light three off!
…you get the idea
call_delay (GO_MAKE_ON, 2)
end
end
Then when you want flashing, you set flash_enabled to true and run GO_MAKE_ON. This will also force all the lights to come on before any go off, for better or for worse. When you want the flashing to end, set flash_enabled to false and it’ll stop blinking within 2 seconds.
Then when you want flashing, you set flash_enabled to true and run GO_MAKE_ON. This will also force all the lights to come on before any go off, for better or for worse. When you want the flashing to end, set flash_enabled to false and it’ll stop blinking within 2 seconds.[/quote]
Very interesting. Thanks for the suggestion. I’ll give that a whirl this weekend.
Finally got around to testing out your idea. The good news - it works. The bad news - it works about as well as my original code. All the lights come on quite quickly when executed but then the lights become haphazard. Some cycle quicker than 2 secs while others stay on much longer than 2 sec. All seem random. Perhaps I am indeed dealing with a limitation of the Vera hardware.
mmmm, that shouldn’t be a possible outcome. Did you nuke your original code and reboot your vera first? Sounds like your original code is still running.
Nope, that wasn’t the problem but I did figure out what was the problem - Aeon. Included in these 19 switches (I added one) were 5 Aeon micro switches. When I removed them from the script leaving only the GE 3way and single poles and a couple of Schlage modules, the script runs almost flawlessly with no haphazard behavior like before. Lights on and off aren’t entirely simultaneous now but close.
So until I get those 5 Aeons replaced I moved them into their own script with a 5 sec interval instead of 2, which seems to help a bit but they still don’t work well as blinkers.
Aeon doesn’t have a very good batting average with me. Had to return the key fob for a refund because it broke (and I didn’t trust the quality) and now this with the switches. The only Aeon product working for me are my minimotes. Grrr…