Interaction between discovery auto off timer and retain flag

Hello,

I’ve noticed a weird interaction between retain flags on commands and the discovery auto off timer, which leads to potentially confusing or undesirable behavior. I’m wondering if this behavior is intended, if there are configuration options to alter it, or if it’s a bug.

The discovery auto-off timer automatically turns home assistant discovery off after a set amount of time (default: 30 minutes). Users have the ability to toggle discovery by publishing a payload to “rfbridge/OpenMQTTGateway/commands/MQTTtoSYS/config” containing “{“discovery”:true,“save”:true}” to enable, or with “false” to disable. (“rfbridge/OpenMQTTGateway” is my base topic.) This all works great.

The weird behavior happens with the meta-discovery of this discovery toggle, in the topic “homeassistant/switch/B0B21CA741B8-discovery/config”, containing

{
“stat_t”:“rfbridge/OpenMQTTGateway/SYStoMQTT”,
“avty_t”:“rfbridge/OpenMQTTGateway/LWT”,
“name”:“SYS: Auto discovery”,
“uniq_id”:“B0B21CA741B8-discovery”,
“retain”:true,
“val_tpl”:“{{ value_json.discovery }}”,
“pl_on”:“{"discovery":true,"save":true}”,
“pl_off”:“{"discovery":false,"save":true}”,
“pl_avail”:“online”,
“pl_not_avail”:“offline”,
“stat_on”:true,
“stat_off”:false,
“cmd_t”:“rfbridge/OpenMQTTGateway/commands/MQTTtoSYS/config”,
“device”: […]
}

(B0B21CA741B8 is my device’s MAC address)

This causes Home Assistant to publish the messages toggling discovery with the retain flag set. As a result, if a user turns discovery on through Home Assistant, then it is turned off automatically after 30 minutes, when the gateway reboots discovery will be turned on again. If the user instead turns off discovery manually before 30 minutes, when the gateway reboots discovery will be off.

Is this behavior intended? If so, are there configuration options I can use to change it? If not, is it a bug that should be fixed?

Thanks!

Hello,

I don’t think we should retain the discovery command now that we save it in the flash memory.
I will remove it.

If it is set to OFF it should remains OFF upon restart.
It should not stay ON for more than 30 minutes. See it has a pairing window on which the gateway will listen for new devices.

Thank you for your reply! That makes sense to me. I’ve put in a pull request to remove the retain flag from those commands, if you agree that’s the best course of action.

1 Like