Error in rule: 'getChannel' is not a member of 'java.lang.String'

In OH2, I was able to do this:

val trigger = receivedEvent.getChannel().toString()

In OH3, only val trigger = receivedEvent works and this rightly gives me the event START, but I am after the channel that triggered the event. I have unsuccessfully tried the below variations but from reading the release notes I wonder if it has been removed.


I initially had this as 2 rules but combined them into one. I suppose I could go back to that, but just checking I am not missing something.

rule "Sunset Rule"
		Channel "astro:sun:home:civilDusk#event" triggered START or
		Channel "astro:sun:minus45:civilDusk#event" triggered START or
		Channel "astro:sun:test:civilDusk#event" triggered START
		val trigger = receivedEvent.getChannel().toString()
		logInfo("Crib","Dusk is approaching - Turning on lights. Triggering item is " + trigger)
		switch trigger {
			case "astro:sun:minus45:civilDusk#event" : {
				logInfo("Crib","Turning on inside lamps")
				sendNotification("xxx","Dusk - Turning on inside lamps")
			case "astro:sun:home:civilDusk#event" : {
				logInfo("Crib","Turning on front lights")
				sendNotification("xxx","Dusk - Turning on outside lights")

Yes, it’s just a string now (so of course no .getChannel() method)

What you need is a new implicit variable like triggeringChannel or something, but I don’t know if they have made that available in DSL rules.
The problem got mentioned but unanswered in a related issue

I think you may need to log an issue for this enhancement/regression.

Can you not just use something like:

import org.openhab.core.model.script.ScriptServiceUtil

And then work off of that?

Not really, these are event channels not Items.


Thanks @rossko57

1 Like

Could you not just tie an item to the channel and monitor that for the update instead?

Only if the binding offers some state channel that is vaguely similar to the event you are looking for.
State channels, the more common type that we link to Items, and event channels, also called trigger channels, are two different things.

In the particular case of Astro here, there is a state channel for e.g. sunrise. But it gets set to 0730 or whatever at midnight, when astro calculates the day ahead. It doesn’t change at 0730.