Skip to content

fix broken solarwatt myreserve template #21417

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

t3r
Copy link

@t3r t3r commented May 24, 2025

  • fix broken "pv" computation by computing VPV * IPV as positive value
  • add new parameter "path".
    PowerGateway provides bmsdata under http://hostname:port/BMSData.shtml
    the parameter defaults to "/" so this patch does not break existing configs

- fix broken "pv" computation by computing VPV * IPV as positive value
- add new parameter "path". PowerGateway provides bmsdata under
http://hostname:port/BMSData.shtml
the parameter defaults to "/" so this patch does not break existing configs
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @t3r - I've reviewed your changes - here's some feedback:

  • The inline comment for the default path says “usually /BSMData.shtml” but the endpoint is actually BMSData.shtml—please fix the typo to avoid confusion.
  • Since both the power and soc sections use the same HTTP URI, consider extracting http://{{ .host }}:{{ .port }}{{ .path }} into a single template variable to reduce duplication.
  • You may want to enforce or document that the .path parameter always starts with a slash to prevent broken URIs if someone omits it.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@andig andig requested a review from premultiply May 24, 2025 07:30
@andig andig added the devices Specific device support label May 24, 2025
@@ -10,24 +10,27 @@ params:
- name: host
- name: port
default: 8080
- name: path
default: / # usually /BMSData.shtml, always start with a /
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does usually mean? Seems this is nothing a regular user would know? Typical value should be default.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code was using the root path, not the BMSData.shtml file. My intention was to keep the original behavior and make this setting optional.
My device does not respond on / but as this is not an official feature supported by solarwatt, I can't say which endpoint is more common.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My device does not respond on /

So your device does not work at all with the original tempalte?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, the request returned a 404 and also there was the typo "VBa" which should have been VBat. And even that was the wrong computation as VBat * IBat computes battery power, not PV power.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we need to figure out what different devices are out there and split the templates.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am almost sure that there has never been a "VBa" element and it was just a typo. The relevant part of the JSON response looks like

  "SData": {
      "IBat": -4.33,
      "VBat": 247.7,
      "PGrid": 1,
      "VPV": 370.2,
      "IPV": 5.85,
      "Aux": 0,
      "SysConfig": "19",
      "CCode": "0",
      "Restarts": 0,
      "RelCnt": 1034,
      "Status": {
        "LTC": "00000000",
        "BMS": "00000000",
        "Com": "00000000",
        "Sys": "00000000"
      },

Regarding the URL, my patch keeps the original behavior and optionally allows setting the path.
The official Solarwatt MyReserve wizzard App queries for BMSData.shtml, here is a snipped from my proxy log:
"GET /BMSData.shtml HTTP/1.1" 200 1100 "-" "MyReserve%20Wizard/24 CFNetwork/3826.x.x.x.x Darwin/24.4.0"
Finding out what devices are out in the wild might be tricky. There is no technical documentation publicly available for the MyReserve Command module.

- name: capacity
advanced: true
render: |
type: custom
{{- $uri := printf "http://%s:%s%s" .host .port .path }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{- $uri := printf "http://%s:%s%s" .host .port .path }}
{{- $uri := printf "http://%s:%s/%s" .host .port .path }}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add a constant forward slash here, the default path must be an empty string and the path property must not start with a slash to not end up with //.
Probably a matter of taste to force it this way or make it part of the path. I'm happy with both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we dont it must start wirh slash. ltrim would get it of the slash.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's why it is mentioned in the comment :)
Neither ltrim nor trimLeft seems to be available so this does not work:
{{- $uri := printf "http://%s:%s/%s" .host .port (ltrim .path "/") }}
Trigger this:
cannot create meter type 'template': template: base:2: function "ltrim" not defined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andig andig marked this pull request as draft May 25, 2025 09:01
@github-actions github-actions bot added the stale Outdated and ready to close label Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devices Specific device support stale Outdated and ready to close
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants