Skip to content

Conversation

@SolarPower2024
Copy link
Contributor

I´m having my battery implemented via a Home Assistant meter in evcc and unfortunately in this way the active battery control is not configurable. With this PR I´m trying to implement.
Please note I´m not a programmer, and this is basically my first try to adjust something like this. So kindly ask you to check, if this is even workable in that way.

cc also @scruysberghs and @sebastiansucker as you were working in the past on the homeassistant template. Maybe you also could take a look at it?

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 - I've found 1 issue, and left some high level feedback:

  • Consider making the strings 'normal', 'hold', and 'charge' configurable via template parameters so the setup can work with Home Assistant entities that use different option labels for the same battery modes.
  • You currently restrict the mode entity to the input_select domain; if some setups use select or another entity type for battery mode, you may want to broaden the service filter or make the domain configurable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider making the strings 'normal', 'hold', and 'charge' configurable via template parameters so the setup can work with Home Assistant entities that use different option labels for the same battery modes.
- You currently restrict the mode entity to the `input_select` domain; if some setups use `select` or another entity type for battery mode, you may want to broaden the `service` filter or make the domain configurable.

## Individual Comments

### Comment 1
<location> `templates/definition/meter/homeassistant.yaml:159-160` </location>
<code_context>
+  {{- if and (eq .usage "battery") .batterymodeswitch }}
+  batterymode:
+    source: switch
+    switch:
+    - case: 1 # normal
+      set:
+        source: homeassistant
</code_context>

<issue_to_address>
**issue (bug_risk):** Indentation of the `switch` sequence looks off and will likely produce invalid YAML.

`switch:` and `- case: 1` are currently aligned, so the list becomes a sibling of `switch` instead of its value, which will yield invalid or unexpected YAML. The list items should be indented under `switch:`, e.g.

```yaml
data:
  batterymode:
    source: switch
    switch:
      - case: 1 # normal
        set:
          ...
      - case: 2 # hold
        set:
          ...
      - case: 3 # charge
        set:
          ...
```
</issue_to_address>

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.

Comment on lines +159 to +160
switch:
- case: 1 # normal
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Indentation of the switch sequence looks off and will likely produce invalid YAML.

switch: and - case: 1 are currently aligned, so the list becomes a sibling of switch instead of its value, which will yield invalid or unexpected YAML. The list items should be indented under switch:, e.g.

data:
  batterymode:
    source: switch
    switch:
      - case: 1 # normal
        set:
          ...
      - case: 2 # hold
        set:
          ...
      - case: 3 # charge
        set:
          ...

@andig andig changed the title Add active battery control to Home Assistant meter Home Assistant meter: add active battery control Jan 1, 2026
@andig andig added the devices Specific device support label Jan 1, 2026
@andig andig marked this pull request as draft January 1, 2026 15:43
@SolarPower2024 SolarPower2024 marked this pull request as ready for review January 1, 2026 17:52
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 - I've found 1 issue, and left some high level feedback:

  • The YAML indentation under batterymode.switch looks off: the list items (- case: ...) should be indented under switch: (e.g. two spaces before - case) to ensure the generated config is valid.
  • The batterymode mapping hardcodes the three modes normal, hold, and charge; consider either documenting clearly that these are the only supported values for the linked input_select or making the options configurable via parameters to avoid coupling to a specific naming convention.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The YAML indentation under `batterymode.switch` looks off: the list items (`- case: ...`) should be indented under `switch:` (e.g. two spaces before `- case`) to ensure the generated config is valid.
- The batterymode mapping hardcodes the three modes `normal`, `hold`, and `charge`; consider either documenting clearly that these are the only supported values for the linked `input_select` or making the options configurable via parameters to avoid coupling to a specific naming convention.

## Individual Comments

### Comment 1
<location> `templates/definition/meter/homeassistant.yaml:111-113` </location>
<code_context>
       de: Entitäts-ID für L3 Spannungsmessung in Volt
   - name: soc
+    usages: ["battery"]
     description:
       de: Batterieladestand
       en: Battery State of Charge
</code_context>

<issue_to_address>
**issue (typo):** German description currently uses the English phrase, which might be unintended.

The `de` description currently reads `Battery Mode Switch Entity`, matching the English text. If that’s not intentional, please replace it with a German translation to stay consistent with the other localized descriptions.
</issue_to_address>

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.

Comment on lines 111 to 113
description:
de: Batterieladestand
en: Battery State of Charge
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (typo): German description currently uses the English phrase, which might be unintended.

The de description currently reads Battery Mode Switch Entity, matching the English text. If that’s not intentional, please replace it with a German translation to stay consistent with the other localized descriptions.

@andig andig marked this pull request as draft January 3, 2026 12:32
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.

2 participants