Skip to content
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

feat: blueprint for EV management #55

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions blueprints/priority_to_ev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
blueprint:
name: "Solar Router EV Control"
description: "Controls a solar router based on energy diversion, eletric vehicule connection and grid export conditions"
domain: automation
input:
ev_connected:
name: EV Connected
description: "Sensor indicating if the electric vehicle is connected"
selector:
entity:
domain: binary_sensor
energy_diversion:
name: Energy Diversion (solar_router.regulator_opening)
description: "Sensor for current energy diversion percentage"
selector:
entity:
domain: number
energy_sent_to_grid:
name: Energy Sent to Grid (solar_router.real_power)
description: "Sensor for energy being sent to the grid (Ex: use real_power of your solar router)"
selector:
entity:
domain: sensor
solar_router:
name: Solar Router (solar_router.activate)
description: "Switch entity for the solar router"
selector:
entity:
domain: switch
max_diverted_energy:
name: Max Diverted Energy
description: "Maximum percentage of energy that should be diverted"
default: 100
selector:
number:
min: 0
max: 100
unit_of_measurement: "%"
excess_energy_threshold:
name: Excess Energy Threshold
description: "Threshold for excess energy sent to grid (could be negative)"
default: 500
selector:
number:
min: 0
max: 3000
unit_of_measurement: "W"
delay_before_deactivation:
name: Delay Before Deactivation
description: "Delay in seconds before deactivating the solar router"
default: 60
selector:
number:
min: 0
max: 300
unit_of_measurement: "seconds"
max_energy_sent:
name: Max Energy Sent
description: "Maximum energy that can be sent to the grid before reactivating the solar router"
default: 200
selector:
number:
min: 0
max: 3000
unit_of_measurement: "W"
delay_before_activation:
name: Delay Before Activation
description: "Delay in seconds before activating the solar router"
default: 60
selector:
number:
min: 0
max: 300
unit_of_measurement: "seconds"

trigger:
- platform: event
event_type: automation_reloaded
- platform: state
entity_id: !input ev_connected
- platform: numeric_state
entity_id: !input energy_sent_to_grid
above: !input excess_energy_threshold
for:
seconds: !input delay_before_deactivation
- platform: numeric_state
entity_id: !input energy_sent_to_grid
above: !input max_energy_sent
for:
seconds: !input delay_before_activation

action:
- choose:
# Condition 1: Deactivate solar router when EV need to be recharged
- conditions:
- condition: state
entity_id: !input ev_connected
state: "on"
- condition: state
entity_id: !input solar_router
state: "on"
- condition: numeric_state
entity_id: !input energy_diversion
above: !input max_diverted_energy
- condition: numeric_state
entity_id: !input energy_sent_to_grid
above: !input excess_energy_threshold
sequence:
- service: switch.turn_off
target:
entity_id: !input solar_router
# Condition 2: Reactivate solar router when EV battery is full
- conditions:
- condition: state
entity_id: !input ev_connected
state: "on"
- condition: state
entity_id: !input solar_router
state: "off"
- condition: numeric_state
entity_id: !input energy_sent_to_grid
above: !input max_energy_sent
sequence:
- service: switch.turn_on
target:
entity_id: !input solar_router
# Condition 3: Activate solar router when EV disconnected
- conditions:
- condition: state
entity_id: !input ev_connected
state: "off"
sequence:
- service: switch.turn_on
target:
entity_id: !input solar_router

49 changes: 49 additions & 0 deletions docs/bleuprint_ev_management.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Blueprint for EV management

This blueprint is designed to activate and deactivate the solar router when EV requiring charge is connected and enough energy is produced to charge this EV.

Here is a transcription of the prompt which help me to create this blueprint wiht AI.
It clearly explain how it behaves:

```
I would like to write a blueprint for Home Assistant that implements the following algorithm:

// EV is disconnected
IF NOT ev_connected
THEN activate the solar router

// EV is connected and its battery needs to be charged
IF ev_connected
AND energy_diversion > max_diverted_energy (%)
AND energy_sent_to_grid is greater than excess_energy_threshold
FOR delay_before_deactivation in seconds
THEN deactivate the solar router

// EV battery is fully charged
IF ev_connected
AND the solar router is deactivated
AND the energy sent back to the grid is greater than max_energy_sent
FOR delay_before_activation
THEN activate the solar router.

The blueprint should be written in English and each variable should be commented.
```

To install this blueprint, refer to [Home assistant documention](https://www.home-assistant.io/docs/automation/using_blueprints/).

The URL to use is : [https://raw.githubusercontent.com/XavierBerger/Solar-Router-for-ESPHome/refs/heads/main/blueprints/priority_to_ev.yaml](https://raw.githubusercontent.com/XavierBerger/Solar-Router-for-ESPHome/refs/heads/main/blueprints/priority_to_ev.yaml)

!!! note
EV connected is a binary sensor. If your EV charge is displaying a string saying id EV is connected or not it will be required to create a custom sensors to create this binary sensor.

Example for MyEnergi Zappi:

```yaml
template:
- binary_sensor:
- name: "EV Connected Status"
unique_id: ev_connected_status
state: "{{ is_state('sensor.myenergi_zappi_plug_status', 'EV Connected') }}"
device_class: plug

```
4 changes: 2 additions & 2 deletions docs/en/alternatives.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ If it doesn't fully feat your needs, you may have a look to the following projec

* [PvRouter](https://ota.apper-solaire.org/) from **Cyril P** (in French), site français qui propose un routeur solaire clé en main avec une carte électronique dédiée.

* [Routeur Photovoltaïque](http://f1atb.fr) from **André** (in French), routeur solaire multi-source qui a été la source d'inspiration de **Solar-Router-for-ESPHome**
* [Routeur Photovoltaïque](https://f1atb.fr) from **André** (in French), routeur solaire multi-source qui a été la source d'inspiration de **Solar-Router-for-ESPHome**

* [PV-Routeur Solaire ESP Home](https://domo.rem81.com/index.php/2023/07/18/pv-routeur-solaire/) from **Remy**, Routeur solaire à base de ESPHome qui a aussi été source d'inspiration pour **Solar-Router-for-ESPHome**

!!! note "Missing alternative?"
Feel free to open an issue on [GitHub](https://github.com/XavierBerger/Solar-Router-for-ESPHome/issues) and I'll update this page with this alternative.
Feel free to open an issue on [GitHub](https://github.com/XavierBerger/Solar-Router-for-ESPHome/issues) and I'll update this page with this alternative.
8 changes: 4 additions & 4 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ nav:
- Home Assistant: temperature_limiter_home_assistant.md
- DS18B20: temperature_limiter_DS18B20.md
- Home Assistant:
- Blueprint for EV management: bleuprint_ev_management.md
- Recorder configuration: recorder_configuration.md
- About:
- ChangeLog: changelog.md
- License: license.md
- ChangeLog: changelog.md
- License: license.md
- Contributing: contributing.md
- compile_coverage.md
- Alternatives: alternatives.md
- About the project: about.md

- Alternatives: alternatives.md

theme:
name: material
Expand Down
8 changes: 8 additions & 0 deletions solar_router/engine_common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ light:
- state: False
brightness: 100%
duration: 250ms

sensor:
- platform: template
name: "Regulator Opening Sensor"
id: regulator_opening_sensor
unit_of_measurement: "%"
accuracy_decimals: 0
lambda: return id(regulator_opening).state;