Can one change the discovery parent topic from '/homeassistant' to something user defined?

For OMG_lilygo_rtl_433_ESP, one can change the MQTT base topic (default: /home) in the Web GUI.

Is it possible to change the base discovery topic?
The discovery messages all seem to have their topics filed under: /homeassistant and I would like to change it to something else.

To understand, why do you want to do that?

I am using a OMG_lilygo_rtl_433_ESP to capture sensor readings from various (cheap) rtl_433 temperature & humidity sensors around my house.

Basically, I find that I am caught in a bind between wanting and not wanting to turn on auto-discovery in OpenMQTTGateway.

  • If I turn on auto-discovery, then Home Assistant creates sensors not just for my devices but for the dozens of rtl_433 devices that my neighbors have (everything from temperature/humidity sensors to weather stations to wireless alarms to remote car key fobs to TPMS data – listening for a couple of days, I sniffed 245 sensors and this number will go up as batteries are changed in many of those devices :slight_smile: )

  • If I turn off auto-discovery, then I have no good way to enter new sensors of my own (if it’s similar to an old one that I have, I can copy/paste/adjust but if it’s a new sensor, I don’t know how to create the appropriate discovery topic).

So my “compromise” would be to change the discovery prefix in OpenMQTTGateway to point to something else – say ‘homeassistant-staging’, rather than the (default) discovery prefix ‘homeassistant’ which is the one used by HomeAssistant. Then, I can selectively and at my leisure copy over selected discovery messages from the ‘homeassistant-staging’ tree to the production ‘homeassistant’ tree. (I could use either MQTT Explorer or manually use mosquitto_pub – all pretty easy).

Alternatively, I could of course change the default prefix of HA, but I would rather not change that since I might have other MQTT Gateways that use the default prefix plus “philosophically”, it seems klugey to change the HA default settings just to avoid automatic inputs)

Alternatively, I could of course recompile and reflash OpenMQTT gateway to my Lilygo device but that is a pain and non-obvious for many users who may just want to use plug-and-play firmware (and updates).

Ideally, OpenMQTTGateway would allow one to change the discovery prefix on the fly, either via the WebGUI “MQTT configuration” page (analogous to the entry for “MQTT Base Topic”) or via a mqtt_pub message such as:

mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{ "discovery_topic": "homeassistant-staging"}'

Similar to the mosquitto_pub command for changing the MQTT topic (System commands (ESP only) | OpenMQTTGateway v1.7.0).

Looking at the code, currently discovery_Topic is harded coded as a declaration – but luckily it only appears 5 times in the codebase (3 times in ‘./main/ZmqttDiscovery.ino’ and 2 times in ‘./main/config_mqttDiscovery.h’)

So, it should be easy to create a variable for it that then could use similar code used for mqtt_topic to set it from the WebGUI and/or mosquitto_pub.

NOTE: There are other use cases where one might want to capture discovery messages in a “staging” tree rather than have them all added to the default discovery tree. And it would be a PITA to have to reflash the firmware to move back-and-forth

NOTE: I submitted this today as a Feature Request on the Github site

Another possibility, would be to create a python script that logs into the MQTT broker, subscribes to the MQTT topic tree and then publishes discovery messages using the same logic and format as OpenMQTT Gateway.

Note that the routine rtl_433/examples/rtl_433_mqtt_hass.py at master · merbanan/rtl_433 · GitHub does that in a way BUT it uses a different naming, organization, and discovery message construction convention compared to OpenMQTT Gateway.