I am currently migrating my rules (or better starting from scratch) using mainUI and blockly.
As far as I understood timers in blockly rules are local only (like in DSL rules).
However inside a DSL rule file I was able to use the timer all over the place.
So if I want to do this in Blockly as well, I assume that the timer can only be used in one file as well (one graphical view in Blockly).
And if so, how to know which trigger fired the rule, so that I can distinguish between different parts / rules within this one blockly file / view?
The timer is persisted within one rule. If you update your rule or restart OH server, you will get a new rule instance with new rule timer.
You can give names to the timers, if you have multiple, to differentiate between timers.
So that means, I cannot cancel the timer from another rule?
No, only from the same rule.
E.g. instead of having two rules, one triggered by item A changes from ON to OFF and a second rule triggered by item B changes from OFF to ON I would combine both into one generic rule triggered by “item A changes”, where you than can manage all you cases for this item and create or cancel the trigger if needed.
Thank you Matze.
I have actually implemented a workaround:
I set one switch (lets say A) with an expiration time, which will receive an OFF if it expires (simulating the timer).
If switch B changes, I will switch A to OFF with postUpdate.
The main execution of switch A (after it expired normally) will only be execute by command OFF.
If this turns out not to work, I will try your approach.
Again - thanks for your support!
Just want to add one detail.
In JSScripting, there is a new cache object that can be used to share variables across all script actions and script conditions.
Why do I say “script actions and script conditions” instead of “rules”? Because in the UI, any single time can have zero or more actions and zero or more conditions. Any variables are limited to just the rule, but to the action or condition. So if you have a timer in one action, it won’t be available even in actions or conditions in the same rule.
Thank you @rlkoshak
I assume this is available in “pure” JSScripting - not Blockly (yet)?
This would exceed my capabilities coming from DSL at this point.
However, for the future - after the learning curve get’s steeper, I will check it out.
it’s only available in the JSScripting add-on.
Probably not. If you can translate your Rules DSL to Blockly you can do so to any language. And you would only need to do so for the errors that use the cache. JA Scripting which comes with openhab-js is far easier to use than NashornnJS or Jython. It’s about on par with Rules DSL and it has a good set of reference docs.
I bet you’ll find it’s easier than trying to rework the logic of your existing rules so it’s all one