MQTT Problems

How to know if i am running the default mqtt broker or mosquitto i installed?

I have this in my config:

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_username
  password: !secret mqtt_password
  discovery: true
  discovery_prefix: homeassistant

Sorry if this an obvious question but i need to learn many things about mqtt and i am having serious problems installing 0.101.3 due to mqtt errors…

If you installed mosquitto then you are using mosquitto.

Also Mosquitto has used discovery for quite some time and requires no configuration yaml. Delete everything you posted above from your config and restart.

Ok another question:

i am trying to check the status of mosquitto using hassbian-config script “sudo systemctl status mosquitto.service” inside venv, but i am asked the homeassistant user password that if i remember well never set. How to know that password ???

I deleted those entries and i got these errors:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 406, in _async_add_entity
    await entity.async_added_to_hass()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/binary_sensor.py", line 133, in async_added_to_hass
    await self._subscribe_topics()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/binary_sensor.py", line 218, in _subscribe_topics
    "qos": self._config[CONF_QOS],
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/subscription.py", line 82, in async_subscribe_topics
    await requested.resubscribe_if_necessary(hass, current)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/subscription.py", line 39, in resubscribe_if_necessary
    hass, self.topic, self.message_callback, self.qos, self.encoding
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/__init__.py", line 443, in async_subscribe
    async_remove = await hass.data[DATA_MQTT].async_subscribe(
KeyError: 'mqtt'
2019-11-09 22:09:17 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 406, in _async_add_entity
    await entity.async_added_to_hass()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/binary_sensor.py", line 133, in async_added_to_hass
    await self._subscribe_topics()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/binary_sensor.py", line 218, in _subscribe_topics
    "qos": self._config[CONF_QOS],
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/subscription.py", line 82, in async_subscribe_topics
    await requested.resubscribe_if_necessary(hass, current)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/subscription.py", line 39, in resubscribe_if_necessary
    hass, self.topic, self.message_callback, self.qos, self.encoding
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/__init__.py", line 443, in async_subscribe
    async_remove = await hass.data[DATA_MQTT].async_subscribe(
KeyError: 'mqtt'
2019-11-09 22:09:38 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 406, in _async_add_entity
    await entity.async_added_to_hass()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/light/schema_basic.py", line 209, in async_added_to_hass
    await self._subscribe_topics()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/light/schema_basic.py", line 534, in _subscribe_topics
    self.hass, self._sub_state, topics
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/subscription.py", line 82, in async_subscribe_topics
    await requested.resubscribe_if_necessary(hass, current)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/subscription.py", line 39, in resubscribe_if_necessary
    hass, self.topic, self.message_callback, self.qos, self.encoding
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/__init__.py", line 443, in async_subscribe
    async_remove = await hass.data[DATA_MQTT].async_subscribe(
KeyError: 'mqtt'
2019-11-09 22:09:38 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 406, in _async_add_entity
    await entity.async_added_to_hass()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/light/schema_basic.py", line 209, in async_added_to_hass
    await self._subscribe_topics()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/light/schema_basic.py", line 534, in _subscribe_topics
    self.hass, self._sub_state, topics
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/subscription.py", line 82, in async_subscribe_topics
    await requested.resubscribe_if_necessary(hass, current)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/subscription.py", line 39, in resubscribe_if_necessary
    hass, self.topic, self.message_callback, self.qos, self.encoding
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mqtt/__init__.py", line 443, in async_subscribe
    async_remove = await hass.data[DATA_MQTT].async_subscribe(
KeyError: 'mqtt'

You need to set up the integration as per the documents:

That’s a hassio addon, he’s using a venv.

Yes, you’re right…
Is there a way to know how to set the mosquitto.conf for working with venv?

Mosquitto is just a program independent of homeassistant. So you just need to install it on your system, start it, and then give homeassistant the details it needs to connect to it.

It’s not mega complicated, but the problem you’ll have if you need a proper ‘guide’ is that they all assume hassio and therefore the guide is just to use the addon.

Basically, install mosquitto. Set your username and password in mosquitto.conf and disallow anonymous. Then set up your mqtt section in your configuration with the same username and password. If you do need a guide for the mosquitto bit then try and find one that isn’t homeassistant focused and is just generic, then use the homeassistant docs for the homeassistant configuration only.

Hope this helps.

Before i had the entry in configuration.yaml about mosquitto, then i was adviced to delete it and added it into integrations of frontend and set username and password. Do i need to add them also inside the mosquitto.conf or not?

It should be the other way around. You set your username and password in mosquitto, then use those credentials in the mqtt integration so homeassistant can talk to mosquitto.

Ok i’ll try to set it, but actually using 0.100.3 i don’t have problems with mqtt. Upgrading to 0.101.3 i get lot of errors regarding mqtt among the others as i posted in this thread.

https://community.home-assistant.io/t/0-101-3-release-problems/147073/48

That’s why i am trying to learn about mqtt to solve that problem…

In fairness, it doesn’t look like mqtt is the problem in that thread, it’s just that whatever the failure is is causing a vast number of errors and mqtt happens to be the first.

Troubleshooting could be a long process, but if it was me I would:

  • Back up my configuration and move it somewhere safe
  • reinstall the latest homeassistant from scratch and start it, creating a new, fresh, default configuration
  • presuming that worked start importing my configuration back in chunk by chunk until I identify the problem

I don’t think mqtt is a problem.

Take out any references to api_password, remove scene.yaml and restart

Wasn’t that the same advice you gave in the other thread too?

Hopefully repeating it here will get it to stick a bit better.:wink:

Yes, I hope so…