mtrossbach / noah-mqtt

A tool for integrating Growatt Noah 2000 home batteries with Home Assistant via MQTT, enabling real-time monitoring and control of your energy storage system.
Apache License 2.0
41 stars 2 forks source link

Use mqtt retain flag for HA discovery message #38

Open kki03 opened 1 month ago

kki03 commented 1 month ago

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/noah0PV.../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