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 suffix instead of prefix of serial number for topic / Multiple Inverter Support #94

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

dc7kr
Copy link

@dc7kr dc7kr commented Feb 6, 2024

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.

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

When trying to use more than one inverter on the same mqtt host
the previous implementation causes a topic clash as the serial numbers
share a common prefix. This change uses the last 8 digits instead of the
first for the topic (and whenever the shortened SN is used)
running two instances of hms-mqtt-publish with the hardcoded
client_id causes conflicts and high cpu load.

This makes the client_id optionally configurable
@DennisOSRM
Copy link
Owner

Thanks so much for the submission

@DennisOSRM
Copy link
Owner

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
Copy link
Collaborator

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 dc7kr changed the title Use suffix instead of prefix of serial number for topic Use suffix instead of prefix of serial number for topic / Multiple Inverter Support Apr 8, 2024
@dc7kr
Copy link
Author

dc7kr commented Apr 8, 2024

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

@stefan123t
Copy link

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

@stefan123t
Copy link

stefan123t commented Jul 17, 2024

@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 tbnobody/OpenDTU#714

@stefan123t
Copy link

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

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

Successfully merging this pull request may close these issues.

4 participants