steff393/wbec

wbec generating different mqtt devices under fhem

Opened this issue · 8 comments

Hello everyone,

i have been using wbec in combination with mqtt and fhem for some time now and I noticed that several (over 100) mqtt devices have been created for wbec in fhem - see the following screenshot. Of course, the device with the highest consecutive number is always used, but deleting the more than 100 devices is not really fun.
Does anyone have an idea why new devices are always being created in autocreate? Apparently wbec always reports to the mqtt broker with a different name!

Greetings & thanks

Marc

image

Hi Marc,

I'm using the Mosquitto MQTT-Brooker. That's fine, there is one topic wbec and one OpenWB published by the wbec. No different names here.

Does your wbec use a fixed IP in your network?

Regards, Andre.

Screenshot_20240318_165759

Hi Andre,

thanks for your reply!
Yes, IP of wbec is fixed.
I have to explore the mqtt tomorrow, currently i don't know the newest topic generated @fhem. There are a lot... ;-)

I did some searching and found out that the mqtt-server included in fhem creates a new device with every reconnect if no clientid is defined in the mqtt device (here the wbec).

Excerpt from the fhem help:
Most MQTT-capable devices contain options for assigning a unique ClientID (see the example of the zigbee2mqtt service above). If no ClientID is assigned, some clients use new IDs for each connection. It is recommended to make use of these setting options if possible.

Unfortunately I could not find the option, is it not included in wbec or does it have a different name?

I have found a solution within fhem:
If you edit the readings list so that it looks like this afterwards, no new mqtt devices are created:

image

However, the question about the mqqt ClientID in wbec might still be interesting in general.

Hello, sorry, but I don't have further information about the MQTT client id.

Hello, sorry, but I don't have further information about the MQTT client id.

Die Arduino-Library unterstützt eine ClientID: https://github.com/knolleary/pubsubclient
Dokumentiert in der API: https://pubsubclient.knolleary.net/api#connect

Danke für den Hinweis. Das hier dürfte es erklären:

wbec/src/mqtt.cpp

Lines 160 to 162 in 07a5855

// Create a random client ID
char clientId[10];
snprintf_P(clientId, sizeof(clientId), PSTR("wbec-%d"), (uint8_t)random(255));

con = client.connect(clientId, lastWillTopic, lastWillQos, lastWillRetain, lastWillMsgOff);

Ich lasse den Issue mal offen und baue künftig eine parametrierbare Client-ID ein: cfgMqttClientId
Wenn der Parameter 0 ist, dann wäre das Verhalten wie bisher (=random(255)). Ansonsten der eingestellte Wert.