Mqtt connection trouble

That looks good. My only question would be why the IP address for HA_MQTT doesn’t start with 172 but the one for MQTT Explorer does (In my case it’s the other way around. HA_MQTT is from a docker container so its address starts with 172 and MQTT Explorer is on a separate computer whose IP address starts with 192). Anyway, let’s skip that for now (it’s probably irrelevant) and proceed with this simple test:

  1. Go to Settings > Devices & Services > Integrations
  2. Click the MQTT integration
  3. Click Configure
  4. Under ‘Listen to a topic’, enter junk in ‘Topic to Subscribe to’ (not /junk but junk)
  5. Click ‘Start Listening’ and leave the web page open.
  6. Go to MQTT Explorer and publish any simple payload (like hello) to the topic junk (not /junk but junk)
  7. Look on the ‘Listen to a topic’ web page for the payload you just published.
  8. If it’s not there then there’s still a communication problem between Home Assistant and the broker.
  9. If it is there, then it implies there may be a configuration problem with your MQTT sensors.

Good idea!
So I published to the topic “junk” 123 from the mqtt explorer and the Home Assistant mqtt integration received:

image

But if I listen to the topic /home/pi_zero/temp1 I do not receive anything

Drop the leading “/”:
home/pi_zero/temp1

You are right. Now I get the data in the mqtt integration:

image

But still not in the dashboard.
The yaml file looks like:

image

Now all that MQTT stuff just happens in the background nd you can write automations using the entity:
sensor.Temperatur_Wohnzilnme

Note, since entity names are case-sensitive, I avoid any upper-case just to not confuse myself.

It received 123 so that confirms Home Assistant is connected to the broker.

Then that means what I wrote here:

Look at what your script contains. According to what you posted, there’s no leading slash in the topic.

mqtt_topic = "home/pi_zero"

The inclusion or absence of a leading slash in an MQTT topic is significant and changes the entire topic.

According to what you posted above, your sensors are configured to subscribe to home/pi_zero not /home/pi_zero.

    - name: "Temperatur Wohnzimmer"
      state_topic: "home/pi_zero/temp1

If they are not receiving payloads then it means your script and sensors aren’t using the same topic. One is using a topic with a leading slash and the other one isn’t.

So which one is using the wrong topic?

I checked again and do not find the mistake:

python code:
image

mqtt explorer:

configuration.yaml:
image

Dashboard:
image

Then the debugging process has reached a deadend.

The following has been confirmed by you:

  • Home Assistant connects to the broker
  • Your python script connects to the broker
  • Home Assistant can create MQTT Sensors
  • Home Assistant can receive payloads published to a topic
  • Your python script can publish payloads to a topic
  • Your MQTT Sensors are subscribed to the same topic used by your python script

Yet your MQTT Sensors fail to receive the payloads published by your python script to a topic they share.

There’s missing, misleading, or incorrect information somewhere, in the debugging process, because at this point (six confirmed critical steps) the MQTT Sensors should be receiving data.

Use MQTT Explorer to publish the following payload to home/pi_zero/temp1

19.9

That’s 19.9 with a period and not 19,9 with a comma.

Then check the state of sensor.temperatur_wohnzimmer.

If the sensor reports the published value, repeat the test but this time use a different value containing a comma like 19,5 and let me know if the sensor displays that value or not.

The goal of these tests is to determine if a published numeric value can or cannot contain a comma.


NOTE

The MQTT Sensors are configured with unit_of_measurement and I am speculating that the option might impose constraints on the data’s format. In other words, it might consider 19,1 to be non-numeric and reject it.

You got it!

The German comma 19,9 instead of the dot 19.9 was the issue!

Thank you very much for your help and enjoy the coffee I’ll spend you!

1 Like

You’re welcome and thank you for the coffee!