I’m wondering whether it’s possible to determine, which of the two cron expresions (or more generally, which triggers.id) has triggered the rule. (Of course triggers.id doesn’t work, otherwise, I wouldn’t have asked )
The short answer is no. If you have two time based triggers, there is no way to distinguish which one triggered the rule. You also cannot tell the difference between a time based trigger and a manual trigger.
You can tell the difference between an Item/Channel/Thing trigger by testing for what variables are defined on event like @chrismast mentions.
That’s actually not the case in UI rules and it’s a source of consternation. I’m not sure what to do about that yet. But in the UI, you get the raw event, same as you’d get in the JSR223 type rules (Nashorn, Jython, etc.). I don’t like it when it works that differently.
How would I configure this rule so that the Benchmark_es is set to say - 20 at 7am - and - 18 at 5pm… Can we get access within the openhab-js environment to the trigger id? so we could do something like:
In the actual openhab-js environment (i.e. a Script Action using JS Scripting) you can tell the difference between a cron tigger and an Item based trigger and even which Item triggered the rule. But you cannot tell the difference between cron triggers, or a cron trigger and a manual trigger.
You have two options:
Make two rules.
Use a Script Action where you can test to see what time of day it is and apply the correct value.
UI Rules are very simple by design and intent. Anything beyond the simple “when event occurs command/update Item” use cases will require the use of Script Actions.
I understood, and that’s how I understood the situation a year ago, when this thread was started.
Obviously, I can use several rules, which I’m currently doing, but they are horrible to maintain and modify.
I was just wondering whether inside a Script Action, I could not easily refer back to which of the several Cron’s have actually triggered the rules. IMHO, it defies the purpose of the interaction between trigger and (complex) Script Actions, if I have to use server resources and plenty of lines of code (to allow for slight trigger delays) to reproduce exactly the same condition, which has triggered the trigger in the first place … but ok.
You don’t need to reproduce the exact trigger conditions. This rule gets triggered exactly twice a day. If it triggers and it’s between 07:00 and 17:00 you know that it was the first trigger. Otherwise you know it was the second trigger. There could be hours between the cron time and the rule running and it will still do the right thing. If you want it to be really tight