Mosquitto MQTT 4.1 doesnt work after update

Are you restarting Hass between changes?

Example:
Remove all set mqtt configs, restart Hass.

Then. Setup the Mqtt broker 4.2 and the ACL files, Maybe a restart here as well, or just try to set up the integration from side panel.

I feel like I’ve tried everything including using a new install on a spare sd card i’m wondering if its a problem with mqtt v 4.3

I did some poking around, because I saw differences between Hass installations. Specifically between a Dockerized install under ubuntu 18.04 and a VM install of Hass.os.

Under a VM Hass.io after setting up Mqtt broker 4.3 and the Mqtt integration side panel. I checked the contents of the file “config.storage\core.config_entries” and the file contained this for the mqtt config (and this is after setting up the addon mqtt broker):

        "connection_class": "local_push",
        "data": {
            "broker": "core-mosquitto",
            "discovery": false,
            "password": "pu3Saigh8Ohghom9muezae6seexaidoopheleighe4suVaich6oF1peeWooxohNi",
            "port": 1883,
            "protocol": "3.1.1",
            "username": "homeassistant"
        },
        "domain": "mqtt",
        "entry_id": "6f3c90647b1d4d459aa5fe322f2cc4e0",
        "options": {},
        "source": "hassio",
        "title": "Mosquitto broker",
        "version": 1
    }

My Dockerized hass install has the following mqtt seetings in the file “core.config_entries”:

        "connection_class": "local_push",
        "data": {
            "broker": "127.0.0.1",
            "discovery": true,
            "password": "mqttPassWord",
            "port": 1883,
            "username": "hassuser1"
        },
        "domain": "mqtt",
        "entry_id": "67ebb49c4c3243a6c5ba87c39c5c2132",
        "options": {},
        "source": "user",
        "title": "127.0.0.1",
        "version": 1

Both I have setup to use the addon Mqtt broker. However the VM hass.io set the broker to the internal broker.

Very odd.

Maybe backup and edit the “config.storage\core.config_entries” to point to the addon broker?

Ok I did not realizes there is a difference in setting up a Hass.io (on a Rpi) and the addon Mqtt broker then on other variants of hass.

If you are useing Hass.IO you NEED to add the Mqtt stuff to your configuration.yaml.
Something like:

mqtt:
  broker: 127.0.0.1
  port: 1883
  username:USER
  password: PASSWORD

Sorry I did not realize the fundamental configuration differences between install variants.
I believe adding that config bit will solve the troubles.

Hope that helps.

If you are using the inbuilt Hass.io addon broker then you do not require ANY settings in configuration.yaml You do not need and should remove any mqtt: section.

If you added (as you have) a Home Assistant User to Home Assistant, you can use that username and password for MQTT. A LOCAL user for MQTT is defined in the addon settings and only there. If you use a Home Assistant user then you just leave the user settings in the broker blank.

You would also add the MQTT integration. If you select to use MQTT discovery then check the box. It won’t ask for any other details like brokers or user/password. If you have your MQTT broker on a different machine then that’s a different story.

Make sure if you add or remove the integration that you then restart home assistant.

So its come to this a you tube video showing what im doing or not doing as the case may be,

brand new Hassio install on a raspberry pi 3 B+ 32bit just samba was installed before the recording…

Try lowercase for the username in accesscontrollist
Other than that I have the identical configuration.

ALSO… in the Hassio Users> my MQTT user is MQTT-User but the actual logon name is mqttuser - they don’t have to be the same… The name and the username can be different
image

Ive tried changing the user name to all lower case and also tried a different one, i can’t believe I’m the only one with this problem ? i’m truly stumped

Just an update on this I eventually got it working by changing the IP address of my raspberry pi causing a change in the mqtt ip used, interestingly I still couldn’t get integrations to work however with the mqtt settings in configuration.yaml it did work and I’m now on 4.3 at long last.
Not sure why this made it work perhaps some sort of conflict with the original ip ??

Shout out to @DavidFW1960 for taking the time to remotely look at my install and help me get things up and running, Thankyou

1 Like

Ok turns out i’m still having problems however i have narrowed it down to my google wifi mesh network… if i plug my raspberry pi directly into my modem router (before my mesh network) it works and mqtt integrates, if i plug it into the network after my modem (the one that features various switches and 5 google mesh nodes) it will not integrate ?? any suggestions

I’m on version 4.3 and what @cogneato suggested on March 13 worked for me. This is my first attempt at using MQTT on HA. The client connects to the broker as you’d expect but nothing would get written when I published. I’m using the default config but this time I went and created a user in configuration > user and that is what used and the user id and password when creating the connection to the broker. That fixed the issue… Thank you all

New Hass.io install here, installed within a docker container.

My issue seems even weirder - going into the integrations page for MQTT, nada. Nothing to select, not even a tick box.

For now I’ve just installed Mosquitto seperately in its own container.

Finally got it working with the latest 5 addon version.

The steps:

  1. Install MQTT broker plugin
  2. In the config enter the following:
{
  "logins": [
    {
      "username": "mqttm",
      "password": "mqttm"
    }
  ],
  "anonymous": true,
  "customize": {
    "active": true,
    "folder": "mosquitto"
  },
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"
}

You can turn anonymous false, as it appears that this function doesnt work (at least for me)
3. save config and start mqtt
4.create file
/share/mosquitto/acl.conf with contents

acl_file /share/mosquitto/accesscontrollist

and /share/mosquitto/accesscontrollist with contents

user mqttm
topic readwrite #
user homeassistant
topic readwrite #

change user name with yours
5. save everything
6.restartt Hassio
Do not need to enter anything in configuration to get it working.
I have tested with a couple of clients.

in configuration added a dummy sensor

sensor:
  - platform: mqtt
    state_topic: "home/minde/temp"
    name: "MQTT Sensor 1"

after rebooting sent the mqtt message from another raspberry pi:

mosquitto_pub -h 192.168.0.101 -t home/minde/temp -u "mqttm" -P "mqttm" -m 75

and it worked.
mqttsensor

Hope this helps.

4 Likes

Thanks for this! It worked so far. One small thing, it wasn’t clear you had to run the Configure in Integrations with discovery not ticked. Again thank you so so much!

1 Like

You need to tick discovery in integrations.

It works without if you’re happy to use define in yaml

I tried this set up in 5.0 and appear to still be having issues. Here is my log. Any ideas?

[13:54:14] INFO: Setup mosquitto configuration
[13:54:14] WARNING: SSL not enabled - No valid certs found!
[13:54:15] INFO: Found local users inside config
[13:54:16] INFO: Initialize Hass.io Add-on services
[13:54:16] INFO: Initialize Home Assistant discovery
[13:54:16] INFO: Start Mosquitto daemon
1562439256: Loading config file /share/mosquitto/acl.conf
1562439256: mosquitto version 1.6.3 starting
1562439256: Config loaded from /etc/mosquitto.conf.
1562439256: Loading plugin: /usr/share/mosquitto/auth-plug.so
1562439256: |-- *** auth-plug: startup
1562439256: ├── Username/password checking enabled.
1562439256: ├── TLS-PSK checking enabled.
1562439256: └── Extended authentication not enabled.
1562439256: Opening ipv4 listen socket on port 1883.
1562439256: Opening ipv6 listen socket on port 1883.
1562439256: Opening websockets listen socket on port 1884.
1562439256: Warning: Mosquitto should not be run as root/administrator.
1562439256: New connection from 192.168.0.101 on port 1883.
[INFO] found user on local database

Recent mosquitto has given me nothing but headaches. It seems to mangle all the packet/payloads. After attempting a bunch of suggestions here I looked for other possibilities and just wanted to share that I have installed emqx as a docker container and have no issues. (I run hassio/ha as docker containers on an aarch64 box) The community version is in active maintenance.


https://hub.docker.com/r/emqx/emqx
docker run -dit --restart always  --name emqx-mqtt-broker -p 18083:18083 -p 1883:1883 emqx/emqx:latest 

Up side is that emqx runs a nice dashboard 18083 (admin/public login).

Hello everyone. I am very new to all of this and have one final hurdle left before I am fully up and running. I am almost finished!! But I am getting stuck where everyone else is on this page. I can’t get mqtt to connect AND I have no previous snapshots. If someone could please point me in the right direction, I will give you unlimited amounts of good karma!!

I am running MQTT 5 and have user and password set.

MQTT config:

{
  "logins": [
    {
      "username": "mqtt_admin",
      "password": "beatles"
    }
  ],
  "anonymous": false,
  "customize": {
    "active": true,
    "folder": "mosquitto"
  },
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"
}

Config-yaml code:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

sensor 1:
  platform: mqtt
  state_topic: 'DHT22-1/sensor1'
  name: 'Temperature'
  unit_of_measurement: '°F'
  value_template: '{{ value_json.temperature }}'

sensor 2:
  platform: mqtt
  state_topic: 'DHT22-1/sensor1'
  name: 'Humidity'
  unit_of_measurement: '%'
  value_template: '{{ value_json.humidity }}'

Why did you ever put that in config yaml file??? That is part of the ACL configuration.