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:
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?
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
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.
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.
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 :
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.
@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).
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
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