MQTT 2.5.0 Need Help getting this binding to work

Hi, I am trying to get the MQTT binding to work with openHAB2.5.0 Build 1568, on windows

I have turned off all persistence in my openHAB2 configuration. I just want to get MQTT working!!

Any assistance would be very much appreciated.

I have read through this URL (https://www.openhab.org/blog/2018-12-16-mqtt-arrives-in-the-modern-openhab-2-x-architecture.html) and other forum topics but I am still confused on some aspects of getting this to work.

Here is my problem, I have 18 devices I want to talk to via MQTT topics.

I want to install the MQTT embedded broker “moquette” to be the MQTT broker on my local system.

I, also, want to configure openHAB2.5.0 via configuration files but it appears that the system will not read these config files and automatically connect up the MQTT channels to the MQTT embedded broker.

So I believe my setup must be wrong. That is why I am here asking for assistance.

Question 1, if I am using the embedded moquette broker do I need a moquette.cfg file defined in c:/openHAB2/conf/services??

Here is how I presently have my moquette.cfg file:

service.pid="org.eclipse.smarthome.mqttembeddedbroker"
name="moquette"
username=""
password=""
clientID=""
host="192.168.0.12"
secure=false

From c:/openHAB2/conf/services here is my addons.cfg file:

# The installation package of this openHAB instance
# Note: This is only regarded at the VERY FIRST START of openHAB
# Note: If you want to specify your add-ons yourself through entries below, set the package to "minimal"
# as otherwise your definition might be in conflict with what the installation package defines.
#
# Optional. If not set, the dashboard (https://<yourserver>:8080/) will ask you to choose a package.
#
# Valid options:
#   - minimal  : Installation only with dashboard, but no UIs or other add-ons. Use this for custom setups.
#   - simple   : Setup for using openHAB purely through UIs - you need to expect MANY constraints in functionality!
#   - standard : Default setup for normal users, best for textual setup
#   - expert   : Setup for expert users, especially for people migrating from openHAB 1.x
#   - demo     : A demo setup which includes UIs, a few bindings, config files etc.
#
# See https://www.openhab.org/docs/configuration/packages.html for a detailed explanation of these packages.
#
package = standard

# Access Remote Add-on Repository
# Defines whether the remote openHAB add-on repository should be used for browsing and installing add-ons.
# This not only makes latest snapshots of add-ons available, it is also required for the installation of
# any legacy 1.x add-on. (default is true)
#
remote = true

# Include legacy 1.x bindings. If set to true, it also allows the installation of 1.x bindings for which there is 
# already a 2.x version available (requires remote repo access, see above). (default is false)
#
legacy = true

# A comma-separated list of bindings to install (e.g. "binding = sonos,knx,zwave")
binding = wemo,ntp,hue,expire1,wifiled,mqtt

# A comma-separated list of UIs to install (e.g. "ui = basic,paper")
ui = dashboard,habpanel,basic,classic,habmin,paper

# A comma-separated list of persistence services to install (e.g. "persistence = rrd4j,jpa")
#persistence = jdbc-mysql

# A comma-separated list of actions to install (e.g. "action = mail,pushover")
#action = 

# A comma-separated list of transformation services to install (e.g. "transformation = map,jsonpath")
#transformation = 

# A comma-separated list of voice services to install (e.g. "voice = marytts,freetts")
#voice = 

# A comma-separated list of miscellaneous services to install (e.g. "misc = myopenhab")
#misc = openhabcloud

and my runtime.cfg file:

##################### LOCALE ####################

# The default language that should be used. If not specified, the system default locale is used.
# The ISO 639 alpha-2 or alpha-3 language code (if there is no alpha-2 one).
# Example: "en" (English), "de" (German), "ja" (Japanese), "kok" (Konkani)
#
org.eclipse.smarthome.core.localeprovider:language=en

# The region that should be used.
# ISO 3166 alpha-2 country code or UN M.49 numeric-3 area code.
# Example: "US" (United States), "DE" (Germany), "FR" (France), "029" (Caribbean)
#
org.eclipse.smarthome.core.localeprovider:region=US

################ PERSISTENCE ####################

#  The persistence service to use if no other is specified.
#
#org.eclipse.smarthome.persistence:default=jdbc

################### AUDIO #######################

# This parameter defines the default audio source to use (if not set, the first available one will be used.
#
#org.eclipse.smarthome.audio:defaultSource=

# This parameter defines the default audio sink to use (if not set, the first available one will be used.
#
#org.eclipse.smarthome.audio:defaultSink=

##################### VOICE ####################

# This parameter defines the default text-to-speech service to use (if not set, the first available one will be used.
#
#org.eclipse.smarthome.voice:defaultTTS=

# This parameter defines the default speech-to-text service to use (if not set, the first available one will be used.
#
#org.eclipse.smarthome.voice:defaultSTT=

# The default voice to use if no specific TTS service or voice is specified.
#
#org.eclipse.smarthome.voice:defaultVoice=

# The default human language interpreter to use if no other is specified.
#
#org.eclipse.smarthome.voice:defaultHLI=

################ MISCELLANOUS ####################

# The karaf sshHost parameter configures the bind address for the ssh login to karaf.
# Default is 127.0.0.1 (localhost), so it is only possible to login from the local machine.
#
# Setting this to the address of another network interfaces will allow login from this network.
# Setting this to 0.0.0.0 will allow login from all network interfaces.
#
# !!! Security warning !!!
#   Remember to change default login/password, if you allow external login.
#   See https://www.openhab.org/docs/administration/console.html for details.
#
org.apache.karaf.shell:sshHost = 0.0.0.0

# Setting this to true will automatically approve all inbox entries and create Things for them,
# so that they are immediately available in the system (default is false)
#
org.eclipse.smarthome.inbox:autoApprove=false

# This setting allows to switch between a "simple" and an "advanced" mode for item management.
# In simple mode (autoLinks=true), links and their according items are automatically created for new Things.
# In advanced mode (autoLinks=false), the user has the full control about which items channels are linked to.
# Existing links will remain untouched. (default is true)
#
org.eclipse.smarthome.links:autoLinks=false

Now to the file that defines the connection between the Moquette Embedded broker and the Generic MQTT thing and its corresponding MQTT channels:

My mqtt.things file located on my shared google drive:

mqtt.things file

Here is my mqtt.items file, also located on my shared google drive:

mqtt.items file

Here is my mqtt.rules file, also located on my shared google drive:

mqtt.rules file

Can some help me figure out what I am doing wrong, I would hate to have to type in all these again manually through the paper UI.

The use of the “Simple Mode” in conjunction with .things and .items file could produce the unexpected behaviour (automatically connect…)
I’d switch off the Simple Mode as well as the AutoApprove.

I believe I have those both turned off already, any other ideas?

I need to see an example of a MQTTbridge.things file and a MQTT.items files

Example

If things have been autl-approved and items have been auto-created and -linked you need to delete them via PaperUI.

I have not created any of these things through the paper UI. This is a brand new reinstall of openhab 2.

my whole system is defined in the configuration files.

I am starting to think, I might have to create the items by hand which I would hate to do because of the sheer number of channels I want to create

I hear your point: If I created the items via the paper UI i need to delete them before creating them in the config files

To be specific, items and things created by PaperUI can to be deleted on PaperUI, those that are created by files can not be deleted there.

My comment about deleting things and items was referring to those that were automatically created ( while the Simple Mode and Auto Approve Mode were on). They are NOT automatically deleted but they are saved, so YOU need to delete them.

I did that, I deleted them and now only creating them through the .things and .items file

Still can not get the system embedded broker to start with ONLINE form the .thing file. I can go in and manually create it in Paper UI and it shows online but if I delete it then try to create it in the .things file, the system embedded broker will never show ONLINE.

so at this point I am going to use mosquitto as a system broker and forget about the system-embedded-broker “Moquette”. I want to see if I can get it working that way. I know my mosquitto broker is working because I can test it without openhab2 running. I can send commands to my device and see the values come back from my devices to the correct mqtt topic. I use mqtt-spy to see the response coming back from the device.

So when openHAB2 is running, I will not be using mqtt-spy, but mosquitto will be running and my hope is that I can get openHAB2 to talk to my local copy of mosquitto

Why not using mqtt-spy while openHAB is running? I’m using MQTTFx for the same task while openHAB is running!
And why aren’t you using your “main” Broker? If Mosquitto is working, openHAB (or better the MQTT bindig) will work with this broker! Just use the correct IP and credentials!

Well I finally figured it out!!!

Here is my addons.cfg. Notice that mqtt is added as a “binding” AND to get the Moquette embedded broker you must add misc = mqttbroker to the misc= line in addons.cfg

# The installation package of this openHAB instance
# Note: This is only regarded at the VERY FIRST START of openHAB
# Note: If you want to specify your add-ons yourself through entries below, set the package to "minimal"
# as otherwise your definition might be in conflict with what the installation package defines.
#
# Optional. If not set, the dashboard (https://<yourserver>:8080/) will ask you to choose a package.
#
# Valid options:
#   - minimal  : Installation only with dashboard, but no UIs or other add-ons. Use this for custom setups.
#   - simple   : Setup for using openHAB purely through UIs - you need to expect MANY constraints in functionality!
#   - standard : Default setup for normal users, best for textual setup
#   - expert   : Setup for expert users, especially for people migrating from openHAB 1.x
#   - demo     : A demo setup which includes UIs, a few bindings, config files etc.
#
# See https://www.openhab.org/docs/configuration/packages.html for a detailed explanation of these packages.
#
package = standard

# Access Remote Add-on Repository
# Defines whether the remote openHAB add-on repository should be used for browsing and installing add-ons.
# This not only makes latest snapshots of add-ons available, it is also required for the installation of
# any legacy 1.x add-on. (default is true)
#
remote = true

# Include legacy 1.x bindings. If set to true, it also allows the installation of 1.x bindings for which there is 
# already a 2.x version available (requires remote repo access, see above). (default is false)
#
legacy = false

# A comma-separated list of bindings to install (e.g. "binding = sonos,knx,zwave")
binding = wemo,ntp,hue,expire1,wifiled,mqtt

# A comma-separated list of UIs to install (e.g. "ui = basic,paper")
ui = paper,dashboard,habpanel,basic,classic,habmin

# A comma-separated list of persistence services to install (e.g. "persistence = rrd4j,jpa")
#persistence = jdbc-mysql

# A comma-separated list of actions to install (e.g. "action = mail,pushover")
#action = 

# A comma-separated list of transformation services to install (e.g. "transformation = map,jsonpath")
#transformation = 

# A comma-separated list of voice services to install (e.g. "voice = marytts,freetts")
#voice = 

# A comma-separated list of miscellaneous services to install (e.g. "misc = myopenhab")
misc = mqttbroker 

IMPORTANT

you than must MANUALLY ADD the Moquette-embedded-broker to the paper UI by doing a auto discovery on the MQTT binding. They paper UI will add the Moquette embedded-broker to your inbox.

If you try to just have the definition of the bridge defined in the .things file, openhab2 will NOT bring it on line.

After you manually add the Moquette MQTT broker (systemBroker:embedded-mqtt-broker) to your configuration you can now load the .things file which has the bride defined in it. Openhab2 will display the following warning in the log file:

 [WARN ] [core.common.registry.AbstractRegistry] - Cannot add "BridgeImpl" with key "mqtt:systemBroker:embedded-mqtt-broker". It exists already from provider "ManagedThingProvider"! Failed to add a second with the same UID from provider "GenericThingProvider"!

Its just a warning, ignore it. Now the system will attach you channels and .item files like it would normally.

Here is an example of my mqtt_embedded.things file:

Bridge         mqtt:systemBroker:embedded-mqtt-broker                             "Moquette System Embedded MQTT Broker"        @ "Family Room"                          [host="localhost", secure=false, retain=false, url="localhost:1883" ] {
// IMPORTANT: do no have another process using the 1883 port on your computer if you plan to use the systemBroker:embedded-mqtt-broker "Moquette"
// to use the embedded-mqtt-broker (Moquette) in openhab2, one must first add it MANUALLY via the paper UI then you can add channels to it
// The openhab2 log file will complain because the SystemBroker was added manually so you will see this log message : 
//      [WARN ] [core.common.registry.AbstractRegistry] - Cannot add BridgeImpl with key mqtt:systemBroker:embedded-mqtt-broker. It exists already from provider ManagedThingProvider! Failed to add a second with the same UID from provider GenericThingProvider!
// If you try use the .things file without adding the MQTT SystemBroker manually, openHAB2 will show the MQTT System Broker as UNINITIALIZED(HANDLER_CONFIGURATION_PENDING) or UNINITIALIZED (HANDLER_MISSING_ERROR)
//Therfore, I stress again that one needs to add the embedded-mqtt-broker (Moquette) via the PAPER UI FIRST before using the .things file

Thing  topic Generic_Moquette_MQTT_Thing                                                               "Generic Moquette MQTT Thing"  @ "Family Room"          {                         
        Channels:
                Type    switch : Test_Smart_Plug_MQTT                                                   "Test Smart Plug MQTT Channel"                                                                                                                          [ stateTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/state", commandTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/command", on="1", off="0" ]
                Type    switch : Test_Smart_Plug_USB_MQTT                                               "Test Smart Plug - USB Port MQTT Channel"                                                                                                               [ stateTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/state", commandTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/command", on="{ \"dps\": 7, \"set\": true }", off="{ \"dps\": 7, \"set\": false }" ]
                Type    switch : Test_Smart_Plug_GET_MQTT                                               "Test Smart Plug MQTT STATUS Channel"                                                                                                                   [ stateTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/state", commandTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/command", on="{ \"schema\": true }", off="{ \"schema\": true }" ]
    
                Type    switch : Light90_MQTT_Light_Bulb                                                "Light90 MQTT Light Bulb Channel"                                                                                                                       [ stateTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/state", commandTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/command", on="1", off="0" ]
                Type    switch : Light90_GET_MQTT                                                       "Light90 MQTT STATUS Channel"                                                                                                                           [ stateTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/state", commandTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/command", on="{ \"schema\": true }", off="{ \"schema\": true }" ]
                Type    string : Light90_Color_MQTT                                                     "Light90 Color MQTT Channel"                                                                                                                            [ stateTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/state", commandTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/color"]

    }
}

Here is my example of mqtt_embedded.items file:

//GROUPS 
Group                           gTuyaLight90Color                           "Tuya Light90 Color Group"                                      <lightbulb>
Group                           gTuyaLight90Attrib                          "Tuya Light 90 Attribute Group"                                  

// Manually update all tuya devices
Switch                          All_Tuya_Device_CommStart                   "Manually Send Get Command to All Tuya Devices"

//Test Smart Plug
Switch                          Test_Smart_Tuya_Plug                        "Test Smart Plug"                                               <switch>                                                                                                                        {channel="mqtt:topic:embedded-mqtt-broker:Generic_Moquette_MQTT_Thing:Test_Smart_Plug_MQTT"}
Switch                          Test_Smart_Tuya_Plug_CommStart              "Test Smart Plug Establish MQTT Commuication"                   <switch>                                                                                                                        {channel="mqtt:topic:embedded-mqtt-broker:Generic_Moquette_MQTT_Thing:Test_Smart_Plug_GET_MQTT"}                 
Switch                          Test_Smart_Tuya_Plug_USB_Port               "Test Smart Plug USB Port"                                      <switch>                                                                                                                        {channel="mqtt:topic:embedded-mqtt-broker:Generic_Moquette_MQTT_Thing:Test_Smart_Plug_USB_MQTT"}

// Light90 Tuya Color Smart Bulb 
Switch                          Light90_Tuya_Smart_Bulb                     "Light 90 EleLight Color Tuya Smart Bulb"                       <switch>                                      (gAll)                                                                           {channel="mqtt:topic:embedded-mqtt-broker:Generic_Moquette_MQTT_Thing:Light90_MQTT_Light_Bulb"}
Switch                          Light90_Tuya_CommStart                      "Light 90 EleLight Color Establish MQTT Commuication"           <switch>                                                                                                                       {channel="mqtt:topic:embedded-mqtt-broker:Generic_Moquette_MQTT_Thing:Light90_GET_MQTT"}                 
Color                           Light90_colorpicker                         "Light 90 EleLight Color Picker"                                <colorpicker>                                                                                                                  
Dimmer                          Light90_level                               "Light 90 White Level [%s %%]"                                  <slider>
String                          Light90_color                               "Light 90 Color Select [%s]"                                                                                  (gTuyaLight90Color)                                                              {channel="mqtt:topic:embedded-mqtt-broker:Generic_Moquette_MQTT_Thing:Light90_Color_MQTT"}             

If you want to use Mosquitto as your MQTT broker, than you can configure that totally from the .things file and .items file.

Here is my example of Mosquitto_Broker.things file:

Bridge         mqtt:broker:mosquitto                             "Mosquitto MQTT Broker"        @ "Family Room"                          [  publickeypin=false, lastwill_qos=0, retain=false, secure=false, certificatepin=false, keep_alive_time=60000, qos=2, host="192.168.0.12", reconnect_time=60000 ] {


Thing  topic Generic_Mosquitto_MQTT_Thing                                                               "Generic Mosquitto MQTT Thing"  @ "Family Room"          {                         
        Channels:
                Type    switch : Test_Smart_Plug_MQTT                                                   "Test Smart Plug MQTT Channel"                                                                                                                          [ stateTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/state", commandTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/command", on="1", off="0" ]
                Type    switch : Test_Smart_Plug_USB_MQTT                                               "Test Smart Plug - USB Port MQTT Channel"                                                                                                               [ stateTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/state", commandTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/command", on="{ \"dps\": 7, \"set\": true }", off="{ \"dps\": 7, \"set\": false }" ]
                Type    switch : Test_Smart_Plug_GET_MQTT                                               "Test Smart Plug MQTT STATUS Channel"                                                                                                                   [ stateTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/state", commandTopic="tuya/socket/67833830cc50e3d57eaa/beb06ceb0fed2edb/192.168.0.46/command", on="{ \"schema\": true }", off="{ \"schema\": true }" ]
                
                Type    switch : Light90_MQTT_Light_Bulb                                                "Light90 MQTT Light Bulb Channel"                                                                                                                       [ stateTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/state", commandTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/command", on="1", off="0" ]
                Type    switch : Light90_GET_MQTT                                                       "Light90 MQTT STATUS Channel"                                                                                                                           [ stateTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/state", commandTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/command", on="{ \"schema\": true }", off="{ \"schema\": true }" ]
                Type    string : Light90_Color_MQTT                                                     "Light90 Color MQTT Channel"                                                                                                                            [ stateTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/state", commandTopic="tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/color"]
   
     }
}

Here is my example of Mosquitto_Broker.items file:

//GROUPS 
Group                           gTuyaLight90Color                           "Tuya Light90 Color Group"                                      <lightbulb>
Group                           gTuyaLight90Attrib                          "Tuya Light 90 Attribute Group"                                  

// Manually update all tuya devices
Switch                          All_Tuya_Device_CommStart                   "Manually Send Get Command to All Tuya Devices"

//Test Smart Plug
Switch                          Test_Smart_Tuya_Plug                        "Test Smart Plug"                                               <switch>                                                                                                                        {channel="mqtt:topic:mosquitto:Generic_Mosquitto_MQTT_Thing:Test_Smart_Plug_MQTT"}
Switch                          Test_Smart_Tuya_Plug_CommStart              "Test Smart Plug Establish MQTT Commuication"                   <switch>                                                                                                                        {channel="mqtt:topic:mosquitto:Generic_Mosquitto_MQTT_Thing:Test_Smart_Plug_GET_MQTT"}                 
Switch                          Test_Smart_Tuya_Plug_USB_Port               "Test Smart Plug USB Port"                                      <switch>                                                                                                                        {channel="mqtt:topic:mosquitto:Generic_Mosquitto_MQTT_Thing:Test_Smart_Plug_USB_MQTT"}

// Light90 Tuya Color Smart Bulb 
Switch                          Light90_Tuya_Smart_Bulb                     "Light 90 EleLight Color Tuya Smart Bulb"                       <switch>                                      (gAll)                                                                           {channel="mqtt:topic:mosquitto:Generic_Mosquitto_MQTT_Thing:Light90_MQTT_Light_Bulb"}
Switch                          Light90_Tuya_CommStart                      "Light 90 EleLight Color Establish MQTT Commuication"           <switch>                                                                                                                       {channel="mqtt:topic:mosquitto:Generic_Mosquitto_MQTT_Thing:Light90_GET_MQTT"}                 
Color                           Light90_colorpicker                         "Light 90 EleLight Color Picker"                                <colorpicker>                                                                                                                  
Dimmer                          Light90_level                               "Light 90 White Level [%s %%]"                                  <slider>
String                          Light90_color                               "Light 90 Color Select [%s]"                                                                                  (gTuyaLight90Color)                                                              {channel="mqtt:topic:mosquitto:Generic_Mosquitto_MQTT_Thing:Light90_Color_MQTT"}