Hello to the community! I would appreciate some help to check yaml code.
I am trying to use HA to create a dynamic charging automation for my BMW i4 using the BMW Connect integration.
I live in Belgium in Flemish region. Over here the final price of electricity is influenced by the peak electricity consumption. For this reason, I would like to keep my total drawn from the grid at max 2500 W.
I have an EV charger that I cannot control. My car charging can be controlled through BMW Connect. When no limit is applied, the car is using more than 7kW.
Using BMW Connect, I can limit the Amperes from 0 to 32. The automations below were intended to do the following (but ID 001 is not working):
ID 001
When the car is connected to the EV charger (binary_sensor.i4_m50_charging_status_2) AND the Override button is off (input_button.override_ev_charging)
Should change the A (sensor.i4_m50_ac_current_limit) to keep electricity from the grid bellow 2500W
ID 002
Should change the A limit to 32A when I disconnect from the charger
ID 003
Should Override ID 001 in case I need to get max charging speed
Any help really appreciated
This it the code from my automation.yaml
- id: '001'
alias: Dynamic EV Charging Amperage
description: Dynamically adjust EV charging amperage to keep total house consumption
below 2500 watts
triggers:
- entity_id: sensor.dsmr_reading_electricity_currently_delivered_watt
for: 00:01:00
trigger: state
conditions:
- condition: state
entity_id: binary_sensor.i4_m50_charging_status_2
state: 'on'
- condition: state
entity_id: input_button.override_ev_charging
state: 'off'
actions:
- variables:
total_power: '{{ states(''sensor.dsmr_reading_electricity_currently_delivered_watt'')
| float }}'
max_allowed_power: 2500
current_amperage: '{{ states(''sensor.i4_m50_ac_current_limit'') | float }}'
voltage: 230
- choose:
- conditions:
- condition: template
value_template: '{{ total_power > max_allowed_power }}'
sequence:
- target:
entity_id: sensor.i4_m50_ac_current_limit
data:
value: '{% set excess_power = total_power - max_allowed_power %} {% set
new_amperage = current_amperage - (excess_power / voltage) %} {{ [new_amperage,
0] | max | round(1) }} # Allow amperage to go down to 0A
'
action: number.set_value
- conditions:
- condition: template
value_template: '{{ total_power < max_allowed_power }}'
sequence:
- target:
entity_id: sensor.i4_m50_ac_current_limit
data:
value: '{% set available_power = max_allowed_power - total_power %} {% set
new_amperage = current_amperage + (available_power / voltage) %} {{ [new_amperage,
32] | min | round(1) }} # Ensure amperage doesn''t exceed 32A
'
action: number.set_value
mode: single
- id: '002'
alias: Reset EV Charging Amperage on Unplug
description: Set the charging limit to 32A when the EV is unplugged
trigger:
- platform: state
entity_id: binary_sensor.i4_m50_charging_status_2
from: 'on'
to: 'off'
action:
- service: number.set_value
target:
entity_id: sensor.i4_m50_ac_current_limit
data:
value: 32
mode: single
- id: '003'
alias: Override EV Charging
description: Set the charging limit to 32A when the override button is pressed
trigger:
- platform: state
entity_id: input_boolean.override_ev_charging
to: 'on'
action:
- service: number.set_value
target:
entity_id: number.your_bmw_charging_amperage
data:
value: 32
mode: single