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.

receivedEvent.getChannel()
receivedEvent.channel

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"
	when
		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
	then
		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")
				Lounge_Lamp_Switch.sendCommand(ON)
				Upstairs_Lounge_Lamp_Switch.sendCommand(ON)
				Christmas_Tree_Lights.sendCommand(ON)
				sendNotification("xxx","Dusk - Turning on inside lamps")
			}
			case "astro:sun:home:civilDusk#event" : {
				logInfo("Crib","Turning on front lights")
				Lights_Front_Switch_1.sendCommand(ON)
				sendNotification("xxx","Dusk - Turning on outside lights")
			}
		}
end

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
ScriptServiceUtil.getItemRegistry.getItem(triggeringItemName)

And then work off of that?

Not really, these are event channels not Items.

Done:

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.