Distinguishing between Channel & Item event in JS rules

Hi all,
I’ve a rule that is triggered from an item event and a channel event.

Now how to distinguish between them in the associated rule ?

Item event is clear : var itemName = event.itemName ;
For channel events, ‘event.itemName’ = undefined ;

Of course an item can be attached to the channel, but why do I get the chance at all to attach channels directly to rules ?

Thx for any help !
br
Gerry

I’ve been helped in that search a few weeks (months?) ago: Using ChannelEventTrigger in UI (JavaScript) - #2 by rlkoshak

1 Like

Only a certain type of channel can be use to trigger a rule. These Channels represent an event that doesn’t have a meaningful state. For example, when you press a momentary button, the button isn’t ON afterward nor is it OFF afterward. The button doesn’t really have a state at all, it’s purely an event.

Items represent state. Therefore, it doesn’t really make sense to link a momentary button (for example) to an Item. Therefore, event type Channels can be used to trigger a rule directly without an Item’s involvement.

1 Like

Thank you Rich & Erik for the explanation.
I will follow the link provided by Erik and found ‘event.eventype’ in rules which should fit.

Background of this all is the typical application ‘switch on light at sunset’ which is a thing event, combined with a zigbee button. Both result in the same result: Switch on the light.

Thx again
Gerry

If you are talking about Astro, you can also link one of the Sunset state Channels to a DateTime Item and trigger the rule using a “Time is Item” trigger. That would be a good way to do it if you need the sunset time for other purposes.

Hi Rich,
thanks for the suggestion.

Tried that immediately. Tried to link an item to the channel “astro:sun:home:set#event (Trigger)”, but got error message that “No profile is available” for this channel" whatever ‘type’ I use.

This was already discusssed long time ago here Astro binding: Cannot create item from thing for Range event (there is no profile available for the selected item) - #6 by rossko57

So I’m a bit lost with your suggestion

Thx
Gerry

You missed the part where I said “state Channels”.

Each solar event (e.g. Nautical Sunrise) has four Channels: start time, end time, duration, and range event. The first three can only be linked to Items. The event Channel cannot be linked to an Item.

Note that solar events have a length. They are not instants. They all have a start time and an end time. The event Channel will get START at the start time and END at the end time, meaning if you trigger a rule using this Channel, that rule will get triggered when solar event starts and then again when it ends.

If you want to change trigger the rule when sunset starts, link the Start Time Channel to the DateTime Item and use that Item to trigger the rule with a Time is Item trigger. If you want it to trigger at the end of sunset, use that Channel instead. Not you can also add offsets to the Channels so you can get 30 minutes before the start of nautical sunset, for example.

Thanks Rich for your explanation ( … and your patience ! )
I did that already: Linked astro:sun:home:set#start to a DateTime- Item and attached the rule to it.
And AFAIR, it was triggerd somewhere around midnight, when the new sunrise-/set is calculated.

Anway, I will wait tonight and see what will happen and will report tomorrow.

Then you used the wrong trigger. You triggered the rule when the Item changes., You need to use the “Time is Item” trigger.