In OH 4.0.1 event is always defined. It contains a string like “Timer 6 triggered”, when the rule isn’t triggered by an item but by a timer.
Is this a new feature which is not mentionend in the docs and in the breaking changes? I have to rewrite some of my rules, because I cannot rely on a not defined event object when I want to react to a timer trigger.
Yes. All rule triggers except manually have an event Object telling how the rule was triggered to differentiate between all trigger types, not just Item and Thing triggers.
I don’t know if this made it into the docs. I’m not entirely certain where in the docs it would go.
All you have to change is what you compare to. Instead of if(this.event === undefined) use if(event.type == 'TimerEvent') (I think, log out event.type to verify it’s called “TimerEvent”).
As previously implemented, you couldn’t tell the difference from a timer trigger, a system started trigger, manual trigger, time of day trigger, nor could you tell the difference between timer triggers (the 6 is the ID of the trigger which is shown in the UI under the code tab for UI rules).