eclipse-archived / smarthome

Eclipse SmartHome™ project
https://www.eclipse.org/smarthome/
Eclipse Public License 2.0
864 stars 782 forks source link

[Rules] Add receivedTrigger to Channel triggers similar to receivedCommand #5114

Open Nebula83 opened 6 years ago

Nebula83 commented 6 years ago

When a rule is trigged due to an Item that received a command, it is possible to get the value of that command via the receivedCommand variable for that rule.

When a channel is used to trigger a rule, the event that triggered the rule cannot be obtained from within the rule. This means that when a rule should be applied to any value sent to a trigger channel, multiple rules need to be created to achieve this:

rule "Harmony TV starting"
when
  Channel "harmonyhub:hub:Woonkamer:activityStarting" triggered TV_Kijken
then
  // Handle actions for 'TV_Kijken'
end

rule "Harmony Radio starting"
when
  Channel "harmonyhub:hub:Woonkamer:activityStarting" triggered Radio_Luisteren
then
    // Handle actions for 'Radio_Luisteren'
end

Proposed is an receivedTrigger analogue to receivedCommand that would simlyfy the above to:

rule "Harmony TV starting"
when
  Channel "harmonyhub:hub:Woonkamer:activityStarting" triggered
then
    switch receivedTrigger {
        case 'TV_Kijken' : // Handle actions for 'TV_Kijken'
        case 'Radio_Luisteren' : // Handle actions for 'Radio_Luisteren'
    }
end
kaikreuzer commented 6 years ago

Makes a lot of sense to me. Hope we find a volunteer to implement it!

Laxmikanth007 commented 6 years ago

Sir, I'd like to implement it and I'm going through the project.

kaikreuzer commented 6 years ago

Great, let us know, if you have any questions!

Laxmikanth007 commented 6 years ago

Sir, After using receivedTrigger, what happens if the rule is 'Harmony Radio Starting' ? Thank you.

paulianttila commented 5 years ago

Before receivedTrigger is implemented, receivedEvent can be used as a alternative.

receivedEvent is full event as string. Example: harmonyhub:hub:Woonkamer:activityStarting triggered TV_Kijken

rule "Harmony TV starting"
when
  Channel "harmonyhub:hub:Woonkamer:activityStarting" triggered
then
    switch receivedEvent.toString.split(' ').get(2).toString {
        case 'TV_Kijken' : // Handle actions for 'TV_Kijken'
        case 'Radio_Luisteren' : // Handle actions for 'Radio_Luisteren'
    }
end
t-8ch commented 5 years ago

It should also possible to directly use receivedEvent.event (and receivedEvent.channel)

dominikkv commented 5 years ago

The documentation talks about receivedEvent.getEvent():

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