Tasmota and MQTT communication problem

Hello dear community,

I installed tasmota on two esp32 to monitor energy consumption of two electric terminals (with pzem).
Everything is working well in the web terminal of both devices and I can read the measurements.

Now after configuring mqtt on home assistant, the two devices were discovered successfully, however sensors are keeping constantly reloading and being unavailable! I made a gif of this behavior, very weird…

Any help will be much appreciated. Thanks!

ezgif-2b14499503ab73

No idea what is going on but here are some words that may help in searching for a solution:

“mqtt retained message” (only do this for state topics, not command topics).

“mqtt last will and testament”

“mqtt keep alive” (timeout may need increasing)

Thank you for helping and for your quick answer, I’ll start by taking a look into your suggestions.
I noticed now after taking one of them off the grid, that the remaining one is working correctly without interruptions.

Ok that’s very interesting and probably not a time-out issue.

Do they have different IP addresses?

Yes they do. The http api terminal is working on both.
When both are connected to the grid, i remember seeing in the console of tasmota “mqt : retained”.
In the log of the mqtt broker, i have this :

2025-07-01 23:15:19: New connection from 192.168.188.100:52765 on port 1883.
2025-07-01 23:15:19: Client core-mosquitto already connected, closing old connection.
2025-07-01 23:15:19: New client connected from 192.168.188.100:52765 as core-mosquitto (p2, c1, k30, u'mqtt').
2025-07-01 23:15:20: New connection from 192.168.188.101:64242 on port 1883.
2025-07-01 23:15:20: Client core-mosquitto already connected, closing old connection.
2025-07-01 23:15:20: New client connected from 192.168.188.101:64242 as core-mosquitto (p2, c1, k30, u'mqtt').
2025-07-01 23:15:20: New connection

Maybe, my mqtt configuration is faulty !

Is this correct? I did understand that the client should be the mqtt broker and that’s why it is the same for both of the esp32.

Hello

I think the client is a name you give the client ( the tasmota device ) so you can recognize it in error logs and such. It probably pops into HA as well as the entity.
They should be unique…
So the client connects, sends the data, then a new client with the same name different IP connects, drops the old connection, then it does it again… and again…

Yep that’s what’s happening.

Nope. The client is to identify the device, not the broker.

You can use the same username and password for both devices but they must have unique client ids.

1 Like

What tom_I said. And topic must be different on each device.

1 Like

Problem solved by changing the client names.

Thank you very much for helping, have a nice day.

1 Like