Can't get MQTT working on a new Setup

I’m new to Home Assistant and have been trying to get MQTT working. I have a couple of temperature sensors connected to a separate Raspberry Pi publishing temperature readings to a Mosquitto broker on a Synology system (192.168.1.2). I’m trying to get my Home Assistant configured to display/graph the temperature readings but not having any luck.

Here are the relevant sections from configuration.yaml:

mqtt:
  broker: 192.168.1.2
  #protocol: 3.1
  keepalive: 60
  client_id: hassio-1
  #username:
  #password:

sensor test:
  - platform: mqtt
    state_topic: "hal/temperature/Outdoor"
    name: "Sensor Test"
    unit_of_measurement: °F

I’ve verified that the broker is getting the info but it doesn’t appear to get to HA. The broker doesn’t require a login/password.

This is the Sensor Card Configuration:

type: sensor
entity: sensor.sensor_test
graph: line
name: Test

There are no logbook entries for this Entity. I’ve been searching the forum and other documentation but have not been able to figure out what’s going on.

Any help would be much appreciated.

is there anything in the logs about not being able to connect to the broker?

Go to the developers tools->mqtt page and listen for all topics (#) to see if HA is connected and receiving traffic.

if all that looks OK then go to your states page and look for you sensor there to see what the state is.

sensor test:

should just be

sensor:

Found this in the log. It looks like HA is trying to connect to a broker at core-mosquitto with a username homeassistant and a password.

This is strange because my mqtt broker is set to 192.168.1.2 with no username/passwd. Why is it being overridden?

I wonder if this is somehow left over from when I was trying to use the mqtt add on? It has been uninstalled.

2020-05-31 16:06:41 WARNING (MainThread) [homeassistant.components.mqtt] Data in your configuration entry is going to override your configuration.yaml: {‘broker’: ‘core-mosquitto’, ‘discovery’: True, ‘password’: ‘Moh5iogh4joR7oosh2eecheNgei6yiewaezahshoop8shi45eepiih5aeh7oB6si’, ‘port’: 1883, ‘protocol’: ‘3.1.1’, ‘username’: ‘homeassistant’}
2020-05-31 16:06:46 ERROR (MainThread) [homeassistant.components.mqtt] Failed to connect due to exception: [Errno -3] Try again

At this point, it looks like I can’t even connect to the broker, but about the syntax - I’m still learning, but my understanding is that I can specify the sensors by either:

method 1

sensor: 
  - platform: mqtt
     state_topic:
     name: test
  - platform: mqtt
     state_topic:
     name: test2

‘’’
method 2:

sensor test:
  - platform: mqtt

and so on…

Did I get this wrong?

If that syntax is valid, I haven’t seen it before. I would be curious if it is, do you have an example somewhere?

But yes, looks like your main problem is getting the MQTT integration connected to the broker. Maybe you should pick a single installation method, either the UI or by configuration.yaml, but not both.

https://thingsmatic.com/2017/02/07/home-assistant-getting-started-and-using-mqtt-sensors/

Huh… looks similar to Style 2 listed in the docs, but it’s not exactly the same.

The error message says you have setup the integration in both configuration.yaml and the UI integration. You should remove one of them, it sounds like you’ve got some left over configuration in one of those that is not correct.

But have you removed the integration from the UI?

If not then it’s going to try to use that instead of yaml (from the logs) but since the add-on docker container is now gone since you “uninstalled” it there is nothing for the integration to connect to.

Deleting the UI integration fixed it. Thanks for the help!

image

1 Like