Skip to content

Instantly share code, notes, and snippets.

@BluSyn
Created July 4, 2025 06:01
Show Gist options
  • Select an option

  • Save BluSyn/1d92f9ebd6be1691f7b3fde73330fa2b to your computer and use it in GitHub Desktop.

Select an option

Save BluSyn/1d92f9ebd6be1691f7b3fde73330fa2b to your computer and use it in GitHub Desktop.
Home Assistant Automation to trigger charging Tesla with excess solar
alias: Tesla Daytime Solar Charging
description: Charge Tesla with excess solar during the day
triggers:
- minutes: /1
trigger: time_pattern
conditions:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
state: "on"
- condition: numeric_state
entity_id: sensor.tesla_battery_level
below: 80
- condition: sun
after: sunrise
before: sunset
- condition: or
conditions:
- condition: state
entity_id: switch.tesla_charge
state: "off"
- condition: and
conditions:
- condition: state
entity_id: switch.tesla_charge
state: "on"
- condition: state
entity_id: input_boolean.tesla_solar_charging_active
state: "on"
actions:
- choose:
- conditions:
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.total_battery_power
above: 1200
- condition: numeric_state
entity_id: sensor.total_pv_power
above: 1500
- condition: or
conditions:
- condition: state
entity_id: sensor.tesla_wall_connector_status
state: ready
- condition: state
entity_id: sensor.tesla_wall_connector_status
state: waiting_car
sequence:
- target:
entity_id: switch.tesla_charge
action: switch.turn_on
data: {}
- target:
entity_id: input_boolean.tesla_solar_charging_active
action: input_boolean.turn_on
data: {}
- target:
entity_id: number.tesla_charge_current
data:
value: >-
{% set voltage =
states('sensor.tesla_wall_connector_grid_voltage') | float(230)
%} {% set power = states('sensor.total_battery_power') |
float(0) %} {{ min(max(5, (power / voltage) | round(0)), 32) }}
action: number.set_value
- conditions:
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.total_battery_power
above: 500
- condition: numeric_state
entity_id: sensor.tesla_charger_current
below: 32
- condition: state
entity_id: sensor.tesla_wall_connector_status
state: charging
- condition: state
entity_id: input_boolean.tesla_solar_charging_active
state: "on"
sequence:
- target:
entity_id: number.tesla_charge_current
data:
value: >-
{% set current = states('number.tesla_charge_current') |
float(0) %} {% set voltage =
states('sensor.tesla_wall_connector_grid_voltage') | float(230)
%} {% set solar_current = (states('sensor.total_battery_power')
| float(0) / voltage) | round(0) %} {% set new_current = current
+ solar_current | round(0) %} {{ min(max(5, new_current), 32) }}
action: number.set_value
- conditions:
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.total_grid_power_w_monitor
above: 1000
- condition: state
entity_id: sensor.tesla_wall_connector_status
state: charging
- condition: state
entity_id: input_boolean.tesla_solar_charging_active
state: "on"
sequence:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.total_pv_power
below: 1300
sequence:
- target:
entity_id: switch.tesla_charge
action: switch.turn_off
data: {}
- target:
entity_id: input_boolean.tesla_solar_charging_active
action: input_boolean.turn_off
data: {}
- target:
entity_id: number.tesla_charge_current
action: number.set_value
data:
value: "32"
- conditions:
- condition: numeric_state
entity_id: sensor.total_pv_power
above: 1500
sequence:
- target:
entity_id: number.tesla_charge_current
data:
value: >-
{% set current = states('number.tesla_charge_current')
| float(0) %} {% set grid_power =
states('sensor.total_grid_power_w_monitor') | float(0)
%} {% set voltage =
states('sensor.tesla_wall_connector_grid_voltage') |
float(230) %} {% set new_current = current - (grid_power
/ voltage) | round(0) %} {{ [5, new_current] | max }}
action: number.set_value
- conditions:
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.total_grid_power_w_monitor
below: 300
- condition: numeric_state
entity_id: sensor.inverter_combined_battery_soc
above: 99
- condition: numeric_state
entity_id: sensor.total_pv_power
above: 2000
- condition: state
entity_id: sensor.tesla_wall_connector_status
state: charging
- condition: state
entity_id: input_boolean.tesla_solar_charging_active
state: "on"
sequence:
- target:
entity_id: number.tesla_charge_current
data:
value: >-
{% set current = states('number.tesla_charge_current') |
float(0) %} {% set voltage =
states('sensor.tesla_wall_connector_grid_voltage') | float(230)
%} {% set new_current = current + 2 | round(0) %} {{
min(new_current, 32) }}
action: number.set_value
mode: single
@BluSyn
Copy link
Author

BluSyn commented Jul 4, 2025

Works with Hardware:

  • Refoss em16 energy monitor CT on House main
  • Deye Hybrid Inverters (Solarman integration)
  • Tesla Wall Connector (Type 2, max 32A)

Notes:
Solar export to grid not enabled, so no direct way to determine excess solar available. Uses current usage, house usage, plus excess to batteries as inputs. Uses batteries charge rate to determine excess solar available, and routes that to car. If batteries are full, instead it regularly increments/decrements charge level to balance no grid power being pulled. Some grid power being used is inevitable, but as minimal as possible within the constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment