Skip to content

Conversation

taste66
Copy link
Contributor

@taste66 taste66 commented Jan 21, 2025

The file gives examples and tips which can help in automating charge control. It is currently standalone no link from other documentation pages

Summary by CodeRabbit

  • Documentation
    • Added comprehensive guide for dynamically adjusting electric vehicle charge current in home automation systems.
    • Included instructions for OCPP integration in Home Assistant.
    • Provided code snippets and examples for solar power and smart meter-based charging strategies.
    • Emphasized safety measures to prevent charger damage and optimize energy usage.

extended with smart meter input
Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Walkthrough

The documentation update introduces a comprehensive guide on dynamically adjusting the electric vehicle (EV) charge current within a home automation system. It details the implementation of these adjustments using OCPP integration in Home Assistant, addressing strategies for optimizing solar power usage and managing energy costs. The guide emphasizes the importance of using a specific profile for charge current adjustments to protect the charger and prevent circuit overload.

Changes

File Change Summary
docs/Charge_automation.md Added comprehensive documentation on dynamic EV charge current adjustment, including:
- OCPP integration techniques
- Solar power current conversion
- Smart meter data integration
- Charge current calculation methods
- Warnings about potential charger damage and circuit overload

Sequence Diagram

sequenceDiagram
    participant Solar Panel
    participant Smart Meter
    participant Home Assistant
    participant EV Charger
    
    Solar Panel->>Home Assistant: Send Power Production
    Smart Meter->>Home Assistant: Send Grid Consumption
    Home Assistant->>EV Charger: Calculate Available Current
    Home Assistant->>EV Charger: Adjust Charge Current Dynamically
Loading

Poem

🔋 A Rabbit's Charge of Delight 🚗

Solar watts dance, meters spin with glee,
Charging my EV so efficiently!
Current flows smart, no circuit's despair,
Home Assistant guides with algorithmic flair
Electrons hop, green energy's might! 🌞


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (6)
docs/Charge_automation.md (6)

9-9: Fix grammatical errors in the benefits section.

There are several grammatical issues that affect readability:

  • Line 9: "avaiable" should be "available", and "Assistent" should be "Assistant"
  • Line 12: The sentence structure is incorrect. Consider: "When you have dynamic energy pricing, you can adjust charging rates based on time-of-use electricity pricing."
-    * When the solar panel production is avaiable in Home Assistent, you can prioritize charging the EV with excess solar energy.
+    * When the solar panel production is available in Home Assistant, you can prioritize charging the EV with excess solar energy.

-    * When you have dynamic energy pricing you charging rates based on time-of-use electricity pricing.
+    * When you have dynamic energy pricing, you can adjust charging rates based on time-of-use electricity pricing.

Also applies to: 12-12

🧰 Tools
🪛 Markdownlint (0.37.0)

9-9: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


18-24: Fix grammar and emphasize hardware safety warning.

The section contains important hardware safety information that should be emphasized. Also, there's a grammatical error:

  • Line 18: Add a comma after "Home Assistant"
-When the OCPP integration is added to your Home Assistent you get a slider
+When the OCPP integration is added to your Home Assistant, you get a slider

Consider adding a warning block to emphasize the hardware safety information:

+> ⚠️ **Warning**: Using the maximum current slider in automations can lead to permanent hardware damage due to frequent writes to non-volatile memory.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~18-~18: Possible missing comma found.
Context: ... OCPP integration is added to your Home Assistent you get a slider to control the maximum...

(AI_HYDRA_LEO_MISSING_COMMA)


[style] ~21-~21: ‘in the long run’ might be wordy. Consider a shorter alternative.
Context: ...ead to permanent damage to your charger in the long run. This entity controls the OCPP ChargePo...

(EN_WORDINESS_PREMIUM_IN_THE_LONG_RUN)


34-50: Add parameter documentation for the custom profile configuration.

The code example is correct, but it would be helpful to document the significance of key parameters:

  • stackLevel: Determines profile priority
  • chargingProfileId: Unique identifier for the profile
  • chargingProfileKind: Why "Relative" is used

Consider adding this explanation before the code block:

The custom profile uses these key parameters:
- `stackLevel`: 0 (highest priority, overrides other profiles)
- `chargingProfileId`: Unique identifier (1 in this example)
- `chargingProfileKind`: "Relative" means the schedule starts immediately

56-63: Fix spelling errors and clarify power conversion formula.

Several spelling errors need to be corrected, and the power conversion explanation could be clearer:

-The solar ystem usualy reports its production in Watt or kWatt. To convert this in the amps available for your EV-charger simply devide the Watt by the mains voltage (e.g 230V for the EU)
+The solar system usually reports its production in Watts or kW. To convert this to amps available for your EV charger, simply divide the watts by the mains voltage (e.g., 230V for the EU)

Consider adding the actual formula for clarity:

Formula: Current (A) = Power (W) ÷ Voltage (V)
🧰 Tools
🪛 LanguageTool

[uncategorized] ~56-~56: The abbreviation “e.g.” (= for example) requires two periods.
Context: ...y devide the Watt by the mains voltage (e.g 230V for the EU) You can create a templ...

(E_G)


88-90: Fix variable name typos and improve documentation.

The variable names contain spelling errors and the code could use better documentation:

   variables:
-     achtual_charge_current: "{{ (states('sensor.charge_current') | float) }}"
-     new_amps: "{{ actual_charge_current + (states('sensor.grid_current_available') | float) }}
+     actual_charge_current: "{{ (states('sensor.charge_current') | float) }}"
+     new_amps: "{{ actual_charge_current + (states('sensor.grid_current_available') | float) }}"

Add explanation for the max filter:

The `max` filter ensures the charge current never goes below 0 amps, which would be invalid for the charging station:

99-102: Fix grammar and emphasize safety information about fuse rating.

The section contains critical safety information that needs better formatting and grammar fixes:

-A simular solution could be use to check how much power is still available from the grid substracting all power used by other appliances in your house. This way you can charge you EV as fast as possible without overloading your main fuse. 
+A similar solution could be used to check how much power is still available from the grid by subtracting all power used by other appliances in your house. This way you can charge your EV as fast as possible without overloading your main fuse.

-:exclamation: By specificatiomn your main fuse can withand 1.2 its rate current for at least 1 hour 
+> ⚠️ **Safety Note**: By specification, your main fuse can withstand 1.2 times its rated current for at least 1 hour.
🧰 Tools
🪛 LanguageTool

[grammar] ~99-~99: Did you mean “used”?
Context: ...imum charge A simular solution could be use to check how much power is still availa...

(BE_USE_TO_DO)


[uncategorized] ~99-~99: “you” seems less likely than “your” (belonging to you).
Context: ... in your house. This way you can charge you EV as fast as possible without overload...

(AI_HYDRA_LEO_CP_YOU_YOUR)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 88cafb7 and 808dcce.

📒 Files selected for processing (1)
  • docs/Charge_automation.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/Charge_automation.md

[uncategorized] ~18-~18: Possible missing comma found.
Context: ... OCPP integration is added to your Home Assistent you get a slider to control the maximum...

(AI_HYDRA_LEO_MISSING_COMMA)


[style] ~21-~21: ‘in the long run’ might be wordy. Consider a shorter alternative.
Context: ...ead to permanent damage to your charger in the long run. This entity controls the OCPP ChargePo...

(EN_WORDINESS_PREMIUM_IN_THE_LONG_RUN)


[uncategorized] ~56-~56: The abbreviation “e.g.” (= for example) requires two periods.
Context: ...y devide the Watt by the mains voltage (e.g 230V for the EU) You can create a templ...

(E_G)


[typographical] ~72-~72: Use a comma after an introductory phrase.
Context: ...ld demand.you might have it as power. For this it is important to know the current you...

(COMMA_INTRODUCTORY_WORDS_PHRASES)


[uncategorized] ~73-~73: “you” seems less likely than “your” (belonging to you).
Context: ... or receive from the grid. Depending on you smart meter sensors you might have this...

(AI_HYDRA_LEO_CP_YOU_YOUR)


[uncategorized] ~73-~73: Possible missing comma found.
Context: ... the grid. Depending on you smart meter sensors you might have this current available i...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~73-~73: Use a comma before ‘or’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... have this current available in a sensor or you might have this as power. The examp...

(COMMA_COMPOUND_SENTENCE)


[typographical] ~74-~74: It appears that a comma is missing.
Context: ...e when receiving from the grid. In this example the power is in kW and the current is c...

(DURING_THAT_TIME_COMMA)


[typographical] ~86-~86: Usually, there’s no comma before “when”.
Context: ...e your EV charge number with this number, when negative you need to decrease. This mea...

(IF_NO_COMMA)


[uncategorized] ~86-~86: Possible missing comma found.
Context: ...rge current and modify this. To do this easily you can use a variable inside your auto...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~99-~99: Did you mean “used”?
Context: ...imum charge A simular solution could be use to check how much power is still availa...

(BE_USE_TO_DO)


[uncategorized] ~99-~99: “you” seems less likely than “your” (belonging to you).
Context: ... in your house. This way you can charge you EV as fast as possible without overload...

(AI_HYDRA_LEO_CP_YOU_YOUR)

🪛 Markdownlint (0.37.0)
docs/Charge_automation.md

6-6: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


9-9: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


12-12: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

Comment on lines +80 to +83
value_template: >-
{{((states('sensor.p1_meter_p1_returned') | float - states('sensor.p1_meter_p1_power') | float )*1000
/ (states('sensor.p1_meter_p1_voltage') | float )) }}
unit_of_measurement: 'A'
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 21, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add safety check for voltage division.

The current calculation could fail if the voltage sensor returns zero or invalid values. Consider adding validation:

              value_template: >-
-              {{((states('sensor.p1_meter_p1_returned') | float - states('sensor.p1_meter_p1_power') | float )*1000 
-              / (states('sensor.p1_meter_p1_voltage') | float )) }}
+              {% set voltage = states('sensor.p1_meter_p1_voltage') | float %}
+              {% if voltage > 0 %}
+                {{((states('sensor.p1_meter_p1_returned') | float - states('sensor.p1_meter_p1_power') | float )*1000 
+                / voltage ) }}
+              {% else %}
+                {{ 0 }}
+              {% endif %}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
value_template: >-
{{((states('sensor.p1_meter_p1_returned') | float - states('sensor.p1_meter_p1_power') | float )*1000
/ (states('sensor.p1_meter_p1_voltage') | float )) }}
unit_of_measurement: 'A'
value_template: >-
{% set voltage = states('sensor.p1_meter_p1_voltage') | float %}
{% if voltage > 0 %}
{{((states('sensor.p1_meter_p1_returned') | float - states('sensor.p1_meter_p1_power') | float )*1000
/ voltage ) }}
{% else %}
{{ 0 }}
{% endif %}
unit_of_measurement: 'A'

Copy link

Choose a reason for hiding this comment

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

should be
{% set voltage = states('sensor.p1_meter_p1_voltage') | float(0) %}

If the component is not defined or is currently unavailable, 0 will be returned with float(0)

Copy link
Contributor

Choose a reason for hiding this comment

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

@rbb-dev Thank you for the correction. You're absolutely right - using float(0) is a better approach as it handles undefined or unavailable components gracefully.


✏️ Learnings added
Learnt from: rbb-dev
PR: lbbrhzn/ocpp#1496
File: docs/Charge_automation.md:83-86
Timestamp: 2025-01-21T23:57:18.708Z
Learning: In Home Assistant templates, use `float(0)` instead of `float()` when converting sensor values to ensure a default value of 0 is returned if the component is undefined or unavailable.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you this is indeed a problem I already ran into

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Updated after coderabit check
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
docs/Charge_automation.md (3)

5-12: Adjust list indentation for consistency.

The unordered list items should use 2 spaces for indentation instead of 4 to follow Markdown best practices.

-    * By monitoring real-time energy consumption, you can automatically reduce the EV's charging rate to prevent overloading the household's electrical circuits and potentially tripping the main fuse.
+  * By monitoring real-time energy consumption, you can automatically reduce the EV's charging rate to prevent overloading the household's electrical circuits and potentially tripping the main fuse.

-    * When the solar panel production is available in Home Assistant, you can prioritize charging the EV with excess solar energy.
+  * When the solar panel production is available in Home Assistant, you can prioritize charging the EV with excess solar energy.

-    * When you have dynamic energy pricing, you can adjust charging rates based on time-of-use electricity pricing.
+  * When you have dynamic energy pricing, you can adjust charging rates based on time-of-use electricity pricing.
🧰 Tools
🪛 Markdownlint (0.37.0)

6-6: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


9-9: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


12-12: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


26-26: Make the warning more prominent.

Consider using a dedicated warning block for better visibility:

-⚠️ **Warning**: Using the maximum current slider in automations can lead to permanent hardware damage due to frequent writes to non-volatile memory.
+> ⚠️ **DANGER**: Using the maximum current slider in automations can lead to permanent hardware damage due to frequent writes to non-volatile memory. This damage may not be covered by warranty.

102-106: Fix typos and grammar in the maximum charge section.

Several typos and grammatical errors need to be corrected:

-A simular solution could be used to check how much power is still available from the grid substracting all power used by other appliances in your house. This way you can charge you EV as fast as possible without overloading your main fuse. 
+A similar solution could be used to check how much power is still available from the grid by subtracting all power used by other appliances in your house. This way you can charge your EV as fast as possible without overloading your main fuse.

-:exclamation: By specificatiomn your main fuse can withand 1.2 its rate current for at least 1 hour 
+:exclamation: By specification, your main fuse can withstand 1.2 times its rated current for at least 1 hour.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~102-~102: “you” seems less likely than “your” (belonging to you).
Context: ... in your house. This way you can charge you EV as fast as possible without overload...

(AI_HYDRA_LEO_CP_YOU_YOUR)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 808dcce and a23ef73.

📒 Files selected for processing (1)
  • docs/Charge_automation.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/Charge_automation.md

[style] ~21-~21: ‘in the long run’ might be wordy. Consider a shorter alternative.
Context: ...ead to permanent damage to your charger in the long run. This entity controls the OCPP ChargePo...

(EN_WORDINESS_PREMIUM_IN_THE_LONG_RUN)


[typographical] ~75-~75: Use a comma after an introductory phrase.
Context: ...ld demand.you might have it as power. For this it is important to know the current you...

(COMMA_INTRODUCTORY_WORDS_PHRASES)


[uncategorized] ~76-~76: “you” seems less likely than “your” (belonging to you).
Context: ... or receive from the grid. Depending on you smart meter sensors you might have this...

(AI_HYDRA_LEO_CP_YOU_YOUR)


[uncategorized] ~76-~76: Possible missing comma found.
Context: ... the grid. Depending on you smart meter sensors you might have this current available i...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~76-~76: Use a comma before ‘or’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... have this current available in a sensor or you might have this as power. The examp...

(COMMA_COMPOUND_SENTENCE)


[typographical] ~77-~77: It appears that a comma is missing.
Context: ...e when receiving from the grid. In this example the power is in kW and the current is c...

(DURING_THAT_TIME_COMMA)


[typographical] ~89-~89: Usually, there’s no comma before “when”.
Context: ...e your EV charge number with this number, when negative you need to decrease. This mea...

(IF_NO_COMMA)


[uncategorized] ~89-~89: Possible missing comma found.
Context: ...rge current and modify this. To do this easily you can use a variable inside your auto...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~102-~102: “you” seems less likely than “your” (belonging to you).
Context: ... in your house. This way you can charge you EV as fast as possible without overload...

(AI_HYDRA_LEO_CP_YOU_YOUR)

🪛 Markdownlint (0.37.0)
docs/Charge_automation.md

6-6: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


9-9: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


12-12: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

🔇 Additional comments (2)
docs/Charge_automation.md (2)

83-86: Add safety check for voltage division.


62-68: 🛠️ Refactor suggestion

Add validation for power and voltage values.

The current calculation should handle edge cases for power values and use actual voltage when available.

     - platform: template
       sensors:
         solaredge_amps:
-        value_template: "{{ (states('sensor.solaredge_power') | round(0, 'floor')| float) / 230 }}"
+        value_template: >-
+          {% set power = states('sensor.solaredge_power') | float %}
+          {% set voltage = states('sensor.grid_voltage') | default(230) | float %}
+          {% if power >= 0 and voltage > 0 %}
+            {{ (power / voltage) | round(1) }}
+          {% else %}
+            {{ 0 }}
+          {% endif %}
         unit_of_measurement: 'A'
         device_class: current

Likely invalid or redundant comment.

@lbbrhzn lbbrhzn temporarily deployed to continuous-integration March 2, 2025 09:37 — with GitHub Actions Inactive
Copy link

codecov bot commented Mar 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.75%. Comparing base (b9d722d) to head (6a35d9b).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1496   +/-   ##
=======================================
  Coverage   92.75%   92.75%           
=======================================
  Files          12       12           
  Lines        2030     2030           
=======================================
  Hits         1883     1883           
  Misses        147      147           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lbbrhzn lbbrhzn merged commit 0eda93e into lbbrhzn:main Mar 2, 2025
9 checks passed
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.

3 participants