I have OctoPi with MQTT. I have turn OFF the retain flag in that config so that ALL event messages have retain=false.
In MQTT Explorer. I connect to my Home Assistant MQTT and delete ALL events for that OctoPi Instance.
I turn on OctoPi, Connect to my 3D Printer and look at all the events from that printer coming into Home Assistant.
All of them have the Retain flag OFF.
I shut down OctoPi and the 3D Printer. Still ALL event messages have Retain flag OFF.
I reboot Home Assistant.
OctoPi
Disconneting event now has Retain ON
Diconnected event now has Retain ON
PritnerStateChanged has Retain ON
But OctoPi is powered OFF!
So obviously Home Assistant MQTT is turning this flag back on.
How do I turn the Retain OFF (FALSE) and keep it that way?
Thank you.
So I went through with the MQTT Publish Service in Home Assistant, and set all Disconnect events with NULL payloads and the Retain Flag OFF:
I verified all these with MQTT Explorer and all Retain Flags were off.
I booted the AuroraA4 device and then disconnected it and the Retain Flag was still OFF for the Disconnect event.
Then rebooted Home Assistant, and the Retain Flag came back even though the AuroraA4 device has been OFF the whole time!
Why the Heck is it doing this and how do I get it to STOP setting the Retain Flag ON (I NEED IT OFF!)
see the big yellow retained with X. hit it
Been there, done that. Still comes back
have you tried hitting trash can in the topic to delete it
Iâve tried that and trashing then entire âeventâ folder. Still comes back with Disconnected âRetainedâ when Home Assistant is rebooted
The source sensor has been removed? If not you have to change the setting for the sensor first. Then in dev tools â services â mqtt publish. Enter topic, blank payload and check the retain box
The sensor has not been removed. There are no settings for Retain Flag in Sensors, there used to be, but that parameter was removed as it only applies to Switches.
Discussion:
This is my MQTT sensor configuration:
sensor A4:
- platform: mqtt
state_topic: "AuroraA4/event/Error"
name: "Aurora A4 Error"
value_template: '{{ value_json._timestamp }}'
- platform: mqtt
state_topic: "AuroraA4/event/Disconnected"
name: "Aurora A4 Disconnected"
value_template: '{{ value_json._timestamp }}'
I tried your screenshot for the Sensor:
And after rebooting Home Assistant, âDisconnectedâ event was reinserted with the Retain Flag ON
The retained button indication in MQTT Explorer is not what you think. It does not show the message is currently retained, it shows that the topic hasnât been updated after Explorer started and the value was retrieved then (possibly old retained data).
Delete the topic in Explorer by using the trash icon and then restart Explorer. If the message is truly retained it will appear again but it wonât otherwise.
Can you expand on this? You had a retain flag set and with one of the upgrades it was no longer valid? and/or threw an error? Maybe comment out the sensors, restart, uncomment the sensors and restart again. The default should be retain: false
.
The method I posted has always worked for me, however, Iâve seen people who it hasnât. They resorted to removing the integration and then adding it back worked.
btw none of the removal matters until you get the sensor config updated.
Like I said above, I have trashed that message and even the entire event folder, and when Home Assistant reboots, it magically reappears with âRetainedâ
See my previous link to the discussion of the Retain Flag in Home Assistant for Sensors and that it was removed and why.
No, I never had the retain flag set for sensors in my configuration.
As for removing Integrations, that doesnât seem to work either. I had an old Integration called âHeroâ and had removed it over a year ago, yet it is still in the MQTT system (shows up in MQTT Explorer connected to Home Assistant MQTT). So I really donât want to go down that rabbit hole.
If you have a topic with a retained message and want to purge it, you simply publish an empty string to the topic, as a retained message. Done; the topic no longer has a retained message. The topic will not have another retained message unless something publishes one after you purged it.
If you have truly purged the topicâs retained message yet another one reappears then something is responsible for publishing it. Your challenge is to determine what it is.
Itâs as uncomplicated as that.
So after the update that removed the option for the retain flag, your sensors started to retain their messages? Have you rolled back to a prior snapshot to see if that is the cause of your problem.?
This has nothing to do with the configuration of the two MQTT Sensors in Home Assistant and everything to do with whatever is responsible for publishing payloads to the two MQTT topics.
If âOctopiâ is responsible for publishing to AuroraA4/event/Error
and AuroraA4/event/Disconnected
then itâs the source of the retained messages. No amount of tinkering in Home Assistant will change that.
I donât know what âOctopiâ is but if you donât want those two topics to receive payloads as retained messages, you will have to change that in Octopi.
123 Taras, Iâm sorry you missed this in my First Post on this topic, so here it is again:
I have OctoPi with MQTT. I have turn OFF the retain flag in that config so that ALL event messages have retain=false.
In MQTT Explorer. I connect to my Home Assistant MQTT and delete ALL events for that OctoPi Instance.
I turn on OctoPi, Connect to my 3D Printer and look at all the events from that printer coming into Home Assistant.
All of them have the Retain flag OFF.
No. That would mean rolling back a couple of years. If you noticed in the Discussion thread I linked to previously on the âretainâ flag for sensors, this was back in Feb of 2019. Iâm sorry, but I donât even have Snapshots that far back.
Iâm sick and tired of working around this stupid issue of rouge âDisconnectedâ messages shutting down my printers. This is supposed to be a safety measure for 3D Printing, but instead its a logistics nightmare of an issue that should not be happening.
Since this only happens when I reboot Home Assistant, and they are MQTT messages, I think itâs logical to point the finger at MQTT.
I just now sent a Null Payload for the topic AuroraA4/event/Disconnect with the retain flag ON (as instructed above) which cleared out that topic. Then restarted JUST Mosquitto MQTT, and that topic reappeared as âRETAINEDâ and triggered my Automation to turn off the corresponding switch.
I have looked through all the files in Home Assistant (configuration, automations, etc.) and nothing generates that topic. The sensor looks for that topic, but it also looks for the âErrorâ topic, which is not regenerated by MQTT. And no other devices on my network generate that topic and the only one that does is Powered OFF.
sensor A4:
- platform: mqtt
state_topic: "AuroraA4/event/Error"
name: "Aurora A4 Error"
value_template: '{{ value_json._timestamp }}'
- platform: mqtt
state_topic: "AuroraA4/event/Disconnected"
name: "Aurora A4 Disconnected"
value_template: '{{ value_json._timestamp }}'
I will also point out that the timestamps on these âregeneratedâ topics are not current, they are the same time stamps of those previously removed through the MQTT:Publish tool as I stated above.
So, no device is sending ânewâ Disconnect messages, MQTT is retaining them and re-populating/re-publishing in them causing that automation to trigger in Home Assistant
Hereâs another walkthrough:
Current state of Home Assistant MQTT Broker as viewed in MQTT Explorer:
Click on âCall Serivceâ to send this topic:
Result shown in MQTT Explorer: that topic is now GONE:
Restart MQTT Brokers:
After Restart Complete, result in shown in MQTT Explorer:
Notice that the timestamp of the topic is the same as before, but the time of the event (on the right) is that of when MQTT was restarted.
Whatever you did failed to work because it continues to publish its payloads as retained messages.
MQTT Explorer reports if a message is retained in a manner that may be misleading you. When itâs connected to the broker and you publish a retained message to a topic, MQTT Explorer will not report itâs retained. If you disconnect MQTT Explorer from the broker and then reconnect, now it will show the topic has a retained message.
If you use NodeRED (or even maybe via an HA automation) you could read this payload and republish it non retained to a different one. Shouldnât be needed but maybe will work around your issue.