Having trouble setting up MQTT

Hello,
I am trying to get started with MQTT in Home Assistant, but I am running into trouble. So far I have:

  1. Installed the Mosquitto MQTT broker add-on
  2. Set up a new user called “mqttuser”
  3. Flashed Tasmota on a 3-relay light switch
  4. Configured MQTT in Tasmota

It seems like it is connecting to Home Assistant, but auto discovery is not working and neither is manually creating a switch entity in the config file.
MQTT Add-On Log:

[19:34:49] INFO: Setup mosquitto configuration
[19:34:49] WARNING: SSL not enabled - No valid certs found!
[19:34:49] INFO: No local user available
[19:34:49] INFO: Initialize Hass.io Add-on services
[19:34:49] INFO: Initialize Home Assistant discovery
[19:34:49] INFO: Start Mosquitto daemon
1590546889: mosquitto version 1.6.3 starting
1590546889: Config loaded from /etc/mosquitto.conf.
1590546889: Loading plugin: /usr/share/mosquitto/auth-plug.so
1590546889:  ├── Username/password checking enabled.
1590546889: |-- *** auth-plug: startup
1590546889:  ├── TLS-PSK checking enabled.
1590546889:  └── Extended authentication not enabled.
1590546889: Opening ipv4 listen socket on port 1883.
1590546889: Opening ipv6 listen socket on port 1883.
1590546889: Opening websockets listen socket on port 1884.
1590546889: Warning: Mosquitto should not be run as root/administrator.
1590546889: New connection from 192.168.1.21 on port 1883.
[INFO] found mqttuser on Home Assistant
1590546890: New client connected from 192.168.1.21 as mqtt-explorer-a2fcf87a (p2, c1, k60, u'mqttuser').
1590546896: New connection from 192.168.1.11 on port 1883.
1590546896: New client connected from 192.168.1.11 as DVES_7F0E2B (p2, c1, k30, u'mqttuser').
1590546992: New connection from 172.30.32.1 on port 1883.
[WARN] Not found homeassistant on local database
1590546993: Socket error on client <unknown>, disconnecting.

MQTT Configuration:

logins: []
anonymous: false
customize:
  active: false
  folder: mosquitto
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false

Tasmota Console (while attempting manual config):

03:34:55 MQT: Attempting connection...
03:34:55 MQT: Connected
03:34:55 MQT: tele/SW_LRoom/LWT = Online (retained)
03:34:55 MQT: cmnd/SW_LRoom/POWER = 
03:35:39 MQT: tele/SW_LRoom/STATE = {"Time":"2020-05-27T03:35:39","Uptime":"0T00:50:09","UptimeSec":3009,"Heap":26,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":4,"POWER1":"ON","POWER2":"OFF","POWER3":"OFF","Wifi":{"AP":1,"SSId":"NetworkOT_Downstairs","BSSId":"B6:FB:E4:AB:C9:E3","Channel":11,"RSSI":98,"Signal":-51,"LinkCount":1,"Downtime":"0T00:00:03"}}```

Any ideas what I’m doing wrong?

Tasmota is connected (as the snippet indicates)

  • what .bin did you flash ? Not all versions of Tasmota support auto-discovery
  • did you enter the command setoption19 1 in the tasmota console ?

looks good

can show us you
switch config

should look some like this

  - platform: mqtt
    name: "SpareRoom"
    state_topic: "stat/SW_LRoom/POWER"
    command_topic: "cmnd/SW_LRoom/POWER"
    availability_topic: "tele/SW_LRoom/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"

snap @francisp about the setoption19 1

I used Tuya-Convert, so I started with the .bin that was included in that. I believe it was tasmota.bin v8.1.x. I tried setoption19 1 with that .bin and didn’t see the entities in Home Assistant, so I upgraded to the latest release, v8.3.1, and tried setoption19 again, but still no auto-discovery.

   - platform: mqtt
     name: "LivingRoomSwitch1"
     state_topic: "stat/SW_LRoom/POWER1"
     command_topic: "cmnd/SW_LRoom/POWER1"
     availability_topic: "tele/SW_LRoom/LWT"
     qos: 1
     payload_on: "ON"
     payload_off: "OFF"
     payload_available: "Online"
     payload_not_available: "Offline"

This is what my config looked like when I was testing the manual config option. This method created the entity, but it appeared as unavailable.

Ok, go to developer tools -> mqtt

First under ‘Topic to subscribe to’, enter # , and click start listening.

Then, under ‘Publish a packet’, enter test, next to payload ‘on’, and click publish

What do you see now under start listening ?


Nothing pops up under start listening. Should I have seen something?
I also went and checked the Add-On logs, and this error fills the entire log file:

1590616591: New connection from 172.30.32.1 on port 1883.
[WARN] Not found homeassistant on local database
1590616592: Socket error on client <unknown>, disconnecting.
1590616712: New connection from 172.30.32.1 on port 1883.
1590616712: Socket error on client <unknown>, disconnecting.
1590616832: New connection from 172.30.32.1 on port 1883.
1590616832: Socket error on client <unknown>, disconnecting.

I appreciate the help with debugging.

Yes, you should have seen the message appearing as soon as you hit ‘publish’. So HA is not listening to your broker.
Besides the add-on (you posted the config in the first post), how did you configure the broker in HA ? Through the integration or manually in configuration.yaml ?

Looks like there is no valid homeassistant system user.

[WARN] Not found homeassistant on local database
1590546993: Socket error on client <unknown>, disconnecting.

I just used the UI integration to configure and enable auto-discovery. I think you’re right about HA not listening to the broker, but I’m not sure how that could have happened.

1 Like

Weird. Maybe that is the problem. Do you see a homeassistant user when you go to Configuration -> Users?

Yes I do.

Interesting. My User is called Hass.io. I don’t think I am able to edit that.

Checked my 3 HA instances. All 3 have hass.io, none have homeassistant.

Screenshot_2020-05-28 Configuration - Home Assistant

There’s a specific instruction not to use homeassisstant as the mqtt user. So it must be used for something. What? :man_shrugging:

Hmm. Sounds like @francisp does not have a homeassistant user and doesn’t have problems, but @tom_l does. I’m really not sure what else to do to try and fix the problem. Any ideas?

same problem here. any solution?

same problem too… Im using a raspberry pi 4 8gb… so the system is 64bits, is there any issues about it?

change “anonymous: true” in mosquito config file

1 Like

anonymous: true worked for me but…

I found out from here: https://youtu.be/1uxRvbbd0fc?t=497 that the MQTT integration automatically sets the username to homeassistant.

I’m assuming the user used to exist before the internal MQTT broker was removed?. Anyway, hitting “Reconfigure” on the MQTT integration, and using a specifically created new user (and its password) works with no problems and means anonymous can be set to false once again.

1 Like