How do I configure the embedded broker using config files when using the new mqtt binding?

I’m trying to use the new mqtt binding together with the embedded broker.
My impression is, that I can only use the systemBroker for the embedded broker. If I define a normal broker everything is online but no messeges get through. Using the systemBroker it sort of work but I need to first create the broker connection in the PaperUI and the add my item file.
If I change anything in the item file everything goes offline. The I have to delete the sytemBroker connection in PaperUI, move the item file away, readd the systemBroker connection in PaperUI and move the item file back.

This is (part of) my item file:

    Bridge mqtt:systemBroker:embedded-mqtt-broker
    {
        Thing topic RollladenBad "Rollladen Bad" @ "home" {
        Channels:
            Type rollershutter : RollladenBad "Rollladen Bad" [ 
                stateTopic="shellies/shellyswitch-13560B/roller/0/pos",
                transformationPattern="JS:reverse_rollershutter.js",
                commandTopic="shellies/shellyswitch-13560B/roller/0/command/pos"
            ]
        }
    }

I also tried adding the systemBroker as described here:

mqtt:systemBroker:embedded-mqtt-broker [ host="127.0.0.1", secure=false ]

but that did not help.

Maybe something to do with a bug in the 2.x mqtt binding? If you make a change in the files you will need to restart OH for the mqtt to start working again.

Restarting the binding, openhab or the complete server does not fix the problem. Only deleting and re adding helps.

I created everything in files and its working fine no issues. Here’s what I’ve converted from 1.x to 2.x so far.

Things

Bridge mqtt:broker:pibroker "pibroker" [ host="10.0.1.10", port=1883, secure=false, username="yourusername", password="passwordhere" ]
{
    // Sonoffs
    Thing topic sonoff11 "Living Room Light" @ "Living Room" {
    Channels:
        Type switch : power       "Power"         [ stateTopic="stat/sonoff11/POWER", commandTopic="cmnd/sonoff11/POWER" ]
        Type number : temperature "Temperature"   [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature" ]
        Type number : humidity    "Humidity"      [ stateTopic="tele/sonoff11/SENSOR", transformationPattern="JSONPATH:$.SI7021.Humidity" ]
    }

    Thing topic sonoff2 "Couch Light" @ "Couch Light" {
    Channels:
        Type switch : power        "Power"         [ stateTopic="stat/sonoff2/POWER", commandTopic="cmnd/sonoff2/POWER" ]
    }

    Thing topic sonoff55 "Office Light" @ "Office" {
    Channels:
        Type switch : power        "Power"         [ stateTopic="stat/sonoff55/POWER", commandTopic="cmnd/sonoff55/POWER" ]
    }

    Thing topic sonoff-7CB10D "Front Porch Light" @ "Porch" {
    Channels:
        Type switch : power        "Power"         [ stateTopic="stat/sonoff-7CB10D/POWER", commandTopic="cmnd/sonoff-7CB10D/POWER" ]
    }
}

Items

Switch LivingRoom_Light "Living Room Light" <light>  ["Lighting"] { channel="mqtt:topic:pibroker:sonoff11:power" }
Number LivingRoom_Light_Temp "Temperature [%.1f °F]"      <temp>             { channel="mqtt:topic:pibroker:sonoff11:temperature" }
Number LivingRoom_Light_Humidity    "Humidity [%.1f %%]"    <humidity>       { channel="mqtt:topic:pibroker:sonoff11:humidity" }

Switch CouchLight "Couch Light" <light>  ["Lighting"]  { channel="mqtt:topic:pibroker:sonoff2:power" }

Switch OfficeLight "Office Light" <light>  ["Lighting"]  { channel="mqtt:topic:pibroker:sonoff55:power" }

Switch FrontPorch_Light "Front Porch Lights" <light>  ["Lighting"]  { channel="mqtt:topic:pibroker:sonoff-7CB10D:power" }
	

When converting the only issue I ran into was “power” in the items file needed to be lower case. Hope the example helps.

After reviewing the example, if your still having issues, please post all the things, and items you have. Maybe someone can spot the issue.

1 Like

Thanks for your help, but I think you misunderstood my problem:

  1. I’m using the embedded broker. I’ve seen several examples using the new binding with an external broker in the config file such as you. I’ve also seen the documentation about using the embedded broker using PaperUI. What I miss is a working example using the embedded broker with config files.

  2. My configuration works. It just breaks if I change anything, e.g. only the display name

  3. The problem is reproducible with the thing file above (although I usually have more of the same in there) The content of the item file doesn’t change anything but for the record here it is:

Rollershutter RollladenBad    "Rollladen Bad"    <blinds> {channel="mqtt:topic:RollladenBad:RollladenBad"}

My impression is, that either there is a bug in the mqtt2 binding or I’m doing something wrong with how I define the systemBroker.

When everything is offline, the broker shows “UNINITIALIZED - HANDLER_CONFIGURATION_PENDING” and the item shows “UNINITIALIZED - BRIDGE_UNINITIALIZED”

I get several java errors in the log file when changing the thing file:

openhab.log
2019-01-25 15:26:09.809 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'Runnable.run()' on 'org.eclipse.smarthome.core.thing.internal.ThingManagerImpl$$Lambda$396/18352649@7fef1a': 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.GeneratedMethodAccessor93.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-25 15:26:09.868 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'Runnable.run()' on 'org.eclipse.smarthome.core.thing.internal.ThingManagerImpl$$Lambda$396/18352649@183686c': 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.GeneratedMethodAccessor93.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-25 15:26:09.926 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'Runnable.run()' on 'org.eclipse.smarthome.core.thing.internal.ThingManagerImpl$$Lambda$396/18352649@1e32cc6': 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.GeneratedMethodAccessor93.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-25 15:26:09.960 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'Runnable.run()' on 'org.eclipse.smarthome.core.thing.internal.ThingManagerImpl$$Lambda$396/18352649@1a22a30': 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.GeneratedMethodAccessor93.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-25 15:26:10.138 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mqtt.things'
2019-01-25 15:26:11.437 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'mqtt.things'

Maybe this link will help with the embedded broker config.

I also miss this this information. i.e “How could the embedded broker’s parameters be configured using the text files?”. The parameters are well defined in the docs but no an example which points out how and in which file.

@David_Graeff could you shine some light on this?

I do not support using text files for openHAB and strongly encourage everyone not to use any form of text files as they are competing with the internal database introduced with openHAB 2. I’m the wrong person to speak too, I’m afraid.

I found Embedded MQTT broker can be configured into the runtime.cfg file:

org.eclipse.smarthome.mqttembeddedbroker:port=1883
org.eclipse.smarthome.mqttembeddedbroker:username=username
org.eclipse.smarthome.mqttembeddedbroker:password=password
org.eclipse.smarthome.mqttembeddedbroker:secure=true/false
org.eclipse.smarthome.mqttembeddedbroker:persistence_file=file_path

You will see all the parameters entered in the config file also in PaperUI->Configuration->Services->MQTT-> MQTT Embedded Broker

1 Like

I agree with David that configuring a.o. mqtt things via paper UI is less vunerable as you can´t make unsystematic mistakes. Under Papier UI /Controls my things work perfectly ok, but rewriting them into files is really a pain and I still don´t have a functionable config.

BUT … in order to use the openhab APP, which relies to the view of the basicUI it still nessecary to keep the file based structure. … if I´m wrong please correct me!!

Welcome ro the openHAB Forum.

In order to show a sitemap you need a .sitemap file, all other file-types (.items and .things) are not needed.

But it would be good if there was way to use embedded MQTT server with files descriptions, at least for things, if one need to add many single type things or changed something in them then text file way more convenient than clicking mouse, especially if one need to use text files in any case (sitemap and rules). I probably know workaround - use external MQTT server (probably I will need it in any case because internal does not work with security connection automatically after installation).