I am a beginner and spend quite some time looking for an answer in the forum… but was not successful yet.
I want to display the remaining time of a timer I created within Blocky rule on one of my openHAB Pages. E.g. I have started a 15min timer and want to see how much time is left while the timer is running.
I think I have to “connect” the Blocky timer with a dedicated “Time remaining” item I have created. But I am not yet successful doing this.
Can someone please describe how to link a Blocky rule timer with a “remaining timer” item that can be displayed on a page?
Thanks so much for any hint or link,
A hack might be to update a DateTime Item when the timer is started, and then perform maths in a separate rule to determine the remaining time. But the UI display updates on Item state changes, so this rule would have to run very frequently.
The core timer object has getExecutionTime which can be used to calculate the remaining time.
nice, a jruby example would be much appreciated
Of course, you generally know the target execution time when you start the timer anyway, but that would have uses if you were managing a whole bunch of timers, say.
You are on the right track. To display pretty much anything on the UI you need to use an Item.
Show what you’ve done so far and maybe we can more efficiently point you in the right direction.
In general you’ll need to implement something like Design Pattern : Expire Binding based Countdown timer which is using Expire but the over all approach would be the same.
- Update the time remaining Item with the amount of time on the timer.
- Create a timer that expires in a second.
- Inside the timer, subtract one second from the time remaining Item and update the Item
4a. If the time is up update the Item to 0 and do the work of the timer.
4b. if the time isn’t up, reschedule the timer for another second.