MQTT - Is OpenHab able to connect to Cloud MQTT services?

Everything I read implies the MQTT broker is running on localhost… This has me confused about how to configure OpenHAB for my particular use since I’m using a cloud-based MQTT broker.

I have a ESP8266 Arduino sketch that is communicating to my HVAC system of my vacation home (System isn’t compatible with the new web-thermostats, so I have to talk to its controller via RS485).

I’ve got the sketch complete and it publishes JSON info to CloudMQTT.com I have verified it all works. I can subscribe and publish just fine via MQTT.fx and with IOS app MQTT_Buddy.

The problem is these apps don’t seem to be able read the JSON payload. The person’s code I started with used OpenHAB and below is a link to his OpenHAB screen so you get an idea what I’m trying to accomplish.

How can I configure OpenHAB to read from CloudMQTT.com?

This is what the JSON payload contains: {“z1”:{“cool”:82,“heat”:67},“z2”:{“cool”:77,“heat”:67},“z3”:{“cool”:76,“heat”:68}}

And this was I’m trying to replicate is here: http://hvac-talk.com/vbb/showthread.php?204152-Carrier-Comfort-Zone-II-packet-data/page4

Openhab will connect to any mqtt server, just set the right address instead of localhost.

See the example configuration at
https://docs.openhab.org/addons/bindings/mqtt1/readme.html

As Jupiter wrote: if configuring your broker like in the docs it’s irrelevant on which machine the broker runs on - cloudmqtt works for me:

mqttcottage.url=tcp://m12.cloudmqtt.com:16595
#mqttcottage.url=ssl://m12.cloudmqtt.com:26595

hint: I couldn’t connect to cloudmqtt by using the ssl-service

I got it working:

1 Like

Can we interface only Node MCU(without using raspberry pi) with openHAB?

What do you mean?
You need an MQTT broker. You can run one on the Raspi or any other machine.

I appreciate the help. I believe I’ve set up the connection to Cloud MQTT based on your input but I don’t get a sense from the log that anything is happening.

This is my mqtt.cfg setup:
NikMQTT.url=tcp://m11.cloudmqtt.com:12355
NikMQTT.clientId=openhab2
NikMQTT.user=user (user is changed here to represent what mine is)
NikMQTT.pwd=password (password changed here)

Below is the log. I waited 4 minutes and then shut it down just to see if there might be log messages buffered and not written.

I have one test item configured but I see no indiction that anything happens with it. (And I’m not sure exactly where to see this in the OpenHAB UI since it’s a bit confusing what can be done in PaperUI, BasicUI, and HABPanel. (keep in mind this it my first attempt to use OpenHAB)

2018-04-18 08:00:23.032 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2018-04-18 08:00:24.475 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-04-18 08:00:24.507 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-04-18 08:00:24.570 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-04-18 08:00:24.738 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-04-18 08:00:24.739 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘nikmqtt’
2018-04-18 08:00:24.741 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:broker
2018-04-18 08:00:24.742 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:topic
2018-04-18 08:00:24.743 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:message
2018-04-18 08:04:16.634 [INFO ] [basic.internal.servlet.WebAppServlet] - Stopped Basic UI
2018-04-18 08:04:36.955 [INFO ] [penhab.io.transport.mqtt.MqttService] - Stopping broker connection ‘nikmqtt’
2018-04-18 08:04:36.990 [INFO ] [io.openhabcloud.internal.CloudClient] - Shutting down openHAB Cloud service connection
2018-04-18 08:04:37.035 [INFO ] [io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = 66159b0e-5578-4c8d-8ea5-a2393558a4f3, base URL = http://localhost:8080)
2018-04-18 08:04:37.249 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Stopped Paper UI
2018-04-18 08:04:37.254 [INFO ] [panel.internal.HABPanelDashboardTile] - Stopped HABPanel
2018-04-18 08:04:37.259 [INFO ] [er.internal.HomeBuilderDashboardTile] - Stopped Home Builder
2018-04-18 08:04:37.266 [INFO ] [.dashboard.internal.DashboardService] - Stopped dashboard

This is however early indications in the log that I’m connecting CloudMQTT (or am I not interpreting the log correctly).

2018-04-17 17:52:58.298 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘nikmqtt’
2018-04-17 17:52:58.302 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:broker
2018-04-17 17:52:58.303 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:topic
2018-04-17 17:52:58.303 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:message
2018-04-17 19:48:28.898 [ERROR] [o.client.mqttv3.internal.ClientState] - openhab2: Timed out as no write activity, keepAlive=60,000 lastOutboundActivity=1,524,006,178,515 lastInboundActivity=1,524,006,178,565 time=1,524,012,508,888 lastPing=1,524,006,178,515
2018-04-17 19:48:32.187 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to broker was lost
org.eclipse.paho.client.mqttv3.MqttException: Timed out while waiting to write messages to the server
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31) [208:org.openhab.io.transport.mqtt:1.11.0]
at org.eclipse.paho.client.mqttv3.internal.ClientState.checkForActivity(ClientState.java:672) [208:org.openhab.io.transport.mqtt:1.11.0]
at org.eclipse.paho.client.mqttv3.internal.ClientComms.checkForActivity(ClientComms.java:732) [208:org.openhab.io.transport.mqtt:1.11.0]
at org.eclipse.paho.client.mqttv3.internal.ClientComms.checkForActivity(ClientComms.java:718) [208:org.openhab.io.transport.mqtt:1.11.0]
at org.eclipse.paho.client.mqttv3.TimerPingSender$PingTask.run(TimerPingSender.java:77) [208:org.openhab.io.transport.mqtt:1.11.0]
at java.util.TimerThread.mainLoop(Timer.java:555) [?:?]
at java.util.TimerThread.run(Timer.java:505) [?:?]
2018-04-17 19:48:32.553 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to ‘nikmqtt’ was lost: Timed out while waiting to write messages to the server : ReasonCode 32002 : Cause : Unknown
2018-04-17 19:48:32.553 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker ‘nikmqtt’
2018-04-17 19:48:42.560 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘nikmqtt’

2018-04-18 08:00:24.739 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘nikmqtt’

tells you, the broker connection is up and running -


2018-04-18 08:04:36.955 [INFO ] [penhab.io.transport.mqtt.MqttService] - Stopping broker connection ‘nikmqtt’

as the Connection is gracefully shut down at 08.04 I suspect you shut openHAB2 service down.

the day before I suspect you had some difficulties with your Internet conenction as there were multiple timeouts.

Please read through the whole MQTT-documentation and Keep in mind, we’re talking about at least three completely different things which have MQTT in the name:

  1. MQTT-binding: https://docs.openhab.org/addons/bindings/mqtt1/readme.html
    basically items connected/publishing via MQTT
  2. MQTT-eventbus: https://docs.openhab.org/addons/bindings/mqtt1/readme.html#event-bus-binding-configuration
    basically an Extended eventbus between two distinct OH2 instances
  3. MQTT-Actions: https://docs.openhab.org/addons/actions/mqtt/readme.html
    using MQTT to publish something in a rule
  4. MQTT-persistence: https://docs.openhab.org/addons/persistence/mqtt/readme.html
    basically sending item changes in a persitence strategy (no restoreonstartup or previousstate() or whatever - write only)

The cloudMQTT port is 14879

Thanks… While I think I’ve read every piece of OpenHAB documentation with MQTT in the title, I think I lack the context for where to configure and test if it’s working or not. Especially where can I see it in a UI?

From the first document - I can assume my binding is correct since the log indicates it connecting.

Do I need to configure the MQTT-event bus to see subscribed payload in OpenHAB? I’ve assumed no as I assumed my instance of OpenHAB should be able to subscribe to the MQTT message whether there is an event bus or not. I may not fully understand the bus if that’s not the case.

I’m only trying to read a subscription at this point, so I’m wasn’t worried about the Actions document. I wanted to walk first then, take the next step.

Same for persistence, I’ve assume this can come after I at least have proof of subscribing successfully.

Please correct my assumptions if I’m lacking understanding.

If the log says it’s connected, then where do I need to go to see the subscribed MQTT payload? Since I see nothing in the log and I can see information updated via other means like MQTT.fx I’m at a loss.

I appreciate the help. I think the real power I’m after is the map function where I can interpret some of my JSON payload, but first I just want to get basic things working to make sure I understand it.

I think, that’s your first misconception (sorry!) - openHAB is a backend system - period.
you have a PaperUI, which purpose is mainly configuration of the backend
you have a Habmin, which purpose is to gather a bit more “frontend-ish” Information
you can configure a sitemap, which displays its information in BasicUI or the App.
you can configure a complex UI within HABPanel

so - without some configuration: you will not see something in a UI at all.

that being said:

  • mqtt-eventbus is to publish/subscribe your event-bus with another oh-instance (but you can use it to “inject” information from external sources
  • read-and-write information (subscription/configuration) can be configured on item-Level[1]
  • persistence is only needed, if you want OH2-items to be published to the Broker

so - Keep in mind openHAB is a backend system - simply having a API in place between openHAB and a broker doesn’t mean anything. There would be no “Magic” to have MQTT topics somehow shown up within openHAB. That’s why you don’t see anything in the log yet!

[1] From your use case as I understand, you need to define items, which subscribe to MQTT topics and get updated by it. Within item configuration you can already have JSON-Transformation. Please read the MQTT-binding docu on this. You won’t need persistence or actions or event-bus just the binding.

Thanks Thomas,

It’s becoming a bit clearer about what each component does. (backend vs. front end).

I really stumbled in to OpenHAB because a GibHub project I started with used it (but gave no information about how). I have a perception that it does some things that other MQTT clients don’t such as mapping and interpreting JSON. I like how OpenHAB enables this to be consolidated instead of defining multiple MQTT topics for each individual value.

Ultimately, this is the end picture of what I’m trying to get to. I think from your input, I need to define this information in a Sitemap to end up where I need to be. Correct?

I’m running OpenHAB on my Mac and I noticed when I started the BASIC UI it says I have no sitemaps.

I created one before I went to BASIC UI so I’m curious why it doesn’t thing I have one.

I’m running on MAC and when I go to the terminal window with the openhab prompt to see if it knows where my config files are I get this.

openhab> echo $OPENHAB_CONF
null
openhab>

I’m assuming that this should be set somewhere and that’s why it’s not finding my configurtions for items and sitemaps. (it does however seem to know where to write log files and it sees my MQTT.cfg just fine).

Let me know if you think this is contributing to my issue.

from the Looks you Need:

  • for each temperature and Action a seperate item
  • populate the item 1:1 from a JSON payload via MQTT
  • alternatively have one JSON payload and split the payload for each item
  • put the items in a sitemap (including the Chart)

no! :wink:

Thanks for your patience.

I found where this configuration is displayed on Mac once I used the system:property command. I’m slowly learning as I dig in further than I thought I would have to.

I also found my items and sitemap files had a hidden filename extension (added my the mac text editor) added therefore the systems wasn’t recognizing them… I’m making progress.

1 Like