Dear users, (cc. @pvizeli),
This post is about a problem I have with setting up Hassio with Mosquitto MQTT and Owntracks. I’m running Hassio 49.1 on a RPi3. My Pi is connected to a router and that router is connected to a modem. I’m using Let’s Encrypt together with duckdns.
Setting up Mosquitto looks quite simple from the documentation available for Hassio, but I think, compared to the documentation in at the “components” page, there are many versions about doing things (I’m offering my help to make tutorials/explanations for the community).
I’ve tried to setup Mosquitto with Owntracks without TLS and that worked. I forwarded the port 1883 from my modem to the router, and from the router to my Pi. I could see in the logs receiving the location from my Owntracks instance on my Android phone. HA tracked my device .
The configuration I used for this is as follows:
Configuration of the Mosquitto MQTT broker Add-On.
{
"plain": true,
"ssl": false,
"anonymous": false,
"logins": [
{
"username": "xxx",
"password": "yyy"
}
],
"customize": {
"active": false,
"folder": "mosquitto"
},
"certfile": "fullchain.pem",
"keyfile": "privkey.pem"
}
The settings of my Owntracks android instance:
Mode: Private MQTT
Host:
host: myduckdns.duckdns.org
port: 1883
Use Websockets: NO
Identification:
Username: xxx
Password: yyy
Security:
TLS: No
Parameters:
No adjustments made.
In my config.yaml file, I did add the following things (Be aware of the differend broker IP than is used in the Hassio Mosquitto add-on website, somebody from Discord helped me figuring out that IP):
mqtt:
broker: 127.0.0.1
username: xxx
password: yyy
device_tracker:
- platform: owntracks
For debugging purposes I also have enabled this in my yaml file:
logger:
default: info
logs:
homeassistant.components.mqtt: debug
I also read here that I had to adjust the mqttProtocolLevel to 4, so I did.
When I look in the logs of HA, everythings looks fine and I receive messages, my Hassio sees my phone and makes a known_devices.yaml file. The logs of the Mosquitto MQTT Add-on looks as follows:
starting version 3.2.2
1501250464: mosquitto version 1.4.12 (build date 2017-06-01 13:03:48+0000) starting
1501250464: Config loaded from /etc/mosquitto.conf.
1501250464: Opening ipv4 listen socket on port 1883.
1501250464: Opening ipv6 listen socket on port 1883.
1501250464: Warning: Mosquitto should not be run as root/administrator.
1501250466: New connection from 172.17.0.1 on port 1883.
1501250466: New client connected from 172.17.0.1 as **asdfasdfasdf** (c1, k60, u'xxx').
1501250489: New connection from **mypublicip** on port 1883.
1501250489: Client xxxherolte disconnected.
1501250489: New client connected from mypublicip as xxxherolte (c0, k3600, u'xxx').
Now, when I switch to TLS some strange things happen. First I make sure I delete the known_devices.yaml file, since it should be created automatically again. I also adjust the port on my router and modem to 8883, as this port is used for TLS.
The configuration of the Mosquitto Add-On looks like this:
{
"plain": false,
"ssl": true,
"anonymous": false,
"logins": [
{
"username": "xxx",
"password": "yyy"
}
],
"customize": {
"active": false,
"folder": "mosquitto"
},
"certfile": "fullchain.pem",
"keyfile": "privkey.pem"
}
The settings in my Owntacks app are the following:
Mode: Private MQTT
Host:
host: myduckdns.duckdns.org
port: 8883
Use Websockets: NO
Identification:
Username: xxx
Password: yyy
Security:
TLS: Yes
Parameters:
No adjustments made.
The configuration in my config.yaml file looks like this:
mqtt:
broker: 127.0.0.1
username: xxx
password: yyy
device_tracker:
- platform: owntracks
logger:
default: info
logs:
homeassistant.components.mqtt: debug
My Owntracks app, in the status menu gives the following information:
Connected
Endpoint state
Not available
Endpoint state message
0
Endpoint queue
When I look in the logs of the Mosquitto Add-On I get the following:
starting version 3.2.2
1501251171: mosquitto version 1.4.12 (build date 2017-06-01 13:03:48+0000) starting
1501251171: Config loaded from /etc/mosquitto.conf.
1501251171: Opening ipv4 listen socket on port 8883.
1501251171: Opening ipv6 listen socket on port 8883.
1501251171: Warning: Mosquitto should not be run as root/administrator.
1501251197: New connection from **mypublicip** on port 8883.
1501251198: Client xxxherolte disconnected.
1501251198: New client connected from **mypublicip** as xxxherolte (c0, k3600, u'xxx').
In the logs I don’t see any location update from my Owntracks app. But as you can read, the app says it’s connected. If I push the queue message button in the upper right of the App, so it published my data to the MQTT broker, it does so, but I don’t receive anything.Since HA doesn’t get the messages from Owntracks, obviously, it didn’t make a new known_devices file.
Since the app says it has a connection and also the logfiles from the Add-on says there is a connection, I can safely assume that my portforwarding is working correctly.
Then there are 3 options left:
- I have to adjust the Mosquitto MQTT Add-on config file.
- I have to adjust the config.yaml file
- I have to import certificates to the Owntracks app.
My best guess it has something to do with all 3 of it, but because of the certificates I need to specify. In the Add-on config, there are already specified, certificates, as you can see.
I hope your expertise can help me further!
Yours sincerely,
Maharball