mqtt discovery on every update bug

Hey! I'm currently in HA core beta, and was looking for other bugs but ended up noticing that hass.agent does something that's not very efficient on the home assistant side, it sends the discovery payload on every update for every sensor which cost CPU time on HA. For example
4-02-28 15:45:46.785 INFO (MainThread) [homeassistant.components.mqtt.discovery] Component has already been discovered: sensor ANTO_HP a2c6a82f-f7a9-4e48-aa6e-2e47c3df05ce_total_disk_count, sending update
4-02-28 15:45:46.785 INFO (MainThread) [homeassistant.components.mqtt.discovery] Component has already been discovered: sensor ANTO_HP a2c6a82f-f7a9-4e48-aa6e-2e47c3df05ce_total_disk_count, sending update
I reported the exact same thing for another integration and you may want to read this here: https://github.com/bachya/ecowitt2mqtt/issues/704 This will definitely lower the burden on HA when it does mqtt processing. I'm running 2.0.1. Sorry if this was already fixed in beta or even reported already
GitHub
update of sensor entities also floods HA mqtt discovery Ā· Issue #70...
Describe the bug Working with @bdraco, we were hunting down what is causing some extra overhead on my system (RPi4 4Gb/HAOS) and discovered that ecowitt2mqtt seems to be flooding HA with MQTT disco...
Solution:
will be part of 2.1.0-beta1
Jump to solution
27 Replies
HASS.Agent Helper
HASS.Agent Helperā€¢9mo ago
Help us Help Others!
To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> āœ… Mark Solution
From An unknown user
HASS.Agent Helper
HASS.Agent Helperā€¢9mo ago
Help us Help You!
Please don't delete messages or posts because it makes it impossible to understand what happened. If you don't want your messages to be seen then don't post here. Make sure to provide detailed reports of bugs.
Please include error log uploads and info about the bug.
DrR0x
DrR0xā€¢9mo ago
@Amadeo
Amadeo
Amadeoā€¢9mo ago
That is interesting I had in my head that the discovery is sent only when entities are recreated/HASS.Agent restarts I'll take a look at this
barrelltitor
barrelltitorā€¢9mo ago
Yeah discovery should only be sent if: * HA Restarts(subscribe to the topic as it will tell you if it went off) * HassAgent restarts * Entities are recreated
Amadeo
Amadeoā€¢9mo ago
now it got more interesting
Amadeo
Amadeoā€¢9mo ago
it got sent only once does this log require debug option to be enabled or is it generated by default?
Anto79-ops
Anto79-opsOPā€¢9mo ago
Yes, need this
logger:
default: info
logs:
homeassistant.components.mqtt: info
logger:
default: info
logs:
homeassistant.components.mqtt: info
Amadeo
Amadeoā€¢9mo ago
ok, I'll add this and see could you please also check on your side with mqtt exploer if the messages are really being sent more than once?
Anto79-ops
Anto79-opsOPā€¢9mo ago
You should see home assistant saying "already discovered" on every update
Amadeo
Amadeoā€¢9mo ago
I can't recall any changes between 2.0.1 and the betas that could cause it but everything is possible ok, got it I think but I'll double check and leave if running for a while and then find the root cause šŸ˜„ yup, confirmed
Anto79-ops
Anto79-opsOPā€¢9mo ago
šŸ˜
Amadeo
Amadeoā€¢9mo ago
I'll work on it today
Anto79-ops
Anto79-opsOPā€¢9mo ago
I'll see if I can confirm it on explorer too
barrelltitor
barrelltitorā€¢9mo ago
I am a dum dum but I just woke up at the time You can also just use the retain flag and you should only need to ever re-send it in case something changes, same for payload values
Amadeo
Amadeoā€¢9mo ago
we can't trust users and/or mqtt servers šŸ˜„ I have the poc ready, it's sent only once per run and when config changes need to replicate it for satellite and do some basic tests
Solution
Amadeo
Amadeoā€¢9mo ago
will be part of 2.1.0-beta1
Amadeo
Amadeoā€¢9mo ago
quite a "sizable" update that will be <insert yoda noises>
Anto79-ops
Anto79-opsOPā€¢9mo ago
Awesome that was fast! I haven't been able to connect to my machine to confirm things on mqtt Explorer But if you confirmed the issue and issued a fix for it, that's great!
Amadeo
Amadeoā€¢9mo ago
yup, got it replicated to satellite (and made me realize how much some parts of the code need rewrite xD) and now letting it run for some time just to make sure
JonnyBergdahl
JonnyBergdahlā€¢9mo ago
Yeah, using the retain flag for the discovery payload is a dumb idea. HA retains everything anyways.
Amadeo
Amadeoā€¢9mo ago
not quite, restarting mosquitto while HASS.Agent is offline will make all the entities dissapear from HA but as always, "configurable by user" is the right answer šŸ˜„ looks like the fix is ready
JonnyBergdahl
JonnyBergdahlā€¢9mo ago
Wait what? It looses them if you restart the BROKER? How stupid is that???
Amadeo
Amadeoā€¢9mo ago
by design that's the way to get rid of mqtt discovered entities other way would be for HA to manage the retained topics itself or have some kind of deletion method like it is for discovery now it's simpler this way, discovery payload exists = entity exists
barrelltitor
barrelltitorā€¢9mo ago
mqtt is such a useful technology
JonnyBergdahl
JonnyBergdahlā€¢9mo ago
Hm. I retract my previous statement. The device reconnects to the broker and when doing so, it publishes the discovery again, resulting in that all entities are back. I had issues with auto discovery devices remaining in HA that I no longer use, just because they used retain. Only way to delete them is to manually send a null payload to the auto discovery topic using an MQTT GUI client. Just tell a noob that is what he needs to do.... šŸ˜¬
Want results from more Discord servers?
Add your server