hms-mqtt-publisher icon indicating copy to clipboard operation
hms-mqtt-publisher copied to clipboard

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

Open dc7kr opened this issue 1 year ago • 7 comments

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.

  • [x] run cargo clippy and fix all issues
  • [x] run cargo fmt to format all source files

dc7kr avatar Feb 06 '24 13:02 dc7kr

Thanks so much for the submission

DennisOSRM avatar Feb 18 '24 19:02 DennisOSRM

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

DennisOSRM avatar Mar 01 '24 10:03 DennisOSRM

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

dominikandreas avatar Mar 03 '24 18:03 dominikandreas

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

dc7kr avatar Apr 08 '24 16:04 dc7kr

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

stefan123t avatar Jul 17 '24 19:07 stefan123t

@dc7kr the Hoymiles serial numbers are of the form

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

  • the first 4 digits are the model number
    • they differ between built-in DTUBI 4143 and
    • the bundled inverter HMS-WiFi Model 1412
  • next 3 digits are the year of production A being 2024 and 23 being the calendar week of manufacture
  • last 5 digits 12345 are the actual serial number of that week's production run for the model

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

stefan123t avatar Jul 17 '24 19:07 stefan123t

@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 ;)

stefan123t avatar Jul 17 '24 19:07 stefan123t