[WORKAROUND] ‘getEvent’ is not a member error [OH 2.5.x]

Apparently, several people (including myself) still have problems using getEvent(). Some comparable threads are marked as “solved”, although the problem still exists. So in order not to forget the issue, I open this thread and hope to find a solution.

Please note that different bindings are affected, e.g. Philips Hue, Homematic, MQTT, …) so that this may not be a binding-specific issue. Personally, I still have the problem with the milestone 2.5.0 M3 (it didn’t work with M1 either).

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

Just for information. I activated the rule and the result from the logger looks like:

2019-09-27 19:08:00.898 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 40 receivedEvent.class.getCanonicalName() --> [org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent], Event = 'START'
2019-09-27 19:08:00.898 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 40 receivedEvent.class.getCanonicalName() --> [org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent], Event = 'END'
2019-09-27 19:08:00.911 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 41 receivedEvent.channel.toString()       --> [astro:sun:local:daylight#event], Event = 'END'
2019-09-27 19:08:00.911 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 41 receivedEvent.channel.toString()       --> [astro:sun:local:set#event], Event = 'START'
2019-09-27 19:08:00.926 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 42 receivedEvent.channel.toString()       --> [astro:sun:local:daylight#event], Event = 'END'
2019-09-27 19:08:00.926 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 42 receivedEvent.channel.toString()       --> [astro:sun:local:set#event], Event = 'START'
2019-09-27 19:08:00.931 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 44 Channel Event = 'END'
2019-09-27 19:08:00.935 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 44 Channel Event = 'START'
2019-09-27 19:08:00.940 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 46 Channel Name =  'astro:sun:local:daylight#event'
2019-09-27 19:08:00.948 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 46 Channel Name =  'astro:sun:local:set#event'
2019-09-27 19:08:00.952 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 48 Channel UID =  'astro:sun:local'
2019-09-27 19:08:00.960 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 50 Channel ID =  'daylight#event'
2019-09-27 19:08:00.965 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 48 Channel UID =  'astro:sun:local'
2019-09-27 19:08:00.968 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 51 receivedEvent.channel.toString() Line 37      --> [astro:sun:local:daylight#event], receivedEvent = 'astro:sun:local:daylight#event triggered END'
2019-09-27 19:08:00.972 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Trigger Line 56 =  'astro:sun:local:daylight#event triggered END'
2019-09-27 19:08:00.976 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 50 Channel ID =  'set#event'
2019-09-27 19:08:00.980 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Type Line 57 =  'sun'
2019-09-27 19:08:00.983 [INFO ] [.smarthome.model.script.sunset Check] - INFO: 51 receivedEvent.channel.toString() Line 37      --> [astro:sun:local:set#event], receivedEvent = 'astro:sun:local:set#event triggered START'
2019-09-27 19:08:00.986 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Name Line 58 =  'local'
2019-09-27 19:08:00.988 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Trigger Line 56 =  'astro:sun:local:set#event triggered START'
2019-09-27 19:08:00.993 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Channel Line 59 =  'daylight#event triggered END'
2019-09-27 19:08:00.993 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Type Line 57 =  'sun'
2019-09-27 19:08:00.999 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Name Line 58 =  'local'
2019-09-27 19:08:01.001 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Channel Line 60 =  'daylight#event'
2019-09-27 19:08:01.005 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Channel Line 59 =  'set#event triggered START'
2019-09-27 19:08:01.011 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Channel Line 61 =  'daylight'
2019-09-27 19:08:01.013 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Channel Line 60 =  'set#event'
2019-09-27 19:08:01.017 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Split_3 ID Line 63 =  'daylight#event triggered END'
2019-09-27 19:08:01.023 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Channel Line 61 =  'set'
2019-09-27 19:08:01.030 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Split_3 ID Line 63 =  'set#event triggered START'

Thank you for your code snippet. Unfortunately, any attempt to use receivedEvent.getEvent results in an error message like this:

2019-09-29 18:44:08.405 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'myrule': 'getEvent' is not a member of 'org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent'; line 61, column 28, length 24

Sorry that I can’t help, but if you see in my Logging

    val channelevent = receivedEvent.getEvent()
    logInfo( "sunset Check", "INFO: 44 Channel Event = '{}'", channelevent )

this works properly, for both Triggers, came up at that moment. Very mysterious.
I have to say that I only tried the Astro-Binding. But I can’t believe that this Binding-specific.

Edit: Just saw in your other post, that you use it in this way

var String ButtonEvent = receivedEvent.getEvent() 

Have you tried it in this way:

var ButtonEvent = receivedEvent.getEvent()
or
val ButtonEvent = receivedEvent.getEvent()

The statement itself fails independent of the declaration. As far as I can judge @cweitkamp, @maggu2810 and @rancor187 have been investigating the issue but there is no activity in that Github issue since end of July.

Hej there, sorry I couldn’t reply earlier. I am on vacation this week and I’ll have finally time to get back to OH.

I’ll keep you posted.

1 Like

Thank you very much!

Hi all,

This issue is frustrating me too. And I have a personal interest in solving it. I will raise its priority on my to-do list and try to do some more research in the next couple of days. Hope to get this fixed soon.

2 Likes

Hej there,

I am still not finished with the wireing of the distribution box (Homematic IP Wired components). Takes longer than expected. Hope I am done with it tomorrow evening.

I maybe have a trace: I did some tests on three different systems. On two of them - running from Eclipse IDE with latest code base and a test environment OH2.5.S1706 - it was working fine and on the third one - my live environment (OH2.5.M3) - it always has thrown the above error. The main difference beside OH versions on those systems was that I NGRE (Rule Engine (Experimental)) has been installed in both systems where it is working and not in my live environment. Can anyone confirm this?

I will do more test in the next days.

1 Like

Thank you, @cweitkamp, for your efforts so far!

Unfortunately not. I have installed the Rule Engine (Experimental) and restarted the OH service but no difference (2.5.0 M3). The error message is still the same.

May be this helps to find the issue. I think its in channel code.

I have a similar issue with the MQTT binding. (openhab-2.5.0-M3)

I’ve created a Channel through PaperUI under a MQTT Broker Thing.

mqtt:broker:mosquitto:OpenHabMQTTSubscription

and this simple rule

rule "Subscribe for commands and updates from the event bus"
when
    Channel 'mqtt:broker:mosquitto:OpenHabMQTTSubscription' triggered
then
    logInfo("MQTT","Channel trigger event received")
    logInfo("MQTT", ("Channel triggered:"+  receivedEvent.channel.id))
    var String resEvent=receivedEvent.toString()
    val itemName = resEvent.split("/").get(2)
    val type = resEvent.split("/").get(3).split("#").get(0)
    val state = resEvent.split("#").get(1)
    logInfo("MQTT", ("Channel triggered Item:" + itemName + " Type:" + type + " State:"+state))
end

Then I publish a topic at the broker by MQTTfx

Topic: openHAB/in/KinderzimmerRechtsAutomationEnabled/command 
Value: OFF

May be this is an initialisation of an object or timing problem during openhab startup. Because:
After restarting openhab (without any config changes) the rule sometimes work:

[INFO ] [org.eclipse.smarthome.model.script.MQTT                 ] - Channel trigger event received
[INFO ] [org.eclipse.smarthome.model.script.MQTT                 ] - Channel triggered:OpenHabMQTTSubscription
[INFO ] [org.eclipse.smarthome.model.script.MQTT                 ] - Channel triggered Item:KinderzimmerRechtsAutomationEnabled Type:command State:OFF

and sometimes not

[org.eclipse.smarthome.model.script.MQTT                 ] - Channel trigger event received
[ERROR] [rthome.model.rule.runtime.internal.engine.RuleEngineImpl] - Rule 'Subscribe for commands and updates from the event bus': 'channel' is not a member of 'org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent'; line 45, column 45, length 21		 

If it fails once all other attempts failed too. If it works once then forever.

The issue persists with milestone 2.5.0 M5. :frowning_face:

Hi all,
For those who are trying to deal with a Hue dimmer switch and suffering from this issue, I observed in the Hue binding documentation an alternative way to characterise the event generated by the dimmer switch, which does not require using the misfunctionning getEvent() call.
The only drawback is that it requires writing several rules (one per type of event you want to handle) instead of one single rule with different action based on the content of getEvent().

So instead of:

rule "Turn Lights On"
when
    Channel "hue:0820:00178828911b:2:dimmer_switch_event" triggered
then
    switch(receivedEvent.getEvent()) {
        case "1002.0": {
            callScript("Lights_Max_Level.script")}
        case "2002.0": {
            callScript("Lights_Mid_Level.script")}
        }
end

I suggest:

rule "Turn Lights On Max level"
when
    Channel "hue:0820:00178828911b:2:dimmer_switch_event" triggered 1002.0
then
    callScript("Lights_Max_Level.script")
end 
rule "Turn Lights On Mid level"
when
    Channel "hue:0820:00178828911b:2:dimmer_switch_event" triggered 2002.0
then
    callScript("Lights_Mid_Level.script")
end

Hi @Alexisfr,

welcome to the openHAB community and thank you for your posting! :smiley:

Yes, exactly! If you want to evaluate all possible combinations of those 4 buttons with 4 states each (see Philips Hue Binding Trigger Channels), you would have to write 16 (!) rules with almost the same code. This is not really an option as there is the getEvent() function that is supposed to work. I would prefer the latter to avoid confusing duplicated code which is difficult to maintain.

1 Like

Hej there,

I’ve been updating to Stable 2.5 and I haven’t had that error yet.
So as of right now, this seems to be working for me:

var actionName = receivedEvent.getEvent()

Hope it stays that way :slight_smile:
I’ll keep you posted if it changes

Thanks

1 Like

… and in the current 2.5 stable. This weekend I took quite some time to perform a full openHAB setup from scratch which means I did

sudo openhab-cli backup

for my current configuration and then a fresh openHABian installation. I finally restored my backup via

sudo openhab-cli restore /var/lib/openhab2/backups/openhab2-backup.zip

To my surprise everything is fully working again except for that receivedEvent.getEvent() stuff. :face_with_raised_eyebrow: Seems like I have wasted the time.

Thanks to @Sharpy I was able to replace the triggering mechanism of my Hue dimmers with his approach:


I for my part will now put the matter to the records and continue with the actual automation. :wink:

2 Likes

Hi Alexis,

thank you for your workaround it took me at least a bit further.

i´m not sure if that helps anyone to actually solve the issue but i found it wired enough to document what i found.

to avoid having to much code copied like miba pointed out i tried to create handlers for all buttonevents and redirecting these to my original handler that i altered to be a function.
Unfortunatly this didn´t resolve the issue for me but showed that any call deeper in the callstack would fail, so the issue is not realy related to getEvent or ChannelTriggeredEvent

surprisingly the call to remoteNum.toString() works in the handler it self but wouldn´t work in myBadTriggerHandler.
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘genericRemote8_1002’: cannot invoke method public java.lang.String java.lang.Integer.toString() on null
also the call to myBadTriggerSubHandler failes
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘genericRemote8_1002’: cannot invoke method public abstract void org.eclipse.xtext.xbase.lib.Procedures$Procedure0.apply() on null

var remoteNum = 8
rule "genericRemote8_1002"
when
    Channel "deconz:switch:e12c892c:90fd9ffffe0579c6011000:buttonevent" triggered 1002
then
    logInfo("Remote #"+remoteNum.toString()+" tripped", "1002")
    myBadTriggerHandler.apply("center short")
    logInfo("Remote #"+remoteNum.toString()+" completed", "1002")
end

var myBadTriggerHandler = [String actionName|

    logInfo("myBadTriggerHandler triggered", actionName)
    myBadTriggerSubHandler.apply()
    logInfo("Remote #"+remoteNum.toString(), "actionName")
    logInfo("myBadTriggerHandler triggered again", actionName)
]
var myBadTriggerSubHandler = [|

    logInfo("myBadTriggerSubHandler triggered", "")
    logInfo("Remote #"+remoteNum.toString(), "actionName")
    logInfo("myBadTriggerSubHandler triggered again", "")
]

I hope this helps anyone to find a fix as my girlfriend startet using our wallswitches again and no one can want that to happen…

thanks for all your work.

cu jason

Hi guys,

I want to check on the status here. I also found those 2 threads mentioned above marked as [SOLVED]. Event this [WORKAROUND] here has no real solution.

What I could say: The problem still persist. I see this with the Shelly binding, already on my old RPI3 setup with 2.5.2 and now also with my new setup based on 2.5.7. This means

  • problem is not solved
  • not dedicated to a specific OH release
  • not dedicated to a specific binding
  • rule engine doesn’t matter

The Shelly binding provides 7 different alarm event types. So having 7 rule duplicates for each group of devices is no option.

@cweitkamp Where you able to find out something.

This is an essential feature from my point of view. It WOULD make the alarm handling for my devices very compact, but having a rule per event type is no option.