-
-
Notifications
You must be signed in to change notification settings - Fork 101
Charge automation #1496
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
Charge automation #1496
Conversation
Initial draft
extended with smart meter input
WalkthroughThe 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
Sequence DiagramsequenceDiagram
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
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 sliderConsider 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 prioritychargingProfileId
: Unique identifier for the profilechargingProfileKind
: Why "Relative" is usedConsider 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
📒 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)
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' |
There was a problem hiding this comment.
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.
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' |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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
📒 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 suggestionAdd 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: currentLikely invalid or redundant comment.
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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