[SOLVED] Problems with a rule after upgrading to 2.5 M2

To syncronize two OpenHab instances I have without problems used the code example from here https://github.com/openhab/openhab2-addons/blob/master/bundles/org.openhab.binding.mqtt.generic/xtend_examples.md.

After upgade to 2.5 M2 this rule does not work any longer:

rule “Receive mqtt from RPi7”
when
Channel “mqtt:broker:zWaveBroker:zWaveTrigger” triggered
then
/* The receivedEvent String contains unneeded elements like the mqtt topic, we only need everything after the “/” as this is were item name and state are */
val parts1 = receivedEvent.toString.split("/").get(1)
val parts2 = parts1.split("#")
postUpdate(parts2.get(0),parts2.get(1))
end

The log shows following:
2019-08-23 13:43:54.805 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Receive mqtt from RPi7’: ‘toString’ is not a member of ‘org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent’; line 460, column 16, length 22

I have cleared the cache several times after the upgrade, tried various rewrites of the rule without success and also looked for a solution at the variou forums but not found a clue to what might be a solution.

Anyone else experiencing same problem and been able so solve it?

What version did you upgrade from ? You’re eventually using the MQTT v2 binding now which is … well, different and not fully backwards compatible (for now you can deploy mqtt1 binding if that’s the problem).

I think you may now need to use

receivedEvent.Event.toString

I upgraded from 2.5 M1.

I tried the suggested receivedEvent.Event.toString but the error message now is:

Rule ‘Receive mqtt from RPi7’: ‘Event’ is not a member of ‘org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent’; line 460, column 16, length 19

I have also tried using receivedEvent.getEvent().toString and then the error message changes to:
Rule ‘Receive mqtt from RPi7’: ‘getEvent’ is not a member of ‘org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent’; line 460, column 16, length 24

So whatever is put after receivedEvent is considered not beig a member of …

Have you tried:

receivedEvent.getEvent.toString()

Yes, I have tried it with same result and error message.

May we see your actual thing and trigger channel?

Are you shure ?

I have the following Rule (for testing):

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:local:noon#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: receivedEvent.class.getCanonicalName() --> [{}], Event = '{}'", receivedEvent.class.getCanonicalName(), receivedEvent.getEvent() )
    logInfo( "sunset Check", "INFO: receivedEvent.channel.toString()       --> [{}], Event = '{}'", receivedEvent.channel.toString(), receivedEvent.getEvent() )
    logInfo( "sunset Check", "INFO: receivedEvent.channel.toString()       --> [{}], Event = '{}'", receivedEvent.channel.toString(), receivedEvent.getEvent.toString() )
    val channelevent = receivedEvent.getEvent()
    logInfo( "sunset Check", "INFO: Channel Event = '{}'", channelevent )
    val channelname = receivedEvent.channel.toString()
    logInfo( "sunset Check", "INFO: Channel Name =  '{}'", channelname )
    val channelthingUID = receivedEvent.channel.thingUID.toString()
    logInfo( "sunset Check", "INFO: Channel UID =  '{}'", channelthingUID )
    val channelID = receivedEvent.channel.id.toString()
    logInfo( "sunset Check", "INFO: Channel ID =  '{}'", channelID )
    logInfo( "sunset Check", "INFO: 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 42 =  '{}'", triggerEvent_split )
    logInfo( "sunset Check", "INFO: Thing Type Line 43 =  '{}'", triggerEvent_split.split(":").get(1))
    logInfo( "sunset Check", "INFO: Thing Name Line 44 =  '{}'", triggerEvent_split.split(":").get(2))
    logInfo( "sunset Check", "INFO: Thing Channel Line 45 =  '{}'", triggerEvent_split.split(":").get(3))
    logInfo( "sunset Check", "INFO: Thing Channel Line 46 =  '{}'", triggerEvent_split.split(":").get(3).split(" ").get(0))
    logInfo( "sunset Check", "INFO: Thing Channel Line 47 =  '{}'", 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 49 =  '{}'", triggerEvent_split_3 )
end

and in the third logInfo I used the above command and the Rule triggers and shows the following in the Logger:

2019-08-23 17:15:00.471 [INFO ] [.smarthome.model.script.sunset Check] - INFO: receivedEvent.class.getCanonicalName() --> [org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent], Event = 'START'
2019-08-23 17:15:00.478 [INFO ] [.smarthome.model.script.sunset Check] - INFO: receivedEvent.channel.toString()       --> [astro:sun:stowing1:noon#event], Event = 'START'
2019-08-23 17:15:00.486 [INFO ] [.smarthome.model.script.sunset Check] - INFO: receivedEvent.channel.toString()       --> [astro:sun:stowing1:noon#event], Event = 'START'
2019-08-23 17:15:00.489 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Channel Event = 'START'
2019-08-23 17:15:00.496 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Channel Name =  'astro:sun:stowing1:noon#event'
2019-08-23 17:15:00.505 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Channel UID =  'astro:sun:stowing1'
2019-08-23 17:15:00.511 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Channel ID =  'noon#event'
2019-08-23 17:15:00.518 [INFO ] [.smarthome.model.script.sunset Check] - INFO: receivedEvent.channel.toString() Line 37      --> [astro:sun:stowing1:noon#event], receivedEvent = 'astro:sun:stowing1:noon#event triggered START'
2019-08-23 17:15:00.522 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Trigger Line 42 =  'astro:sun:stowing1:noon#event triggered START'
2019-08-23 17:15:00.528 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Type Line 43 =  'sun'
2019-08-23 17:15:00.534 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Name Line 44 =  'stowing1'
2019-08-23 17:15:00.539 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Channel Line 45 =  'noon#event triggered START'
2019-08-23 17:15:00.548 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Channel Line 46 =  'noon#event'
2019-08-23 17:15:00.556 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Thing Channel Line 47 =  'noon'
2019-08-23 17:15:00.561 [INFO ] [.smarthome.model.script.sunset Check] - INFO: Split_3 ID Line 49 =  'noon#event triggered START'

The third INFO is the one used with receivedEvent.getEvent.toString() Command

I upgraded from 2.5.M1 to 2.5.M2 too. So for me it seems to work

The code has been working well on both 2.4 and 2.5 M1 so there is nothing new introduced, just made an upgrade to M2. The trigger channel gives the expected result which can be seen from the eventlog, an example is:

2019-08-23 17:31:56.544 [vent.ChannelTriggeredEvent] - mqtt:broker:zWaveBroker:zWaveTrigger triggered gzWave/Lum_FF_Corridor#473

Logically the trigger channel has no influence on this (because it is working) but the definition is made in PaperUI and the resulting json representation is:

“mqtt:broker:zWaveBroker”: {
“class”: “org.eclipse.smarthome.core.thing.internal.BridgeImpl”,
“value”: {
“label”: “MQTT ZWave Broker”,
“channels”: [
{
“kind”: “TRIGGER”,
“uid”: {
“segments”: [
“mqtt”,
“broker”,
“zWaveBroker”,
“zWaveTrigger”
]
},
“channelTypeUID”: {
“segments”: [
“mqtt”,
“publishTrigger”
]
},
“configuration”: {
“properties”: {
“stateTopic”: “gzWave/#”,
“separator”: “#”
}
},
“properties”: {},
“defaultTags”: []
}
],
“configuration”: {
“properties”: {
“publickeypin”: true,
“lastwill_qos”: 0,
“clientid”: “paho5333216496874”,
“qos”: 0,
“retain”: true,
“host”: “192.168.1.17”,
“secure”: false,
“certificatepin”: true,
“keep_alive_time”: 60000,
“reconnect_time”: 60000
}
},
“properties”: {},
“uid”: {
“segments”: [
“mqtt”,
“broker”,
“zWaveBroker”
]
},
“thingTypeUID”: {
“segments”: [
“mqtt”,
“broker”
]

The triggering item is a group item named gZwave.

Yes I have tried it (again). I changed the code to get something similar to yours:

rule “Receive mqtt from RPi7”
when
Channel “mqtt:broker:zWaveBroker:zWaveTrigger” triggered
then
/* The receivedEvent String contains unneeded elements like the mqtt topic, we only need everything after the “/” as this is were item name and state are */
//val parts1 = receivedEvent.toString.split("/").get(1)
val parts0 = receivedEvent.getEvent.toString()
val parts1 = parts0.split("/").get(1)
val parts2 = parts1.split("#")
postUpdate(parts2.get(0),parts2.get(1))
end

A trigger comes in as:

2019-08-23 17:53:32.256 [vent.ChannelTriggeredEvent] - mqtt:broker:zWaveBroker:zWaveTrigger triggered gzWave/Motion_FF_Corridor#ON

The log shows this for same timestamp:

2019-08-23 17:53:32.267 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Receive mqtt from RPi7’: ‘getEvent’ is not a member of ‘org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent’; line 461, column 16, length 22

So it is the same mystery still.

What I was actually fishing for was whether you used a publishTrigger channel type, or some other channel with trigger=true. The first, it seems.

It’s very odd, like the “wrong kind” of event. This may be a missed smarthome code migration. Do you have any imports in that rule file?

The imports are:

import org.eclipse.smarthome.core.library.types.DateTimeType
import org.eclipse.smarthome.core.library.types.DecimalType
import org.eclipse.smarthome.model.script.actions.Timer
import org.joda.time.DateTime
import org.joda.time.Duration

Thanks a lot for taking the time to assist me, wish I knew enought to troubleshoot it myself but this is closer to the inner workings of OpenHab and there I am lost.

I think all those imports need binning, except perhaps Duration, never seen that before.

Please excuse my ignorance but the term “binning” is unknown to me. Do you mean a fully qualified file name? These are imports which have been used for years so something must have changed to M2 then.

I think he means to remove them, as to throw away, or put in the bin. :slight_smile:

1 Like

Yep, “binning” colloquial for throw away, remove, delete.
In practice, comment out those lines // until you are satisfied you do not want them.

Yes, that is exactly what happened. M2 was all about removing smarthome code. The whole purpose of new versions is that something somewhere changed :smiley:

1 Like

Thanks @rossko57 and @Laufeyjarson! will try that.
(Made my first computer program in 1969, ought to have learnt most of the terms by now but obviously not, still alive though so have a chance to catch up :slight_smile: ).

I commented out all the imports and the code is working again. Many thanks to all participating in the discussion and especially to @rossko57 for guidance to a solution of the problem.

I had it working for a short time after cleaning the cache this morning but after that there was no progress until now.

I will check the logs for a few hours and then mark it as solved if OK

1 Like

That was a really non-obvious consequence of “old code”, good to sort it out.

1 Like