triggeringItemName of Time

I have a rule with different triggers, one of them is Time

    Time cron "0 0 16 ? * * *" or
    Item item1 changed or
    Item item2 changed or
    Item item3 changed
logInfo("Trigger", triggeringItemName)
    switch(triggeringItemName) {
        case "Time": {
            //do stuff, does not work
        case "item1": {
            //do stuff, works
        case "item2": {
            //do stuff, works

Unfortunately the switch case works with all my items, except for the Time cron trigger. What am i doing wrong? The triggeringItemName is null. I am certain its because Time is not an Item. How to get the Time cron as a switch case trigger?

That’s right. There is no triggering Item.

You can discover if there is no triggering Item, and infer it was a cron trigger.
You can acces the time ‘now’ in your rule, though its likely to be a few milliseconds after the cron by the time you can.

Can you show me how to infer when it was a cron trigger?

In OH2 the triggeringItem simply did not exist, so you had to test for that.

But I think in OH3 it exists but is null as you said.

if (triggeringItemName == null) {
   logInfo("test", "There was no Item trigger")

What an easy solution, why didnt i think of that? Haha.

it must be

triggeringItemName === null

for everyone else seeing this topic in the future.

//edit: after a bit of testing

case null: {
    //do stuff

also works

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.