0.76.2 MQTT configuration issues, silently failing

Hey guys, I seem to be having issues configuring an external MQTT broker on home-assistant 0.76.2 (on hassio rpi3). The broker is running on a server and is accessible from the local network. It’s configured to only allow TLS using a self-signed certificate.

The first issue I have is that I cannot set the root ca certificate in the config YAML. The documentation clearly states I should set the certificate property (which should be the path of the root ca certificate file). Whenever I configure home-assistant like this:

mqtt:
  broker: my.broker.tld
  port: 8883
  username: !secret mqtt_username
  password: !secret mqtt_password
  certificate: /path/to/ca.crt

It fails to configure the MQTT component (and all dependencies) with the following error:

Invalid config for [mqtt]: not a valid value for dictionary value @ data['mqtt']['certificate']. Got '/path/to/ca.crt'. (See /config/configuration.yaml, line 92). Please check the docs at https://home-assistant.io/components/mqtt/

I couldn’t find any solution for this, so I tried removing the certificate config and just setting tls_insecure to true. This appears to work at first glance, looking at the logs:

2018-08-31 09:19:05 INFO (MainThread) [homeassistant.setup] Setting up mqtt
2018-08-31 09:19:05 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=mqtt, service=publish>
2018-08-31 09:19:05 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 0.2 seconds.
Config directory: /config
[Errno 104] Connection reset by peer
2018-08-31 09:19:05 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=mqtt>
2018-08-31 09:19:05 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server

But when testing the component by publishing a message to the broker, I’m not receiving anything in subscribers. The logs don’t show any errors:

2018-08-31 09:21:52 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=homeassistant/switch/1/on, payload_template=Switch is ON>
2018-08-31 09:21:52 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]>

Home-assistant also doesn’t seem to be receiving any messages (from OwnTracks for instance).

The only odd thing I see in the logs is the very generic and not so informative [Errno 104] Connection reset by peer message.
I tested the credentials and the access to the topic using a different client, and all is working there. What am I missing?

I wonder if this is related with the HBMQTT problem I am seeing with stats from a heat pump.
http://forum.husdata.se/viewtopic.php?f=40&t=282&sid=3a47fd7662c5b3a2894c18e8ae65b83b

If I use a Windows client to publish a topic, that is picked up by HA. However, something has changed whereby the monitoring interface does not seem to publish the metrics since the last update.

I shall continue investigating!

There is a change associated with the embedded broker and API password which, frankly, I do not understand. But you are using an external broker.

The embedded broker is not using the http.api_password setting anymore, and now requires its own mqtt.password property to be set.
This does not affect me however, as you already stated, since I’m using an external broker.

How do I set the mqtt.password property? There is not much about that in the docs.

If I use the MQTT dev tools to publish a topic for the heat pump, that is recognised by the MQTT part of Home Assistant. I managed to get over a “Broken pipe” error by sticking a loop in the code but I am having to learn fast about this!

Are you using a QOS other than zero?

Make sure the password property is set like so:

mqtt:
  password: your_password_goes_here

I haven’t gotten to any QoS settings yet. I’m not able to send or receive any messages, so I’ll need to fix that first.

Thanks for the info. I had already set that in HA. I have just found out that if I use the Windows client to publish a specific topic as if it came from the heat pump, HA picks it up immediately. I think the initial connection to the broker works as I tried altering the port and it picks up the exception. I assume that, as the program publishing the metrics is running under Pi user and it connects ok, there cannot be an authentication problem. It is as if the broker is not receiving any published message from the python prog. I am new to MQTT but have years of experience of Websphere MQ so not a complete novice.

Sussed it eventually! I discovered that using an external broker (iot.eclipse.org), the publishing worked a treat. The problem is down to needing a function call to explicitly set the username and password for the client connection. I rationalised a lot of the MQTT code in an attempt to simplify the calls and it is working now.

Thanks for your help though.

Oh - I did not get any failed status returned from the connect call which must have been failing. There must be a way to trap such exceptions so I will research it.

Are you using a secure (TLS) connection to the broker?

This is still an issue on 0.77.3…

Hi, Had the same problem with homeassistant not seeing my MQTT certificate.
I put the ca.crt here: /root/config/ca.crt. And had specified certificate: /root/config/ca.crt which yielded an error.

Leaving the cert in /root/config and removing the path was the magic for me.

mqtt:
  certificate: ca.crt
  <etc etc>