receivedTrigger in Channel triggered rules

To be able to send push notifications to my phone I was exploring the possibility to create a rule on a particular trigger channel and then send the received tiggerEvent to that phone. I was hoping to re-use receviedCommand, but that does not work.

Is there something like receivedTrigger? Or is there any other way to obtain the value of the event that triggered the rule? This is what I have right now:

 rule "Harmony started"
 when
   Channel "harmonyhub:hub:RoomName:activityStarted" triggered
 then
   Notification.sendCommand("Harmony started " + receivedTrigger.toString())
 end

This works for all activities I start, but, in the rule, I have no clue as to what started it. Should I default to a rule for each activity with an explicit tiggerEvent, like:

Channel "harmonyhub:hub:RoomName:activityStarted" triggered PowerOff

Channel "harmonyhub:hub:RoomName:activityStarted" triggered Activity1

Channel "harmonyhub:hub:RoomName:activityStarted" triggered Activity2

Feels like a rather crude way to obtain the info that was sent to the channel anyway…

try: triggered START

Hi Dim, thanks for your answer. How would that help me converting any received event to a string?

btw, use ’ not "

here is an example:

when
        Channel 'astro:sun:local:set#event' triggered START
then

edit: i will check about the second part

Please see my updated question. START is not an activity that is available in my Harmony binding so that rule will never fire, but that’s beside the point. What I want to know it that when I take your example:

rule "Astro example"
when
    Channel 'astro:sun:local:set#event' triggered
then
    logInfo("someLoggingTitle", "Astro binding setted event " + receivedCommand.toString()
end

Which should then print a log line like

Astro binding setted event START

Any way to go go about this? Because receivedCommand is not available in a Channel triggered rule

not sure if this can be done… i will check also.
maybe another way: use a (dummy?) item , set the state using a rule, then use the state for your notification?

What seems to work for me is using this:

rule "Harmony starting"
when
  Channel "harmonyhub:hub:RoomName:activityStarting" triggered
then
  Notification.sendCommand("Harmony starting " + HarmonyActivity.state.toString())
end

rule "Harmony started"
when
  Channel "harmonyhub:hub:RoomName:activityStarted" triggered
then
  Notification.sendCommand("Harmony started " + HarmonyActivity.state.toString())
end

and

String HarmonyActivity           "Activiteit [%s]" { channel="harmonyhub:hub:RoomName:currentActivity" }

But that is very binding specific. I was hoping on a more generic and elegant way of doing this, but it seems it cannot be done since it seems you cannot get the event from within a rule and you cannot bind an item to a Trigger Channel.

Update
This doesn’t even work, since there is no guarantee that currentActivity is set before starting is called.

@Kai can you please confirm that there is no receivedCommand counterpart for Channel triggers?

I much rather do:

rule "Harmony Activity starting"
when
  Channel "harmonyhub:hub:Woonkamer:activityStarting" triggered
then
  // Pseudo code follows
  if (receivedCommand == "Activity 1") {
    // Activity 1 actions
  }
  
  else if (receivedCommand == "Activity 2") {
    // Activity 2 actions
  }
  
  else if (receivedCommand == "Activity 3") {
    // Activity 3 actions
  }
  
end

than:

rule "Harmony Activity 1 starting"
when
  Channel "harmonyhub:hub::RoomName:activityStarting" triggered "Activity 1"
then
  // Activity 1 actions
end

rule "Harmony Activity 2 starting"
when
  Channel "harmonyhub:hub::RoomName:activityStarting" triggered "Activity 2"
then
  // Activity 2 actions
end

rule "Harmony Activity 3 starting"
when
  Channel "harmonyhub:hub::RoomName:activityStarting" triggered "Activity 3"
then
  // Activity 3 actions
end

I believe the expected way to handle that use case is to link that channel to an Item. Typically, with the channel triggers in the past, the trigger itself carries no data so it makes no sense to have a receivedCommand. The only data is the fact that the event triggered (e.g Dash button, Astro event).

If the Channel trigger carries data, it should be linked to an Item and the Item used to trigger the rule. Then you get receivedCommand populated and everything else Items support.

I can confirm that receivedCommand only gets populated for Item received command triggers.

Hi Rich,

Thanks for some background. Though I don’t think I fully understand yet. You mentioned that in the past the channels did not carry data. I wouldn’t know about that but at least they do now. Referring to the documentation :

Channel "<triggerChannel>" triggered [<triggerEvent>]

Item received command []

I don’t really see any difference in the semantics, so it feels a bit in consistent that a command has receivedCommand but an event does not have receivedEvent. Maybe I could post it as a feature request?

I tried trying an item to the trigger channel but no dice. It won’t trigger my rule. The fact that paper UI does not support it and I was not able to find any documentation on the subject led me to believe it it couldn’t be done. Could you perhaps enlighten me with an item and rule trigger example?

Rules and Persistence and Sitemap all work with Items. Before the addition of Channel triggers, the ONLY way to trigger a Rule is through Items. However, that meant that for momentary events one ended up having a Switch Item that momentarily went ON then OFF at the right time.

To avoid this requirement, the concept of Channel Triggers were introduced so we no longer need to define an Item that doesn’t carry any data to trigger on these momentary events.

But the “proper” way to deal with data from channels is through Items. This Channel should be linked to an Item.

Let’s delve deeper into the problems you had trying to link it to an Item. I have no experience with Harmony Hub so I don’t know specifics. Please describe what you tried.

No, this indeed does not exist, but I agree that it would be a useful addition - feel free to create a feature request at Issues · eclipse-archived/smarthome · GitHub.

@rlkoshak In general you are right, but these rule triggers were specifically introduced to also allow “custom” trigger events being used in rules without the need for an item (which would hold a state).

1 Like

Thanks for the feedback @Kai and @rlkoshak! I created feature request https://github.com/eclipse/smarthome/issues/5114.

Concerning linking an Item to the trigger channel, I tried this:

Rules

rule "Harmony TV starting"
when
  Channel "harmonyhub:hub:Woonkamer:activityStarting" triggered TV_Kijken
then
  // This works
end

rule "Harmony Radio starting"
when
  Channel "harmonyhub:hub:Woonkamer:activityStarting" triggered Radio_Luisteren
then
  // This works
end

rule "Harmony stopping"
when
  Channel "harmonyhub:hub:Woonkamer:activityStarting" triggered PowerOff
then
  // This works
end

rule "Harmony started"
when
  Channel "harmonyhub:hub:Woonkamer:activityStarted" triggered
then
  // This works but I don't now _what_ started
end

rule "Harmony item started"
when
  Item HarmonyStarted received command
then
  // Does not trigger
end

rule "Harmony item started update"
when
  Item HarmonyStarted received update
then
  // Does not trigger
end

rule "Harmony item started update"
when
  Item HarmonyStarted changed
then
  // Does not trigger
end

Items

String HarmonyActivity "Activiteit [%s]" { channel="harmonyhub:hub:Woonkamer:currentActivity" }
String HarmonyStarted  "Activiteit [%s]" { channel="harmonyhub:hub:Woonkamer:activityStarted" }
1 Like

Did you also try the third event-based trigger?

rule "Harmony item started changed"
when
  Item HarmonyStarted changed 
then
  // Does not trigger
end

Nope, will do.
Doesn’t trigger either. Added it so the list :slight_smile:

1 Like

Does the Item change?
It seem to me that there is something else also not right as it is reported to change work like this.

But maybe there is no trigger when the item gets updated from the channel.

Just wanted to mention that the rule dsl documentation has the following example, maybe this was added in the last year:

rule "Start wake up light on sunrise"
when
    Channel "astro:sun:home:rise#event" triggered
then
    switch(receivedEvent.getEvent()) {
        case "START": {
            Light.sendCommand(ON)
        }
    }
end
5 Likes