Github Gist: Tesla controlled charge rate based on power sensor · GitHub
Purpose
Dynamically adjusts Tesla EV AC charging load to keep the overall power load within the capacity of the home power infrastructure.
This functionality is also known as load curtailment, load management, load shedding, and dynamic load management.
Similar functionality to Smart EV chargers with load curtailment features, but by using an existing power sensor (CT claim sensor) in your home and the Telsa cars charge rate controls.
IMPORTANT => Use at your own risk
Smart EV chargers with load curtailment features (i.e. using their own power/CT clamp sensor) are superior to what this automation can provide because they are dedicated to that task, respond quicker to load changes and have higher availability.
Requirements
-
Tesla HACS Integration
alandtse/tesla: Tesla custom integration for Home Assistant. (github.com)
a. Controls > Safety > Allow Mobile Access must be enabled in car -
CT clamp sensor to measure grid power
Integrating your electricity grid - Home Assistant
Must provide a “power” device class and a unit of measurement of W or kW (take note of this) via an entity in Home Assistant.
e.g.
state_class: measurement
unit_of_measurement: W
device_class: power
friendly_name: Main Power Meter power
Optional Integrations
- EV charger controlled charge rate (instead of Tesla vehicles native one), currently only Lektrico is supported
Lektrico/ha_lektrico: Manage your Lektrico EV Charger (github.com)
Operation
Responds by decreasing the charge rate significantly when an upper or maximum W value is reached by a power sensor.
Checks every x minutes to find the optimum charging value based on current power sensor value W.
Increases charge rate by 1 amp every x minutes (+ random delay of 1-30 seconds if the power sensor is below a lower W value. Stops delay and restarts the automation if another trigger occurs.
Only operates while charging is occurring and when the Tesla is at a specified (Home/Away/Any), to prevent changing charging rates while not connected to the power sensor selected.
See the example below from Home Assistant showing it in action.
Configuration Recommendations
The default values for the blueprint at based on 60 amp 240 volt service which calculates to a technical max of 14400 watts and the Tesla EV charger is capable of 10A.
These are the default values based on power sensors which measure in W, they must adjusted to match your use case.
- Power Sensor 1 Max value: 11000
- Power Sensor 1 Upper value: 8000
- Power Sensor 1 Lower value: 6000
- Polling frequency: 5 minutes
- Peak amps for charger: 8
- Minimum amps for charger: 2
11000 watts is used as the max value so very little charging occurs if the load is high, headroom from uncontrolled loads is getting close to the technical maximum of 14400 watts at this level.
Between 6000 and 8000 watts is where we want the charging to occur. This provides a bit of headroom for other dynamic loads to come online before the charging is knocked back to its minimum amp value of 2 amps.
Polling is set to 5 minutes to allow a gradual but useful increase in charging amps as well as a frequent additional check the power upper value hasn’t been exceeded.
Power Sensor 2 can be used to point at either the same sensor as Power Sensor 1 but with a higher value. i.e. 12000W, or if you have an additional sensor from another high-load device like a clothes dryer or kitchen oven set to that device’s sensor and an appropriate value like 2000W. The only purpose of this is to provide an additional trigger to quickly knock back the charging rate.
If you have multiple Teslas charging at the same location, you can create an automation based on this blueprint for each Tesla. You may need to increase the range between the lower and upper-value w to prevent them from knocking each other’s charging rates back frequently.
The location (Home/Away) is based on the home location of the Tesla account configured in Home Assistant.
Future improvements
This blueprint is could be modified to work with other brand EVs or control Smart EV chargers without CT clamps. Please let me know if you have a use case like this.
It was developed using the Tesla Mobile Connector and cars native charge rate controls, but I would also be interested if controlling the charging of a Tesla Gen3 Wall Connector can be done using this automation. They don’t currently support load shedding using a CT clam.
Troubleshooting
The version of the blueprint is shown in the description of the automation, check if this is the latest.
Blueprint Code
Show
blueprint:
name: Tesla controlled charge rate based on power sensor
description: |
## Tesla controlled charge rate based on power sensor
Checks every x minutes to find the optimum charging value based on home power usage W.
Decreases charge rate significantly when a upper or maximum W value is reached by a power sensor.
Increases charge rate by 1 every x minutes if power sensor is below a lower W value.
**IMPORTANT => Use at your own risk. Please see the discussions in the Home Assistant community**
*[Blueprint Version: 0.04.01](https://community.home-assistant.io/t/tesla-controlled-charge-rate-based-on-power-sensor/607107)*
domain: automation
input:
power_sensor_1_entity:
name: Power Sensor 1
description: This is the main power sensor that will be used to measure load (e.g. sensor.main_meter_power), check the state of the sensor to determine if it uses W or kW and use the same units when setting trigger values.
selector:
entity:
filter:
- domain: sensor
device_class: power
power_sensor_1_max_value:
name: Power Sensor 1 Trigger Max Value (W or kW based on sensor type)
description: This is a absolute max value which will trigger a drop in charging amps.
default: 11000
selector:
number:
min: 0
max: 100000
mode: box
power_sensor_1_charge_upper_value:
name: Power Sensor 1 Trigger Upper Value (W or kW based on sensor type)
description: This is the upper value for the power sensor which will trigger a drop in charging amps.
default: 8000
selector:
number:
min: 0
max: 100000
mode: box
power_sensor_1_charge_lower_value:
name: Power Sensor 1 Charging Lower Value (W or kW based on sensor type)
description: This is the value for the power sensor which allows the charger to increase amps.
default: 6000
selector:
number:
min: 0
max: 100000
mode: box
polling_time:
name: Polling frequency (Mins)
description: Number of minutes before checking if charging amps can be increased.
default: /5
selector:
select:
options:
- label: 1 min
value: /1
- label: 5 mins
value: /5
- label: 15 mins
value: /15
- label: 30 mins
value: /30
tesla_charging_state_entity:
name: Select the Tesla charging state entity
description: Select the entity which represents the Tesla charging state (e.g. binary_sensor.tesla_charging)
selector:
entity:
filter:
- domain: binary_sensor
device_class: battery_charging
tesla_charging_amps_number_entity:
name: Select the Tesla charging amps entity
description: Select the entity which represents the Tesla charging amps (e.g. number.tesla_charging_amps)
selector:
entity:
filter:
- domain: number
integration: tesla_custom
- domain: number
integration: tesla
- domain: number
integration: lektrico_custom
tesla_charging_amps_upper_value:
name: Select the peak amps for charger (Amps)
description: Select the number of amps that charging should not be increased past. Best set to the maximum charge rate possible with the charger, or a lower value. Not higher than the maximum possible with the charger.
default: 8
selector:
number:
min: 0
max: 32
step: 1
mode: slider
tesla_charging_amps_lower_value:
name: Select the minimum amps for charger (Amps)
description: Select the number of amps to reduce charging to when a power sensor upper/max value is exceeded
default: 2
selector:
number:
min: 0
max: 32
step: 1
mode: slider
tesla_device_tracker_entity:
name: Select the Tesla location entity
description: Select the entity which represents the Tesla location (e.g. device_tracker.tesla_location_tracker)
selector:
entity:
filter:
- domain: device_tracker
integration: tesla_custom
- domain: device_tracker
integration: tesla
tesla_control_location:
name: Select the Tesla location to be controlled
description: Select the location where the charging should be controlled (e.g. Home)
default: home
selector:
select:
options:
- label: Home
value: home
- label: Away
value: not_home
- label: Any
value: "null"
power_sensor_2_entity:
name: Power Sensor 2
description: Additional power sensor which can trigger a drop in charging amps (e.g. 2nd high load monitor). If no additional power sensor is required, set to the same entity as Power Sensor 1 but with a higher trigger max value, it can then act as backup trigger.
selector:
entity:
filter:
- domain: sensor
device_class: power
power_sensor_2_max_value:
name: Power Sensor 2 Trigger Max Value (W or kW based on sensor type)
description: This is a absolute max value which will trigger a drop in charging amps.
selector:
number:
min: 0
max: 100000
mode: box
source_url: https://gist.github.com/DataBitz/bcccb37ab0678286bc8cabb23a61d4cb
variables:
var_tesla_charging_amps_number_entity: !input tesla_charging_amps_number_entity
trigger:
- platform: numeric_state
entity_id: !input power_sensor_1_entity
above: !input power_sensor_1_max_value
id: power_1_max_trigger
- platform: numeric_state
entity_id: !input power_sensor_1_entity
above: !input power_sensor_1_charge_upper_value
id: power_1_upper_trigger
- platform: time_pattern
minutes: !input polling_time
enabled: true
id: polling_time_trigger
- platform: numeric_state
entity_id: !input power_sensor_2_entity
above: !input power_sensor_2_max_value
id: power_2_max_trigger
condition:
- condition: state
entity_id: !input tesla_charging_state_entity
state: "on"
enabled: true
- condition: state
entity_id: !input tesla_device_tracker_entity
state: !input tesla_control_location
action:
- if:
- condition: trigger
id:
- polling_time_trigger
then:
- delay:
hours: 0
minutes: 0
seconds: "{{ range(1, 30) | random }}"
milliseconds: 0
- if:
- condition: numeric_state
entity_id: !input power_sensor_1_entity
above: !input "power_sensor_1_charge_upper_value"
then:
- service: number.set_value
data:
value: !input "tesla_charging_amps_lower_value"
target:
entity_id: !input tesla_charging_amps_number_entity
alias: Cut Tesla charging rate significantly
else:
- condition: numeric_state
entity_id: !input power_sensor_1_entity
below: !input "power_sensor_1_charge_lower_value"
alias: Check load from main power sensor is low enough to allow increase in charging rate
- condition: numeric_state
entity_id: !input tesla_charging_amps_number_entity
below: !input tesla_charging_amps_upper_value
alias: Check charging amp rate is not already at or above the desired upper value
- service: number.set_value
target:
entity_id: !input tesla_charging_amps_number_entity
data:
value: "{{ states(var_tesla_charging_amps_number_entity) | int + 1 }}"
alias: Increase charging rate by 1 amp
alias: >-
Adjust Tesla charging amp based on Home EV Charging Max Power and Target values
mode: restart
Changelog
* 0.01.05 Initial version published to HA Blueprint Exchange
* 0.02.03 Adds random delay (1-30 seconds) to polling, so when multiple copies of the automation are being used (i.e. multiple Tesla’s), it prevents them from all increasing load at exactly the same time.
Trigger mode changed to restart, to allow an overload trigger to stop the existing automation - i.e. while waiting for delay time.
* 0.03.00 Can now control charge amps using Lektrico EV chargers (lektrico_custom) instead of Tesla. Thanks to Cquad
* 0.04.01 Updated descriptions and configuration guide to explain that if kW sensors are used as triggers, values in automation must be in kW. Added link to HA Community page.