Without the logs there’s nothing to tell you that an upgrade is required. I make all my rule templates and this block library test to see if the version of the library is recent enough and generate a meaningful error in the log. Otherwise it would throw some random exception.
I also put the minimum version in the dependencies section of the original post, but there is no section in the template for block libraries.
Hi,
I am trying the new Countdown Timer but i am facing this error.
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘4cf9f4f077’ failed: org.graalvm.polyglot.PolyglotException: TypeError: (intermediate value).private.get(…).isActive is not a function.
The OHRT timers do not support (yet) all the capabilities of a generic OH timer. CountdownTimer does not have an isActive() method. It has the hasTerminated() but that’s it. It’s a todo to add the rest but for for now you can’t use “is active” with OHRT timers.
What is it you want, because I have little time and cannot guarantee when I’ll add the rest of the functions. It could be months. And you should be able to do exactly what you are after with just the exists and hasTerminated blocks.
But the first thing to note is that your code as written doesn’t make sense. When the if statement runs the timer will always be active so it will always be canceled.
Looking at the code this generates, it turns out that the “has terminated” block already tests whether the timer exists in the cache for you so we don’t need to do that separately.
The above example was just to demonstrate that it gives an error.
I just want to avoid that the item that hold the count timer to run multiply times.
if item x=ON run a count timer but if x=ON again must stop the timer and not creating another timer. because the item that hold the coun timer showing 2 or 3 different count timers
Hope that i have explain it good for you.
Then do the if statement before creating the timer.
if not [private] timer "test1" has terminated
do
log info "cancel timer"
cancel [private] timer "test1"
else
after [10] [seconds] with [private] "test1" using countdown item [item Testnumber]
log [info] "Do something"
If the timer already exists and it hasn’t run, it will be cancelled. Only if there is no timer or the last timer was cancelled or ran to completion will it create a new timer.
if you run this blockly 2 or 3 times and observe the item you will see that the item counting 2 or 3 different timers so the “has terminated” block doesn’t work or i understand it wrong??
You still need an if statement to test for “not has terminated” before the block that creates the timer.
You still have to cancel the timer if it exists and not hasTerminatedbefore you create a new one. And that doesn’t happen automatically. You need to add an if block to test whether the timer has not terminated and cancel it if that’s true.
if not (timer test1 doesn't exist) and not (timer1 exists and timer1 has terminated)
Using the values from above that give us the table:
exists
True
False
not (exists and hasTerminated) True
True
False
not (exists and hasTerminated) False
False
False
That’s what we want. It’s only true when the timer exists (i.e. not is undefined) and it has not yet terminated (i.e it exists and hasTerminated returns false).
All the “not” blocks is unfortunately but they are a result of how the other blocks work.
I modify the blocks like yours, now the timer its running but again if i run again the code its creating another timer and so one, without to cancel the existed ones.