MQTT Binding 2.4 ClassCastException

At the moment I’m using the old MQTT binding to controll some Sonoff Tasmota devices. After upgrading to openHAB 2.4 I wanted to switch to the new MQTT 2 binding, but I didn’t get it working. I can’t controll the device and I don’t see any messages on the broker. This is my mqtt.things:

Bridge mqtt:broker:MqttBroker [ host="photon-machine", secure=false, port=1883 ]
{
    Thing topic sofa {
    Channels:
        Type switch : switch "Power Switch" [ stateTopic="stat/sofa/POWER", commandTopic="cmnd/sofa/POWER" ]
     }
}

and the mqtt.items:

Switch SofaNew_On "Sofa On MQTT2" (Wohnzimmer) { channel="mqtt:topic:MqttBroker:sofa:switch" }

Whenever I change something in the things file I get the following message in the logs:

2019-01-18 21:15:51.699 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'Runnable.run()' on 'org.eclipse.smarthome.core.thing.internal.ThingManagerImpl$$Lambda$692/1461730391@128923': org.eclipse.smarthome.binding.mqtt.generic.internal.handler.GenericThingHandler cannot be cast to org.eclipse.smarthome.binding.mqtt.handler.AbstractBrokerHandler
java.lang.ClassCastException: org.eclipse.smarthome.binding.mqtt.generic.internal.handler.GenericThingHandler cannot be cast to org.eclipse.smarthome.binding.mqtt.handler.AbstractBrokerHandler
	at org.eclipse.smarthome.binding.mqtt.internal.MqttBrokerHandlerFactory.lambda$0(MqttBrokerHandlerFactory.java:83) ~[?:?]
	at java.util.WeakHashMap.forEach(WeakHashMap.java:1025) ~[?:?]
	at java.util.Collections$SynchronizedMap.forEach(Collections.java:2647) ~[?:?]
	at org.eclipse.smarthome.binding.mqtt.internal.MqttBrokerHandlerFactory.removeHandler(MqttBrokerHandlerFactory.java:83) ~[?:?]
	at org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory.unregisterHandler(BaseThingHandlerFactory.java:261) ~[?:?]
	at org.eclipse.smarthome.core.thing.internal.ThingManagerImpl.lambda$5(ThingManagerImpl.java:811) ~[?:?]
	at sun.reflect.GeneratedMethodAccessor95.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [102:org.eclipse.smarthome.core:0.10.0.oh240]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [102:org.eclipse.smarthome.core:0.10.0.oh240]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
2019-01-18 21:15:51.735 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mqtt.things'
2019-01-18 21:15:51.743 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'photon-machine' with clientid paho2941222602831 and file store '/openhab/userdata/mqtt/photon-machine'
2019-01-18 21:15:52.767 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'mqtt.things'
2019-01-18 21:15:52.832 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'photon-machine' with clientid paho2942309173314 and file store '/openhab/userdata/mqtt/photon-machine'

Can this be the reason why it does not work and does anyone know how to solve the problem?

If you are not on SNAPSHOT, there is a bug and everytime you edit the things file, you will need to restart OH

Thanks for this information, it works after restartign OH. I did not think of that.

I’m on the official release 2.4, not on a snapshot. Do you know if this is only a problem of the MQTT binding, so that I could use the binding from a snapshot? Is there an official bug for this?

Yes only the binding
Please tick the solution thanks

It is actually a more complicated error in this case. mqtt broker and mqtt thing are two separate bindings. And they were not on the same version for whatever reason, therefore the class cast exception.

A restart of OH resolved it for you. Perfect :slight_smile:

Hi,
I’ve exactly the same problem on my setup.

Debian 9 with OH2.4

dpkg -l|grep openh
ii openhab2 2.4.0-1 all openhab2
ii openhab2-addons 2.4.0-1 all openhab2-addons

openhab> bundle:list|grep MQ
201 │ Active │ 80 │ 1.2.0 │ Paho MQTT Client
204 │ Active │ 80 │ 0.10.0.oh240 │ Eclipse SmartHome MQTT Binding
205 │ Active │ 80 │ 0.10.0.oh240 │ Eclipse SmartHome MQTT Thing Binding
210 │ Active │ 80 │ 0.10.0.oh240 │ Eclipse SmartHome MQTT Transport Bundle

After changing the mqtt.things file I get the same exception.
Is there allready a fix in progress?

Restarting OH2 every time isn’t the best idea when I see that every restart all my KNX GAs will be polled.

Same here, i’m on STABLE, too and this happens to me all the time. I didn’t found a bug on GitHub, should i create one?

It works on snapshots. OH does not backport fixes to specific release versions.