Solved: Help with MQTT setup

Trying to get an esp8266 MQTT message into ha. Running ha on a raspberrypi (raspian), using Mosquitto as my broker (on the raspberrypi). Also, mosquitto is set up with “allow_anonymous true.”

I’m pretty sure the ESP8266 side is working. When I run:
mosquitto_sub -h 127.0.0.1 -v -t "sensor/#"

I get the output from my esp8266 project:
sensor/humidity 56.67
sensor/temperature 19.72

The MQTT part of my ha config looks like this:

mqtt:
  broker: 127.0.0.1
  discovery: true
  discovery_prefix: sensor

sensor:
  - platform: mqtt
    name: "Attic Temperature"
    state_topic: "sensor/temperature"
    unit_of_measurement: "°C"
    value_template: "{{ value_json.temperature }}"

The problem is I’m not reading any values for temperature. The Overview page has the icon for my Attic Temperature sensor but no data is coming in. Any thoughts?

You have to enter the ip address of the system mosquitto is running on in the broker section. In my case it is running on my rasberry pi so I enter it’s ip address.

I’m running homeassistant and mosquitto on the same system.

I doubt that the ip address of the pi is 127.0.0.1

Actually it will be. The IP address of the broker on my NUC is happy being configured like that.The broker on the same pi running home assistant means you can use localhost/127.0.0.1

You are not sending a payload continaing json, so the value_template is not necessary. Remove the value_template line and it should be fine.

That is assuming you are not getting any MQTT component could not be set up messages when you restart, which would indicate some error connecting to the broker, but it looks correct to me.

Thanks!

Brilliant! this did the trick!

for clarity my new sensor config looks like this:

sensor:
  - platform: mqtt
    name: "Attic Temperature"
    state_topic: "sensor/temperature"
    unit_of_measurement: "°C"
1 Like