Implicit variable triggeringItem castrated in OH3

Hi,

in order to manage my text based rules in an easy way I make extensive use of the implicit variable: triggeringItem

Unfortunately OH3 does only provide access to this variable if the rule has a “Member of” trigger. Good thing, this is documented :wink: Bad thing, I’m stuck here:

rule "turn on TV and AVR"
when
      Item Harmony_XBOX received command ON or
      Item Harmony_Nintendo received command ON or
      Item Harmony_Playstation received command ON or
      Item Harmony_SatTV received command ON or
then
      HarmonyActivity_HK.sendCommand(triggeringItem.label.toString())
end

I see two options:

  1. split all the triggers into individual rules
  2. use the import org.openhab.core.model.script.ScriptServiceUtil together with implicit variable triggeringItemName to access the item label

Would you agree these are good ways to implement? Or is there any better way?

Stefan

  1. Put your random collections of Items into a Group “stuffToTriggerRuleXX” and use the Member of trigger.
    Bonus - never edit the rule again to add or remove triggering Items, manage by membership.instead.

I think this restriction is only for DSL rules under OH3, and in other languages there is a way to extract the Item from the general trigger event.

1 Like

sh… sometimes you don’t see the forest for the trees. thanks man :wink: