Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mqtt retain flag for HA discovery message #38

Closed
kki03 opened this issue Oct 28, 2024 · 2 comments
Closed

Use mqtt retain flag for HA discovery message #38

kki03 opened this issue Oct 28, 2024 · 2 comments

Comments

@kki03
Copy link

kki03 commented Oct 28, 2024

Hi Markus,
I installed my Noah 2000 yesterday and also setup the HA integration. And now I was just looking into the HA discovery stuff and wanted to check how the sensors have been registered.

But I had to restart noah-mqtt to get the HA registration messages again.
E.g. topic: homeassistant/sensor/noah_0PV.../OutputPower/config
{ "name":"Output Power", "device_class":"power", "state_topic":"noah2mqtt/0PV...", "state_class":"measurement", "unit_of_measurement":"W", "value_template":"{{ value_json.output_w }}", "unique_id":"0PV..._output_power", "device": { "identifiers":[ "noah_0PV..." ], "name":"NOAH 2000", "manufacturer":"Growatt", "sw_version":"07.08.05.4004", "model":"NOAH 2000", "serial_number":"0PV..." }, "origin": { "name":"noah-mqtt", "sw_version":"0.0.24", "support_url":"https://github.com/mtrossbach/noah-mqtt" } }

It would be great if you could set the retain flag in method https://github.com/mtrossbach/noah-mqtt/blob/main/internal/homeassistant/service.go#L42 to true because that allows to read the messages from the mqtt server at any time.
E.g.
s.options.MqttClient.Publish(topic, 0, false, string(b))
would become
s.options.MqttClient.Publish(topic, 0, true, string(b))

Thanks
Klaus

@mtrossbach
Copy link
Owner

mtrossbach commented Jan 11, 2025

Hi Klaus,

Thanks for the feedback on the HA integration!

I understand you'd like the discovery messages retained. However, retaining them can cause issues if sensors change in the future (like if one is removed). It would make it hard for users to get the correct setup again.

Instead of retaining the messages, I'll add a feature to automatically republish the discovery payload every 6 hours. This should keep HA up-to-date.

This will be implemented in 0.0.26

Thanks for your understanding! If you have any other ideas, let me know.

Thanks,
Markus

@kki03
Copy link
Author

kki03 commented Jan 11, 2025

Hi Markus,
that´s of course a valid point and indeed it can cause issues if it is not handled correctly. But if there are changes in the sensors you have it in your hand to also remove retained messages.

I checked various other projects on that and every project I have in use retains the messages.

Therefore it´s not that unusual to retain the messages, but on the other hand I also ran into issues because of that and hat to remove certain things manually with MQTT Explorer.

Maybe it is also possible to manually send the discovery message by clicking a button on the add-on configuration page.

Thanks.
Klaus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants