Don’t know if it helps, but here is a Rule where I tinkered a bit with “receivedEvent.getEvent”
//import org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent // When using this import, you can see the answer next line
// The import 'org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent' is never used.
rule "sunset check"
when
Channel 'astro:sun:local:set#event' triggered
or Channel 'astro:sun:local:noon#event' triggered
or Channel 'astro:sun:local:rise#event' triggered
or Channel 'astro:sun:stowing3:astroDusk#event' triggered
or Channel 'astro:sun:local:civilDusk#event' triggered
or Channel 'astro:sun:local:nauticDusk#event' triggered
or Channel 'astro:sun:local:astroDusk#event' triggered
or Channel 'astro:sun:local:daylight#event' triggered
or Channel 'astro:sun:stowing1:noon#event' triggered START
or Channel 'astro:sun:stowing2:noon#event' triggered
or Channel 'astro:sun:stowing3:noon#event' triggered
or Channel 'astro:sun:local:rise#event' triggered
or Channel 'astro:sun:local:morningNight#event' triggered
or Channel 'astro:sun:local:astroDawn#event' triggered
or Channel 'astro:sun:local:nauticDawn#event' triggered
or Channel 'astro:sun:local:night#event' triggered
then
// val String ruleTitle="event::getCanonicalName()"
logInfo( "sunset Check", "INFO: 40 receivedEvent.class.getCanonicalName() --> [{}], Event = '{}'", receivedEvent.class.getCanonicalName(), receivedEvent.getEvent() )
logInfo( "sunset Check", "INFO: 41 receivedEvent.channel.toString() --> [{}], Event = '{}'", receivedEvent.channel.toString(), receivedEvent.getEvent() )
logInfo( "sunset Check", "INFO: 42 receivedEvent.channel.toString() --> [{}], Event = '{}'", receivedEvent.channel.toString(), receivedEvent.getEvent.toString() )
val channelevent = receivedEvent.getEvent()
logInfo( "sunset Check", "INFO: 44 Channel Event = '{}'", channelevent )
val channelname = receivedEvent.channel.toString()
logInfo( "sunset Check", "INFO: 46 Channel Name = '{}'", channelname )
val channelthingUID = receivedEvent.channel.thingUID.toString()
logInfo( "sunset Check", "INFO: 48 Channel UID = '{}'", channelthingUID )
val channelID = receivedEvent.channel.id.toString()
logInfo( "sunset Check", "INFO: 50 Channel ID = '{}'", channelID )
logInfo( "sunset Check", "INFO: 51 receivedEvent.channel.toString() Line 37 --> [{}], receivedEvent = '{}'", receivedEvent.channel.toString(), receivedEvent)
// logInfo( "sunset Check", "INFO: receivedEvent.channel.toString() Line 40 --> [{}], Event = '{}'", receivedEvent.class.getCanonicalName.toString().split(".").get(5), receivedEvent.getEvent() ) // geht so nicht - doesn't work either
// val channelState = receivedEvent.getStatusInfo // geht so nicht - doesn't work either
// logInfo( "sunset Check", "INFO: Channel Status Line 42 = '{}'", channelState ) // geht so nicht - doesn't work either
val triggerEvent_split = receivedEvent.toString
logInfo( "sunset Check", "INFO: Trigger Line 56 = '{}'", triggerEvent_split )
logInfo( "sunset Check", "INFO: Thing Type Line 57 = '{}'", triggerEvent_split.split(":").get(1))
logInfo( "sunset Check", "INFO: Thing Name Line 58 = '{}'", triggerEvent_split.split(":").get(2))
logInfo( "sunset Check", "INFO: Thing Channel Line 59 = '{}'", triggerEvent_split.split(":").get(3))
logInfo( "sunset Check", "INFO: Thing Channel Line 60 = '{}'", triggerEvent_split.split(":").get(3).split(" ").get(0))
logInfo( "sunset Check", "INFO: Thing Channel Line 61 = '{}'", triggerEvent_split.split(":").get(3).split(" ").get(0).split("#").get(0))
val triggerEvent_split_3 = triggerEvent_split.split(":").get(3)
logInfo( "sunset Check", "INFO: Split_3 ID Line 63 = '{}'", triggerEvent_split_3 )
end
/*
Example-Results of the Logger
INFO: receivedEvent.class.getCanonicalName() --> [org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent], Event = 'END'
INFO: receivedEvent.channel.toString() --> [astro:sun:stowing3:astroDusk#event], Event = 'END'
INFO: Channel Event = 'END'
INFO: Channel Name = 'astro:sun:stowing3:astroDusk#event'
INFO: Channel UID = 'astro:sun:stowing3'
INFO: Channel ID = 'astroDusk#event'
INFO: receivedEvent.channel.toString() Line 37 --> [astro:sun:stowing3:astroDusk#event], receivedEvent = 'astro:sun:stowing3:astroDusk#event triggered END'
INFO: Trigger Line 42 = 'astro:sun:stowing3:astroDusk#event triggered END'
INFO: Thing Type Line 43 = 'sun'
INFO: Thing Name Line 44 = 'stowing3'
INFO: Thing Channel Line 45 = 'astroDusk#event triggered END'
INFO: Thing Channel Line 46 = 'astroDusk#event'
INFO: Thing Channel Line 47 = 'astroDusk'
INFO: Split_3 ID Line 49 = 'astroDusk#event triggered END'
*/
and a rule which I have in my valid setup (OH 2.5.M3) to look what triggers the rule (item or channel)
import org.eclipse.smarthome.model.script.ScriptServiceUtil
val sonoff_device_ids = newArrayList("sonoffs")
val rulename = "sonoff_firmware_info"
var Timer tSonoffFirmware = null
rule "Sonoff_firmware_info"
when
Item Sonoff_Release_Refresh changed to ON
or Channel 'astro:sun:local:noon#event' triggered START
or Channel 'astro:sun:local:astroDusk#event' triggered START
then
var firmware = transform("REGEX", ".*([0-9].[0-9].[0-9])", Sonoff_Current_FW_Available.state.toString)
logInfo(rulename, "Tasmota Refresh Items Firmware-Release-State in BasicUI : " + firmware + "(sonoff)")
// is it an event based Trigger ?
if (triggeringItem !== null) {
// now you can do stuff like logInfo
logInfo(rulename, "Rule fired manually by : " + triggeringItem.name + " State: " + triggeringItem.state + " previousState: " + previousState)
// or something other like: generic item from triggeringItem.name "it's Just fun and tinkering"
//++++ Pointer-adresses for the dynamically generated items to get corresponding/generic item ***thx to @5iver and @rlkoshak for help***
var GenericItem tempTriggerItem = ScriptServiceUtil.getItemRegistry.getItem(triggeringItem.name) as GenericItem //
logInfo (rulename, "Itemname is: " + tempTriggerItem.name)
// or this :
if (tSonoffFirmware !== null) {
logInfo(rulename,"Timer wird gecancelled: " + tSonoffFirmware)
tSonoffFirmware.cancel
}
logInfo(rulename,"Timer wird initialisiert")
tSonoffFirmware = createTimer(now.plusSeconds(5), [ |
if (triggeringItem.state == ON) { // this is the state of the triggering Item (could also be generic Item's State) "it's Just fun"
tempTriggerItem.postUpdate(OFF) // update(switch Off) the triggering item via generic item (as it's the same in this case) "it's Just fun"
logInfo(rulename,"GenericItem ist " + tempTriggerItem)
// or whatever stuff you want ;)
}
])
}
// is it a channel based Trigger ?
else if (receivedEvent !== null) {
// now you can do stuff like logInfo
logInfo(rulename, "Rule fired by Channel: " + receivedEvent.toString )
// and of course a lot of other stuff if you/I want ;)
}
val actionsBroker = getActions("mqtt","mqtt:broker:hans") //mqtt2
for (String device_id : sonoff_device_ids) {
actionsBroker.publishMQTT( "cmnd/" + device_id + "/status", "2") // mqtt2
// publish("peter", "cmnd/" + device_id + "/status", "2") // mqtt1
logInfo(rulename, "Sonoff Maintenance: " + device_id)
}
logInfo(rulename, "Tasmota Refresh Items Firmware-Release-State : end")
end
Edit: Here is the Result of the logger
2019-09-27 13:13:01.963 [INFO ] [me.model.script.sonoff_firmware_info] - Rule fired by Channel: astro:sun:local:noon#event triggered START