Hi,
Let’s unravel what is going on here:
- You are writing client device code in Python, which connects to a MQTT broker via the
paho.mqtt.client
. (I had to go to the Github page.) - You are using HASS Discovery, so by publishing specific topics to the MQTT broker, HASS creates entities automatically.
- There seems to be a loop which registers two devices, twice.
- The second loop iteration does not register +2 devices.
As I’m not keen to read and understand many lines of Python, my advice is to break this down.
What I did when writing a complex client device in Python using the same Paho libraries and HASS Discovery, was to create a test rig on the command line. This allows FAST and IMMEDIATE testing.
Prototype what you want in a script on the command line, check it instantly configures HASS, and THEN write code. You’ll find misunderstandings in the discovery paylods much faster.
Here’s an explanation and example:
Note that entity naming changed slightly in 2023.8, which impacts HASS Discovery naming;
The Mosquitto broker log only shows the client MQTT connections coming and going - not what the MQTT integration is doing with the payloads as it interprets HASS Discovery.
I’d suggest MQTT Explorer to dump the actual HASS Discovery payload topics so we can interpret what is going on.
If this helps, this post!