As I have had received the request to share my project on another forum, I have decided to document it here in a structured way. Hoping it inspires or triggers additional idea’s.
The objective of this set of automations is to activate the charging of a Tesla when the electricity produced by my solar panels would normally be sent back to the grid.
In order to only charge when I don’t use the solar electricity I produce I actually based the triggers on the net (negative) consumption from the digital meter, but one could consider only using energy produced from solar panels as an alternative trigger.
Preparing for the 2022 electricty rate card that will be based on peak usage in my area, I also included a reverse trigger to stop charging when the rest of the house is using electricty.
Setup
Hardware :
- A Tesla (but I guess it could work with many EV’s) on a basic wall connector;
- Homewizard P1 meter (https://www.homewizard.nl/homewizard-wi-fi-p1-meter) attached to digital meter;
Integrations :
- Tesla Custom Integration (https://github.com/alandtse/tesla) installed via HACS
It’s very similar to the official Tesla Integraton, but seems much more stable as far as login/MFA management is concerned. - HomeWizard Energy integration (https://github.com/DCSBL/ha-homewizard-energy) installed via HACS
My installation produces a maximum of 4 KWh.
I have set the Tesla to charge at 13A when at home (you can configure that in the car based on geo-location): charging at 3KWh, which is purposely low and enough for my needs. If you charge at a higher rate, some thresholds will have to be adapted in the codes below (otherwise charging would overpass the threshold and provoke the end of charging by itself).
Automations
There are two basic automations:
- The basic: activate charging switch when electricity is available
- id: 'Tesla001'
alias: Tesla - Active charge si électricité solaire disponible (>2KWh exporté &
batterie <80%)
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.fluvius_p1_active_power
below: '-2000'
#value to be adapted based on your solar capacity & charging rate
for: 00:00:20
#adding a 'for' duration condition to avoid start on short sunbursts, if you want to avoid multiple on/offs you may increase that duration
condition:
- condition: state
entity_id: device_tracker.[TeslaName]_location_tracker
state: home
#making sure this only activates when the Tesla is actually at home
- condition: state
entity_id: binary_sensor.[TeslaName]_charger_sensor
state: 'on'
- condition: state
entity_id: switch.[TeslaName]_charger_switch
state: 'off'
#avoid a loop where the automation would try to turn on a switch that's already on
action:
- service: switch.turn_on
target:
entity_id: switch.[TeslaName]_charger_switch
mode: single
- Stop charging when consumming too much from the grid
- id: 'Tesla002'
alias: Tesla - Couper charge si consommation trop élevée (>1500)
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.fluvius_p1_active_power
above: '1500'
for: 00:01:00
#adding a 'for' duration condition to avoid stop on every small cloud, if you want to avoid multiple on/offs you may increase that duration
condition:
- condition: state
entity_id: device_tracker.[TeslaName]_location_tracker
state: home
#making sure this only activates when the Tesla is actually at home
- condition: numeric_state
entity_id: sensor.[TeslaName]_charging_rate_sensor
above: '2'
#making sure this only activates when the Tesla is actually charging: using the charging rate value seemed more stable than the state of the switch
- condition: not
conditions:
- condition: state
entity_id: switch.[TeslaName]_maxrange_switch
state: 'on'
#"misusing" the Max Range switch to force charging even if conditions are not optimal, this switch is used in different automations
action:
- service: switch.turn_off
target:
entity_id: switch.[TeslaName]_charger_switch
mode: single
On top of these, there are ways to fine-tune the concept, for instance:
- Making sure charging stops quickly when above acceptable peak (unless battery is really low)
- id: 'Tesla006'
alias: Tesla - Stop Charge au-dessus de 5.4KWH
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.fluvius_p1_active_power
above: '5400'
condition:
- condition: state
entity_id: device_tracker.[TeslaName]_location_tracker
state: home
- condition: numeric_state
entity_id: sensor.[TeslaName]_range_sensor
above: '40'
action:
- service: switch.turn_off
target:
entity_id: switch.[TeslaName]_charger_switch
mode: single
- “Misusing” the Max Range switch to force charge manually
- id: 'Tesla007'
alias: Tesla - Force charge si mode max range enclenché
description: ''
trigger:
- platform: state
entity_id: switch.[TeslaName]_maxrange_switch
from: 'off'
to: 'on'
for:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.[TeslaName]_charger_switch
mode: single
Those are a few example.
Display commands
As far as Lovelace is concerned, buttons are just placed in a box on my mobile interface: note, the “charging” icon updates with some delay.
type: horizontal-stack
cards:
- type: custom:button-card
tap_action:
action: toggle
hold_action:
action: more-info
entity: climate.[TeslaName]_hvac_climate_system
name: Tesla A/C
icon: mdi:thermometer
size: 25%
color: orange
show_state: false
styles:
name:
- justify-self: middle
- font-weight: bold
- font-size: 14px
state:
- value: 'off'
icon: mdi:thermometer-off
color: '#56819F'
- type: custom:button-card
tap_action:
action: toggle
hold_action:
action: more-info
entity: switch.[TeslaName]_charger_switch
name: Charge
icon: mdi:battery-charging-medium
size: 25%
color: orange
show_state: false
styles:
name:
- justify-self: middle
- font-weight: bold
- font-size: 14px
state:
- value: 'off'
icon: mdi:battery-off
color: '#56819F'
- type: custom:button-card
tap_action:
action: toggle
hold_action:
action: more-info
entity: switch.[TeslaName]_maxrange_switch
name: Max Range
icon: mdi:gauge-full
size: 25%
color: orange
show_state: false
styles:
name:
- justify-self: middle
- font-weight: bold
- font-size: 14px
state:
- value: 'off'
icon: mdi:gauge
color: '#56819F'