8000 OpenEMS: add battery control by iseeberg79 · Pull Request #20948 · evcc-io/evcc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

OpenEMS: add battery control #20948

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

Merged
merged 6 commits into from
Apr 30, 2025

Conversation

iseeberg79
Copy link
Contributor
@iseeberg79 iseeberg79 commented Apr 29, 2025

see #11501

uses channel SetActivePowerEquals to control ess device via HTTP/REST API
relies on REST/API controller, correct ess device name and proper watchdog/timeout definition

Summary by Sourcery

Add battery control capabilities for OpenEMS devices using HTTP/REST API

New Features:

  • Implement battery control mode functionality for OpenEMS devices

Enhancements:

  • Introduced new parameters for battery control, including battery device selection and watchdog timeout

Summary by Sourcery

Add battery control capabilities for OpenEMS devices using HTTP/REST API

New Features:

  • Implement battery control mode functionality for OpenEMS devices

Documentation:

  • Add license requirement description for active battery control on FENECON systems

Copy link
Contributor
sourcery-ai bot commented Apr 29, 2025

Reviewer's Guide

This pull request adds battery control for OpenEMS devices by introducing a new batterymode configuration. It uses the HTTP source to interact with the OpenEMS REST API, specifically targeting the SetActivePowerEquals channel of a specified battery component (ess). A watchdog timer ensures the control signal is reset if updates stop.

File-Level Changes

Change Details Files
Added battery control capability and configuration.
  • Declared 'battery-control' capability.
  • Added a note about commercial license requirements for FENECON systems.
  • Introduced 'battery' parameter to specify the target battery component.
  • Introduced 'watchdog' parameter to configure the control timeout.
templates/definition/meter/openems.yaml
Implemented battery control logic using HTTP API.
  • Added 'batterymode' section, conditional on the 'battery' parameter being set.
  • Used 'watchdog' source to reset the mode on timeout.
  • Used 'switch' source to handle different battery modes (normal, hold, charge).
  • Used 'http' source to send POST requests to the '/rest/channel/{battery}/SetActivePowerEquals' endpoint.
  • Configured basic authentication using existing credentials.
  • Set active power to 0 for 'normal' (1) and 'hold' (2) modes.
  • Marked 'charge' mode (3) as not implemented ('ErrNotAvailable').
templates/definition/meter/openems.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@iseeberg79
Copy link
Contributor Author

@andig draft completed, thought about initial battery parameter - comments welcome

@iseeberg79 iseeberg79 marked this pull request as ready for review April 29, 2025 19:00
Copy link
Contributor
@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 @iseeberg79 - I've reviewed your changes - here's some feedback:

  • The 'normal' (case 1) and 'hold' (case 2) battery modes appear to execute the identical action; consider clarifying the distinction or combining them if functionally equivalent.
  • The charge mode (case 3) is unimplemented; consider adding basic charge functionality if the API supports it or clarifying why it's unavailable.
  • The username for basic authentication appears hardcoded as 'x' in the template, while a 'user' parameter exists; consider using the parameter value instead.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 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 changed the title add battery-control for OpenEMS OpenEMS: add battery control Apr 30, 2025
@andig
Copy link
Member
andig commented Apr 30, 2025

Wieso bewirken zwei identische Posts unterschiedliches Verhalten? Hast du das getestet?

@andig andig added the devices Specific device support label Apr 30, 2025
- name: battery
example: ess0
help:
de: steuerbare Batterie Komponente
Copy link
Member

Choose a reason for hiding this comment

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

Hier fehlt noch der Hinweis, dass Fenecon dafür eine kostenpflichtige Lizenz erwartet.

8000 Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kann ich nachtragen!

@andig andig marked this pull request as draft April 30, 2025 09:02
@iseeberg79
Copy link
Contributor Author

Wieso bewirken zwei identische Posts unterschiedliches Verhalten? Hast du das getestet?

Ich brauche hier keinen POST, aber der Watchdog muss enden. Geht das auch ohne definierten case 1? War unsicher! Exklusiv Case 2 auszuführen wäre für die Funktion ausreichend. Dann würde ich ggf. über die Löschung von case 3 nachdenken wollen, und nur case 2 definieren.

Ja, das Template ist getestet. OpenEMS endet nach Timeout und kehrt im Standard nach 60s bei NORMAL in den nicht limitierten Zustand zurück.

@andig
Copy link
Member
andig commented Apr 30, 2025

Ahh, mhhm. Ich überleg mal ob sich case 1 klarer unterscheiden lässt.

@andig
Copy link
Member
andig commented Apr 30, 2025

Bitze noch Formatierung korrigieren.

@iseeberg79
Copy link
Contributor Author
iseeberg79 commented Apr 30, 2025

Bitze noch Formatierung korrigieren.

gefunden.. erledigt

@andig andig marked this pull request as ready for review April 30, 2025 14:21
@andig andig merged commit 5ceecd1 into evcc-io:master Apr 30, 2025
6 checks passed
@andig
Copy link
Member
andig commented Apr 30, 2025

Klasse PR, vielen Dank!

Copy link
Contributor
@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 @iseeberg79 - I've reviewed your changes - here's some feedback:

  • The 'normal' and 'hold' battery modes currently trigger the same API call; consider if 'hold' requires a different implementation.
  • Consider removing the unimplemented 'charge' mode case for clarity.
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.

default: 60s
help:
de: abgestimmt auf das API-Timeout
en: adjusted to the API timout
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (typo): Typo detected in the API help message.

Replace 'timout' with 'timeout'.

Suggested change
en: adjusted to the API timout
en: adjusted to the API timeout

@iseeberg79
Copy link
Contributor Author

Klasse PR, vielen Dank!

Typo ignorieren? Cooles Werkzeug..

@sfeilmeier
Copy link
Contributor

Just a few notes: SetActivePowerEquals does not actually control (only) the battery charge/discharge power but it refers to the AC-side of the battery inverter. If you wanted to discharge the battery during the day, you would have to add the DC-side production power to your set-point. Also: the current implementation does not allow curtailing the DC-side production power.

Thanks for improving the OpenEMS-integration! 👍

@iseeberg79
Copy link
Contributor Author
iseeberg79 commented May 12, 2025

Happy to contribute. I would have liked to set a constraint like lessOrEqual but did not figure out how to set via API. It would allow to charge the battery. The way it's actually implemented equals other inverter implementations and is compatible with not calculating and not setting power specific values to control the energy flow. It has positive effects and counterparts :-)
Because the user is able to decide it should be okay. Perhaps we should add your notes for documentation.
If you have an idea how to set a constraint it would allow another enhancement.

6D40

@sfeilmeier
Copy link
Contributor

There are Channels available to set the constraints: SetActivePowerLessOrEquals and SetActivePowerGreaterOrEquals. (https://github.com/OpenEMS/openems/blob/develop/io.openems.edge.ess.api/src/io/openems/edge/ess/api/ManagedSymmetricEss.java#L114-L145)

@iseeberg79
Copy link
Contributor Author
iseeberg79 commented May 13, 2025

@sfeilmeier I've tried using SetActivePowerLessOrEquals - it works fine, but I've found that the controllers from openEMS try to compensate for that. It has the effect that the battery is charged even when no power is available (home use) when testing. I suspect that the PID filter is trying to compensate for a short period of time. It then settles to a true zero after a few seconds.

We could adjust the template so that the channel is a constraint that allows the battery to charge (available PV energy). But we should be aware of the side effects. The current implementation sets a power of zero for the ESS device, so charging and discharging is not possible, preventing the home battery to charge the battery of the car.

We have discussed a comparable situation in the past with other inverters (e.g. Plenticore) and when in doubt decided that it is ok not to charge the battery when the car is (fast-)charging because most of the energy is probably used for charging the car. The implementation seems to be more robust if the power is fixed at zero. Of course, it would be desirable to charge the battery whenever possible using remaining energy. I don't want to make a decision here. What do you prefer?

Probably we need to replace
uri: http://{{ .host }}/rest/channel/{{ .battery }}/SetActivePowerEquals

with the following:
uri: http://{{ .host }}/rest/channel/{{ .battery }}/SetActivePowerLessOrEquals

@iseeberg79 iseeberg79 deleted the feature/openems-batterymode branch May 13, 2025 19:48
@iseeberg79 iseeberg79 restored the feature/openems-batterymode branch May 13, 2025 19:49
@iseeberg79 iseeberg79 deleted the feature/openems-batterymode branch May 13, 2025 19:55
@sfeilmeier
Copy link
Contributor

We have discussed a comparable situation in the past with other inverters (e.g. Plenticore) and when in doubt decided that it is ok not to charge the battery when the car is (fast-)charging because most of the energy is probably used for charging the car. The implementation seems to be more robust if the power is fixed at zero. Of course, it would be desirable to charge the battery whenever possible using remaining energy. I don't want to make a decision here. What do you prefer?

Your reasoning is absolutely correct. SetActivePowerLessOrEquals 0 would be a little bit smarter, but it might sometimes cause PID problems. At the same time there is usually some power remaining after surplus-charging a car (e.g. because the charging station only allows control in [A] and not in [mA]), which should ideally be charged to the battery. I am not using evcc myself (did not want to pay for the license, so I am just supporting the development a little bit). You will have to test it yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devices Specific device support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0