Mosquitto + OH2 - I can not finish the configuration

  • Platform information:
    • Hardware: RP3+
    • OS: openhabian
    • openHAB version: 2.4

Hi, need some help at the end of the OH2 + mosquitto configuration process.

  • I have configured openhab2
  • Until now I used only Ikea Tradfri
  • I’m configuring mqtt today

I launched mosquitto as described: https://www.smarthomeblog.net/mqtt-openhab/

I added in:

default.things

Bridge mqtt:broker:mosquitto [
host = “10.10.100.88”
port = “1883”
secure = false
username = “openhabian”
password = “secret”
ClientID = “openhab”
]

default.items

Number mqtt_aquarium_temperature “Aquarium Temperature [% .1f]” {mqtt = “<[mosquitto:majula/robert/aquarium/temperature_sensor:state:default]”}

default.sitemap

Text item = mqtt_aquarium_temperature icon = “temperature”

and, I created:
mqtt.cfg in the “services” directory

mosquitto.url=tcp: //10.10.100.88: 1883
mosquitto.qos=1
mosquitto.retain=true
mosquitto.async=false
mosquitto.clientID=openhab
mosquitto.user=openhabian
mosquitto.pwd=secret

Now

I connected to openhab using SSH - in two sessions

1 / in the first I entered: mosquitto_pub -d -u openhabian -P secret -t “majula/robert/aquarium/temperature_sensor” -m 25

2 / in the second I entered: mosquitto_sub -v -u openhabian -P secret -t “majula/robert/aquarium/temperature_sensor”

I received the result: majula/robert/aquarium/temperature_sensor 25

In my opinion everything works correctly

But in basicui I still have:

Why?

Thanks in advance for your help.

This is an openHAB MQTT binding version 2 configuration.

This is an openHAB MQTT binding version 1 configuration.

You’ve probably mixed parts of two tutorials.

You can use either binding version, but if starting out it would be best to go with v2 (using things and channels) and not v1 (using mqtt=)

You need to install the correct binding version.

OK, I read this:

I corrected:

default.things

Bridge mqtt: broker: mosquitto [
host = “10.10.100.88”
port = “1883”
secure = false
username = “openhabian”
password = “16394306”
clientID = “openhab”]
{
Thing topic aquarium
{
channels:
Type string: temperature “Temperature in aquarium” [stateTopic = “temperature_height”]
}
}

and default.items

Number AquariumTemperature “Aquarium temperature” {channel = “mqtt: topic: mosquitto: aquarium: temperature”}

and default.sitemap

Frame label = “Aquarium”
{
Switch item = ControlOutlet1 label = “Outlet Aquarium Light”
Switch item = ControlOutlet6 label = “Outlet Aquarium Fetilizer”
Switch item = ControlOutlet3 label = “Outlet Aquarium Air Pump”
Text item = AquariumTemperature label = “Temperature in Celcius” icon = "temperature"
}

I entered in putty on my openhab:

mosquitto_pub -u openhabian -P secret -t aquarium/temperature/temperature_height -m 1234

And it still does not work :frowning:

What am I doing wrong ?

Your thing is set up to look for
aquarium/temperature/somevalue
so far as I can see

Have you looked in openhab.log to see if the connection to your broker is established?

You’ve two different passwords in default.things file and your manual mqtt publishing.
Firstly: Is your broker connection is online? Pls check on paper-ui. OH’s broker connection must able to login to mqtt server, and subscribe to topics, what you defined as channels under that.
Second: Your temp sensor is well configured? In this case the sensor has to send temp values via mqtt. You could check it, if you download mqtt.fx application, connect it to the mosquitto service, and subscribe to #. You should see every mqtt messages in the app.
When everything is ready, your sensor will connect to mqtt server, and publish temp values to the configured topic. Your OH also connects to the mqtt server, and subscribe to this topic. When an mqtt message arrives to the mqtt server, the subscribed channel gets it, and write to the item, what you defined in your items file. You can check it step by step with mqtt.fx app, OH’s log viewer and OH’s paper ui.
mqtt.fx download link: https://mqttfx.jensd.de/index.php/download

OK - I’m desperate. Because I have 2x RP3 at home, I made a clean installation on the second RP3.

I have only 4 files:

default.things

// MQTT
Bridge mqtt:broker:mosquitto [
host=“10.10.100.88”,
port=“1883”,
secure=false,
username=“openhabian”,
password=“16394306”]
{
Thing topic aquarium
{
Channels:
Type string : temperature “Temperature in aquarium” [ stateTopic=“temperature_height”]
}
}

default.items

// MQTT 2.0

Number AquariumTemperature “Aquarium temperature” { channel=“mqtt:topic:mosquitto:aquarium:temperature” }

default.sitemap

sitemap default label=“Majula” {
// Aquarium
Frame label=“Aquarium”
{

Text item=AquariumTemperature label=“Temperature in Celcius” icon=“temperature”
}
}

mqtt.cfg

mosquitto.url=tcp://10.10.100.88:1883

mosquitto.qos=1

mosquitto.retain=true

mosquitto.async=false

mosquitto.user=openhabian

mosquitto.pwd=16394306

Let’s start!

After running - my logs:

[21:18:53] openhabian@openHABianPi:/var/log/mosquitto$ cat mosquitto.log
1562007758: mosquitto version 1.4.10 (build date Wed, 13 Feb 2019 00:45:38 +0000) starting
1562007758: Config loaded from /etc/mosquitto/mosquitto.conf.
1562007758: Opening ipv4 listen socket on port 1883.
1562007758: Opening ipv6 listen socket on port 1883.
1562007779: New connection from 10.10.100.174 on port 1883.
1562007779: New client connected from 10.10.100.174 as 4a471e603ba14ac683d0ef9b6b8129dd (c1, k60, u’openhabian’).
1562007813: New connection from 10.10.100.88 on port 1883.

[21:21:25] openhabian@openHABianPi:/var/log/openhab2$ cat openhab.log
2019-07-01 21:03:05.530 [WARN ] [.MqttBrokerConnectionServiceInstance] - MqttBroker connection configuration faulty: host : You need to provide a hostname/IP!
2019-07-01 21:03:07.479 [INFO ] [ebuilder.internal.HomeBuilderServlet] - Started Home Builder at /homebuilder
2019-07-01 21:03:07.493 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Time zone set to ‘Poland’.
2019-07-01 21:03:07.512 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Location set to ‘51.666,19.6838’.
2019-07-01 21:03:07.524 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Locale set to ‘en_PL’.
2019-07-01 21:03:07.527 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Measurement system set to ‘SIUnits’.
2019-07-01 21:03:14.573 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2019-07-01 21:03:18.065 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = 635baac3-5139-404d-bbd9-62a5c4d8da4f, base URL = http://localhost:8080)
2019-07-01 21:03:25.147 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘default.items’
2019-07-01 21:03:28.803 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2019-07-01 21:03:29.736 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘default.rules’
2019-07-01 21:03:29.773 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘default.rules’ is either empty or cannot be parsed correctly!
2019-07-01 21:03:30.365 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘default.sitemap’
2019-07-01 21:03:30.779 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘default.things’
2019-07-01 21:03:31.849 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://10.10.100.88:8080
2019-07-01 21:03:31.853 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://10.10.100.88:8443
2019-07-01 21:03:32.291 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2019-07-01 21:03:32.809 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin servlet at /habmin
2019-07-01 21:03:33.392 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to ‘10.10.100.88’ with clientid paho54054852791 and file store ‘/var/lib/openhab2/mqtt/10.10.100.88’

[21:21:30] openhabian@openHABianPi:/var/log/openhab2$ cat events.log
2019-07-01 21:03:31.035 [.ItemChannelLinkAddedEvent] - Link ‘AquariumTemperature-mqtt:topic:mosquitto:aquarium:temperature’ has been added.
2019-07-01 21:03:31.156 [hingStatusInfoChangedEvent] - ‘mqtt:topic:mosquitto:aquarium’ changed from UNINITIALIZED to UNINITIALIZED (BRIDGE_UNINITIALIZED)
2019-07-01 21:03:33.163 [hingStatusInfoChangedEvent] - ‘mqtt:broker:mosquitto’ changed from UNINITIALIZED to INITIALIZING
2019-07-01 21:03:33.282 [hingStatusInfoChangedEvent] - ‘mqtt:broker:mosquitto’ changed from INITIALIZING to OFFLINE
2019-07-01 21:03:33.312 [hingStatusInfoChangedEvent] - ‘mqtt:topic:mosquitto:aquarium’ changed from UNINITIALIZED (BRIDGE_UNINITIALIZED) to INITIALIZING
2019-07-01 21:03:33.361 [hingStatusInfoChangedEvent] - ‘mqtt:topic:mosquitto:aquarium’ changed from INITIALIZING to OFFLINE (BRIDGE_OFFLINE)
2019-07-01 21:03:33.453 [hingStatusInfoChangedEvent] - ‘mqtt:broker:mosquitto’ changed from OFFLINE to ONLINE
2019-07-01 21:03:33.471 [me.event.ThingUpdatedEvent] - Thing ‘mqtt:broker:mosquitto’ has been updated.
2019-07-01 21:03:33.480 [hingStatusInfoChangedEvent] - ‘mqtt:topic:mosquitto:aquarium’ changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE

Now a few pictures:

Then in putty on the openhab:

mosquitto_pub -u openhabian -P 16394306 -t aquarium/temperature/temperature_height -m 25

I received:

In my opinion so far everything is OK.

But in basicUI still - nothing

Ok, we are close :slight_smile:
Delete the mqtt.cfg from /etc/openhab2/services. This is a mqtt v1 configuration, you don’t need it.
The state topic on your .things file is short a bit. On mqtt.fx, you can see the topic, where the value arrives: aquarium/temperature/temperature_height . Change your .things file:
From:

Type string : temperature “Temperature in aquarium” [ stateTopic=“temperature_height”]

To:

Type string : temperature “Temperature in aquarium” [ stateTopic=“aquarium/temperature/temperature_height”]

Finally, change your .items file from:

Number AquariumTemperature “Aquarium temperature” { channel=“mqtt:topic:mosquitto:aquarium:temperature” }

to:

Number AquariumTemperature “Aquarium temperature [%.2f °C]” { channel=“mqtt:topic:mosquitto:aquarium:temperature” }

The short explanation (IMHO): Your thing sends the mqtt message to the longer topic, but you subscribe with OH to a short one. The two topics are different, that’s why your item remains empty. You have to use the same string as state topic, what your thing use to send the proper value. If you configure your sensor, you can set anything, as mqtt topic, but you have to use that full topic in your .things file.

For the final check, ssh to your OH, and type the command:

openhab-cli console

…and there issue the command:

items list

You’ll see your configured items, and it’s current value also. If everything works, the events.log will show you also, when your item gets the new value.

For some reason you’ve chosen to link a string type channel to a number type Item.
While you are investigating it would be best to link the channel to a String type Item - you can add one using the same channel without removing your existing number type.

I think you have to be more explicit here and give the full topic (the Thing topic is just making up an internal name for OH)

Type string : temperature “Temperature in aquarium” [ stateTopic=“aquarium/temperature/temperature_height”]

I apologize for the absence, unfortunately my wife forced me to a small renovation in our house ;). Then I completely reconfigured my network at home, created several VLAN’s, I launched the WPA Enterprise authentication in the part of WIFI and … the IKEA Tradfri has stopped working. Today I found topic on UBNT community ( https://community.ui.com/questions/USG-ikea-tradfri-connection-issues/efc09532-a808-4c43-86cf-2bb5e6573635 ).

As soon as I deal with Tradfri, I will return to MQTT. For now, thank you for your help, but please follow this topic - if I run MQTT, I will be proud of it, or I will continue to ask how to do it;)