MQTT entities not appearing

I’m at a total loss here. I just can’t seem to get mqtt messages into entities.

I have MQTT running natively on the same pi I use for HA (which is running in docker).

I have a python script publishing simple strings (i’m using the subprocess library to build a simple system monitor) to an MQTT topic. Testing on the pi (using mosquitto_sub) shows the messages coming through. Testing within HA via the MQTT “Listen to a topic” function shows them coming through.

Here’s an excerpt from my config file. I’m 99.9% certain there’s no issues here:

sensor:
  #MQTT
  - platform: mqtt
    name: "rpi4 Temperature"
    state_topic: "rpi4/KeplerNAS/temp"

I’m verified over and over that the state_topic matches my script and perfectly matches the subscribed topic in my tests. Everything seems fine. But, no entities are getting created in HA. Nothing funky is showing in the logs. I’ve restarted multiple times.

Any ideas?

Correct username and password in your python script ?

None set. But I can’t imagine that the script is the problem as my messages are passing to the testing enviros fine.

Can you post what you get with ‘listen to a topic’ ?

0 is just a test message I’m trying, but I’ve also tried strings of text as well.

Home Assistant:

Message 0 received on rpi4/KeplerNAS/temp at 8:14 AM:
0
QoS: 0 - Retain: false

And for good measure, here is what I’m seeing in mosquitto_sub:

Client mosqsub|12800-KeplerNAS received PUBLISH (d0, q0, r0, m0, 'rpi4/KeplerNAS/temp', ... (1 bytes))
rpi4/KeplerNAS/temp 0

Should work. Are you sure you only have

sensor:

1 time in your configuration.yaml ?

Yup. I have multiple other sensors in there working fine. Here’s the section:

sensor:
  #Installed/Latest HA versions
  - platform: version
    name: Installed Version

  - platform: version
    name: Latest Available Version
    beta: false
    image: raspberrypi4
    source: container

  #MQTT
  - platform: mqtt
    name: "rpi4 Temperature"
    state_topic: "rpi4/KeplerNAS/temp"

Regardless of whether or not the topic or payload is correct, you should still be seeing the sensor show up in developer tools > states - even if the state is just unknown.

You are absolutely sure, you aren’t seeing it in developer tools?

It won’t show up in the handy popup menu you get by typing “e” on the keyboard anywhere in the web interface, you will need to refresh the page for it to show up there.

I seem to have got it working. I ended up just re-writing the config file portion for mqtt and it’s working. There must’ve been an issue with an extra space or something copied/pasted.

Definitely a lot of cleanup to do, but it’s working:

1 Like

Just in case anyone else comes across this issue, my problem was I had two ‘sensor:’ elements in my configuration.yaml file. All sensors needed go under a single ‘sensor:’ element. The file editor complained about this (there was no checkmark in the upper right corner of the file editor window) but I just ignored it for some reason.
After I fixed this and restarted the sensor showed up as ‘sensor:test0003’ in the Developer Tools → States list.

Here is the sensor section content of my configuration.yaml file

sensor:
  - platform: fitbit
    clock_format: 24H
    monitored_resources:
        - activities/activityCalories
<snip>
        - sleep/timeInBed

  - platform: mqtt_room
    device_id: iBeacon:2bc24954-63b1-4041-ba78-6e040ffbc41e-0-0
    name: "test0003"
    state_topic: "espresense/rooms"
    timeout: 5
    away_timeout: 20
2 Likes

Such a basic thing, I cannot believe it is not shown as a configuration error or something like it, thanks! I was having the same problem and was unable to see my error