Using ChannelEventTrigger in UI (JavaScript)

True, if you need to test if event exists, you need to use this. But it’s unnecessary everywhere else.

Testing against the event type is a powerful way to make flexible rules. For example, in my rule templates I use that so that when the rule is triggered manually it runs internal tests to ensure everything is configured correctly. For my MQTT EventBus rule template, I was able to combine the subscribe and publish functions into one rule by seeing how the rule was triggered (if triggered by a Channel event I know it’s a received message, when triggered by an Item I know it’s a message to publish).

But there are cases where event won’t exist (though it’s not super consistent, an issue was recently opened on that) so if you are using the event Object, and your rule has multiple ways to be triggered it’s important to test that it exists before trying to use it.

Most of the time, it’s an error case if the rule is triggered in a way that the event Object doesn’t exist so it’s OK to let it just thorw that exception.