DennisOSRM / hms-mqtt-publisher

HMS-XXXXW-2T MQTT publisher and Home Assistant addon
BSD 2-Clause "Simplified" License
111 stars 16 forks source link

Use suffix instead of prefix of serial number for topic / Multiple Inverter Support #94

Open dc7kr opened 7 months ago

dc7kr commented 7 months ago

The current implementation uses the first 8 digits of the serial as an mqtt topic. If you manage more than one device with the same MQTT broker this causes a topic collision as the serials share a common prefix.

Running two instances in parallel causes disconnects on MQTT due to the hardcoded client_id. This also introduces a configurable client_id

This PR uses the last 8 digits instead for the topic to make it unique.

DennisOSRM commented 6 months ago

Thanks so much for the submission

DennisOSRM commented 6 months ago

Seems this requires an additional fix:

error[E0063]: missing field `client_id` in initializer of `MqttConfig`
  --> tests/integration_tests.rs:48:10
   |
48 |         &MqttConfig {
   |          ^^^^^^^^^^ missing `client_id`

For more information about this error, try `rustc --explain E0063`.
error: could not compile `hms-mqtt-publish` (test "integration_tests") due to 1 previous error
dominikandreas commented 6 months ago

Unfortunately this is a breaking change for existing users, as it will change the unique IDs of the sensors in home assistant (so effectively introduce new sensors instead).

Changing the lovelace UI elements and other references is relatively easy, but afaik the energy dashboard history would be lost after switching to the new sensor id.

We could solve this dilemma by introducing a mapping from serial number to a custom string as a configuration option in the home assistant addon to be used in the client id and unique identifier of the sensors, or just live with the breaking change for the sake of simplicity. Let me know what you think

dc7kr commented 5 months ago

Any update on the review? There are two issues open (#115 and #111) that would be resolved by this PR...

stefan123t commented 1 month ago

@DennisOSRM pinging for #127 being an other duplicate request for the same feature.

stefan123t commented 1 month ago

@dc7kr the Hoymiles serial numbers are of the form

DTU-SN: 4143 A23 12345 Mikro-SN: 1412 A23 12345

See e.g. here https://github.com/tbnobody/OpenDTU/issues/714

stefan123t commented 1 month ago

@DennisOSRM BTW would you like to join us on Discord, we could add another channel for #hms-mqtt-publisher and ask DanielR92 to grab the github updates too ;)