Countdown timer plugin (UI5)

It’s a UI5 bug in the JavaScript for the scene editor. I reported it to MCV. For what it’s worth, it’s only a presentation bug, and the action is still there (as you can check by going to the scene Advanced tab).

Ok thanks for explaining.
it is indeed only visualisation, the plugin works normal.

Every time I select TIMER STARTS WHILE NOT MUTED, I save, then go back and it’s showing “TIMER RESTARTS WHILE NOT MUTED”. It’s like I cannot save the correct action… frustrating, UI5 Bug? Browser?

EDIT: I’ve tried multiple browsers, Clearing Cache etc… I cannot save the trigger as “Timer starts and not muted” which is the first choice on the drop-down. Every time I save or tab after typing the trigger name it’s defaulted back tot he RESTART option… Is this a bug with the Plugin?

Plugin bug, of the embarrassing copy-and-paste kind. I’m very sorry, totally my fault.

I’ve submitted version 3.0 of the plugin which should fix this. You may have to delete the scene with the trigger and re-create it (maybe not). You also will need to flush your browser’s cache.

Anyone who has used the TIMER RESTARTS WHILE NOT MUTED events will likewise have to edit their scene for the event to pick up its new ID.

Thanks for spotting this bug.

Edit: 4.0 fixes another such error which I just found.

I’m trying to get the plugin working, but having problems setting the timer to start, restart, etc in a scene. It just does not save?? I can get mute or un-mute but none of the other actions. :-[ Just updated firmware today to 1.5.36 - using the veralite to fix other issues. Then added the timer plugin. The timer works if not in a scene. Any ideas what might be wrong. I’m following your Turn off the light after 10 Min.

Ted

I can tell I’m still learning. Not sure what was wrong, but each time I tried to set the timer to start it added to the advanced tab. Something must have be wrong with my first one… Anyway, it is working great now after I cleaned out all of the triggers in the advanced tab.

First of all futzle, thanks! This is great!

I had some scenes that were automatically turning lights off after I would turn them on, but without a doubt, I would get caught in a dark room when I went back in between on and auto off. This solved that!

I do have two questions:

  1. When I hit “Set duration” do I need to explicitly hit “Reload” or “Save?” I don’t get prompted to save, and I haven’t tried a power cycle to see what happens.

  2. Is it possible to have the duration either on the device box (near the countdown?), or possibly on the control tab? I know I can find it on the “Advanced” tab, so it’s not a huge deal if not.

You should press SAVE after editing the duration. Edit: Perhaps this isn’t necessary after all, after further thought.

The real estate on the dashboard is a bit limited. Would it be good enough for it to show the duration in the place of the remaining time, when the timer isn’t counting?

Edit: definitely I can pop the current duration on the Control tab.

[quote=“futzle, post:28, topic:170481”]You should press SAVE after editing the duration.

The real estate on the dashboard is a bit limited. Would it be good enough for it to show the duration in the place of the remaining time, when the timer isn’t counting?[/quote]
I figured I needed to press save, but the icon isn’t changing for me. For everything else (like the name of the time), the moment I change something, the blue “RELOAD” changes to a red “SAVE” but not when I change the duration. So I’m hitting “RELOAD” which I think is working ok.

I think showing the duration in place of the remaining time when not active/counting is a great idea.

This may be the wrong forum or it may be my inexperience with ZWave., but . . . I have downloaded the plug-in and used it before in several areas. But how do I make a copy of the plug in for use in different scenes?

You’ll need to create a new device.

UI5 → Apps tab → Click “Countdown timer” → Create another

I wish I knew this plugin existed earlier, i’ve just deleted a load of scenes and replaced them with this.

I have just stumbled upon this as think I have a usecase for my “find the bathroom” scene but I definatey need to address it using luup.

I notice once i trigger a time the variables are not updated in the advanced tab? is this a GUI issue and those variables would actually give me the values if I was to figure out the luup code to check the variable.

on this note do you have any luup fragments to help get me started?
basically start countdown, poll status, remaining time, reset and start counting again etc?

Ta
Stu

trouty00,

The Advanced Tab doesn’t update in real time in UI4 or UI5, but it’s purely visual: behind the scenes the values are updating.

I haven’t needed to use Luup on Countdown Timer devices—it would be a design failure of sorts—but here are some snippets of Luup that should work.

local deviceId = 123 -- change this

-- String "0" (not counting down) or "1" (counting down).
isCounting = luup.variable_get("urn:futzle-com:serviceId:CountdownTimer1", "Counting", deviceId)

-- time() when the timer will ding. Valid only while counting.
if (isCounting == "1") then dueTimestamp = tonumber(luup.variable_get("urn:futzle-com:serviceId:CountdownTimer1", "DueTimestamp", deviceId)) end

I don’t recommend using variable_set() on any of these variables. Any timer-setting should be done through a full-fledged action.

-- Actions are: StartTimer, RestartTimer, CancelTimer, ForceComplete luup.call_action("urn:futzle-com:serviceId:CountdownTimer1", "RestartTimer", {}, deviceId)

Edit: added tonumber() on the DueTimestamp value.

futzle,
appreciate the sentiment regards if this plugin needed luup then it could be considered a failure but as suggested im struggling with my “find the bathroom” scene and this forum can sometimes be slow to respond (people are busy!) and I think i can use this as a work around, I may end up with twice the amount of code required but if that is what it takes then so be it, always a good learning exercise anyway interfacing with other plugins. What you have provided will certainly get me started!!

just to clarify dueTimestamp will then contain the number of how many seconds which are remaining which I can then place conditions on

-- time() when the timer will ding. Valid only while counting. if (isCounting == "1") then [b]dueTimestamp[/b] = luup.variable_get("urn:futzle-com:serviceId:CountdownTimer1", "DueTimestamp", deviceId) end

The “dueTimestamp” variable isn’t the number of remaining seconds, but the Unix-epoch time that the timer will hit zero at. You can subtract os.time() from this to get the number of seconds left. It was done this way to avoid clock skew. Also note the additional tonumber() that I added to the code sample today.

(There is a “Remaining” variable on the plugin which is ostensibly the number of seconds remaining, but it’s a derived value and there are some pathological edge cases where it will be wrong.)

futzle, thanks for that, have finally just got my scene working and have posted the code here.

Great plugin. How about the addition of a random amount of extra seconds to the initial duration? In that way you can trigger several countdown timers after each other and schedule lights like your at home during a holiday.

Thanks

Yes, I can see how that would be useful. I’ll have to mull it over to think of the best way to implement it invisibly for the majority of uses where randomness would just be additional clutter. It’s hard enough for beginners to use this plugin already.

Anyone who wants this: please help by describing specific real-world use cases. There are still unanswered questions like what random number distribution is most useful (uniform, binomial, exponential), and whether this is better done as part of the countdown timer plugin or as a separate plugin.

If you were to implement random times, I would leave the majority of the plugin unchanged. Could you then add new variable that only appear in the advanced tab, and have something like “Random Delta?” This “random delta” (if non-zero) would be added to the “duration” already established?

This way, the “duration” is essentially the minimum countdown time, but if and only if, random delta is non-zero, you would calculate a random number between 0 and “random delta” and add that to the “duration” to get “actual duration.”

That makes is transparent to new users, but flexible for advanced users.

As for the type, whatever Lua provides internally would be fine. I assume it’s a uniform distribution, but hey, what do I know? ;D