Charge your Tesla EV with surplus solar power

Charge your EV with surplus solar power

Introduction

Hey there, tech enthusiasts and green energy aficionados! Today we’re diving into an exciting project that combines two groundbreaking fields: electric vehicles (EVs) and home automation. Specifically, we’ll explore how to charge your Tesla EV with surplus solar power, all orchestrated by the ever-so-versatile Home Assistant. If you’ve got solar panels on your roof and a Tesla in the driveway, this one’s for you!

 

The Concept: Why Not Just Plug and Play?

Sure, you could simply plug your Tesla into the wall and let it draw power from your solar installation. But what happens when you’re not generating enough juice from the sun? Your car will start to draw power from the grid, negating the financial benefits of having a solar setup in the first place.

Enter Home Assistant—a powerful open-source home automation platform. This smart system can be configured to optimise the charging process, ensuring that you charge your Tesla EV with surplus solar power. This way, you’re always driving on sunshine, quite literally!

 

The Components

  1. Tesla Vehicle – Obviously, you need a Tesla that you can charge at home.
  2. Solar Panel Installation – A solar panel setup that’s hooked up to your home’s power grid.
  3. Home Assistant – You’ll need to have Home Assistant installed and configured, possibly on a Raspberry Pi or a dedicated computer.
  4. Smart Meter – A device to monitor energy production and consumption in real-time.
  5. Shelly EM – Real time power consumption wifi connected device

 

How It Works

Here’s the simplified rundown:

  1. Monitor Solar Output – Home Assistant keeps tabs on how much energy your solar panels are producing via the smart meter.
  2. Decision-Making Time – Using this information, Home Assistant decides whether there’s enough excess solar energy to charge your Tesla.
  3. Real time monitoring – Through the Shelly EM your actual Tesla consumption is recorded in real time ensuring optimal solar consumption
  4. Charge On! – If there’s enough excess energy, Home Assistant sends the command to your Tesla to start charging.

 

Step 1 – Get going with Home Assistant

Before diving in, have a look at my previous blog for some basics. It’ll make following this guide a breeze. Let’s get to it!

 

Step 2 – Setting Up Dynamic Tesla Amp Control

To gain better control over your Tesla’s charging process, we’ll be leveraging the Tessie Integration. This allows us to dynamically adjust the charging amps based on real-time data, such as solar output.

Follow the Instructions: The Tessie Integration page has a step-by-step installation process. Make sure to follow each step carefully to avoid any hiccups.

Once you’ve successfully installed the Tessie integration, you’ll be all set to proceed with configuring it to adjust the charging amps dynamically.

Note: I was previously using Tesla Custom Integration, however this will be deprecated early 2024. I suggest using Tessie, although it has a minor cost. Refer Tesla API changes.

 

Step 3: Setup MQTT

To get the current draw data from your Tesla via the Shelly EM, you’re going to need an MQTT broker in the mix. Not sure where to start? No worries—check out the Home Automation Guy’s blog for a solid walkthrough on setting it up. Once you’ve got your MQTT broker in place, you’ll be able to seamlessly collect and analyze your Tesla’s power usage. Ready to wire it all together?

 

Step 4: Setup Shelly EM hardware

For real-time charge rate monitoring, integrate Shelly EM into your setup. Simply install the Shelly EM near your Tesla charger and connect it to Home Assistant. This enables you to track the power flow to your Tesla in real-time, allowing for more nuanced control and data-driven decisions.

Shelly EM
Shelly EM Wiring Diagram

Contract a licensed electrician to install the Shelly EM.

 

Step 5: Configure Shelly EM

Log into Shelly EM’s IP address and head to MQTT settings. Plug in your server’s IP and port, and you’re good to go.

 

Shelly EM MQTT configuration

 

Step 6: Consume the MQTT entries

Update configuration.yaml for MQTT Switch and State Monitoring

Time to tie it all together! Open up your configuration.yaml file and add the following MQTT settings to track your Tesla’s power state. This will let you both control and monitor the switch status via MQTT.

 

    
mqtt:
  switch:
    - name: "Tesla Power State"
      state_topic: "shellies/shellyem-0620F0/relay/0"
      command_topic: "shellies/shellyem-0620F0/relay/0/command"
      availability_topic: "shellies/shellyem-0620F0/online"
      qos: 1
      payload_on: "on"
      payload_off: "off"
      payload_available: "true"
      payload_not_available: "false"
      retain: false
  sensor:
    - name: "Tesla Watts"
      state_topic: "shellies/shellyem-0620F0/emeter/0/power"
      qos: 1
      unit_of_measurement: "W"
      icon: mdi:car

 

Step 7: Add Your Solar Inverter’s Integration

Integrate Your Solar Inverter into Home Assistant for Real-Time Output Monitoring. To keep an eye on your solar output, you’ll want to integrate your solar inverter into Home Assistant. This way, you’ll have real-time insights into how much renewable energy you’re generating.

Home Assistant Fronius Integration

 

Step 8: Setup in Home Assistant

1. Managing Solar Charging with Home Assistant: Creating an Input Boolean

To control solar charging, you can set up an Input Boolean in Home Assistant. This will serve as a convenient on/off switch for the feature. You can create a button within your Home Assistant dashboard.

Steps:

  1. Go to Home Assistant Dashboard: Open your Home Assistant interface in your preferred browser.
  2. Navigate to Settings > Helpers:
    • Click on the sidebar to go to Configuration.
    • From there, select Helpers under the “Settings” category.
    • Click on the Add Helper button, then choose Toggle.
    • Name it “Enable Solar Charging” and make sure its initial state is set to ‘off’.

Create a button using a glance card or equivalent.



entities:
  - entity: input_boolean.tesla_solar_charging
    show_name: true
    show_icon: true
    type: button
    name: Tesla Solar
    tap_action:
      action: toggle
show_icon: true
show_name: true
show_state: false
title: Overrides
type: glance

 

Step 9. Create your sensors to support the automation

Build a Trio of Sensors to Monitor Power, Voltage, and Amps

Ready to take your automation to the next level? You’ll need to set up three key sensors:

  1. Power Feed Sensor: Monitors the power you’re feeding into the grid.
  2. Grid Voltage Sensor: Keeps an eye on the grid voltage.
  3. Tesla Power Draw Sensor: Tracks the live power draw of your Tesla via the Shelly EM sensor.

 

sensor:
  - platform: template
    sensors:
      feed_into_power_grid:
        value_template: '{{states.sensor.power_grid_fronius_power_flow_0_http_fronius.state | round(0,default=0) | int(0) / -1 }}'
        availability_template: '{{ states("sensor.power_grid_fronius_power_flow_0_http_fronius") not in ["unavailable", "unknown"] }}'
        unit_of_measurement: W
      grid_voltage:
        friendly_name: 'Grid Voltage'
        value_template: '{{states("sensor.device_with_voltage")|round(1)}}'
        unit_of_measurement: 'V'
      car_tesla_watts:
        friendly_name: 'Car Watts'
        value_template: '{{ states("sensor.tesla_watts") }}'
        unit_of_measurement: 'W'
        availability_template: '{{ states("sensor.tesla_watts") not in ["unavailable", "unknown"] }}'
      total_tesla_amps_available:
        friendly_name: 'Total Tesla Amps Available'
        unit_of_measurement: 'A'
        value_template:  '{{ (((states("sensor.feed_into_power_grid")|float(0) + states("sensor.car_tesla_watts")|float(0))/(states("sensor.grid_voltage")|round(0,default=1)) - 0|float(0)))|round(0,default=0) }}'
        availability_template: '{{ states("sensor.car_tesla_watts") not in ["unavailable", "unknown"]
                                or states("sensor.grid_voltage") not in ["unavailable", "unknown"] 
                                or states("sensor.feed_into_power_grid") not in ["unavailable", "unknown"] }}'

 

Step 10. Create your automation controlling the variable current

This automation smartly adjusts the Tesla’s charging current, considering various elements like solar power availability, among other factors. It incorporates a myriad of conditions to make a well-rounded decision, all the while keeping rate limits and the vehicle’s home status in mind.

Triggers

  1. State Change in Total Amps Available: The automation starts when the sensor.total_tesla_amps_available changes value.
  2. Home Assistant Startup: Additionally, the automation triggers when Home Assistant starts.

Conditions

  1. Solar Charging is On: Now it checks if input_boolean.tesla_solar_charging is set to “on” as per step 8.
  2. Change in State: Validates if there’s an actual increase or decrease in the sensor’s state, confirming a real change.
  3. Sun is Up: The sun must be above the horizon.
  4. Rate Limit: The automation won’t trigger more than once every 10 seconds.

Action

  • It executes a shell command that modifies the Tesla’s charging current.

 

alias: "ON: Variable Tesla Current Peak Cost"
description: "ON: Set Tesla charging current when solar mode is on and sun up"
trigger:
  - platform: state
    entity_id:
      - sensor.total_tesla_amps_available
    to: null
  - platform: homeassistant
    event: start
condition:
  - condition: state
    entity_id: input_boolean.tesla_solar_charging
    state: "on"
  - condition: or
    conditions:
      - condition: template
        value_template: |
          {{ trigger.to_state.state|float > trigger.from_state.state|float }}
      - condition: template
        value_template: |
          {{ trigger.to_state.state|float < trigger.from_state.state|float }}
    alias: Confirm there is a change in state
  - condition: state
    entity_id: sun.sun
    state: above_horizon
  - condition: template
    value_template: >
      {{ as_timestamp(now()) -
      as_timestamp(state_attr('automation.variable_tesla_current',
      'last_triggered')) > 10 }}
    alias: Limit triggering of this automation
action:
  - service: tesla_custom.api
    data:
      command: CHARGING_AMPS
      parameters:
        path_vars:
          vehicle_id: "{{ state_attr('binary_sensor.<name of car>_online', 'id') }}"
        charging_amps: "{{ states('sensor.total_tesla_amps_available') }}"
        wake_if_asleep: true
mode: single

 

 

Share the Post:

Leave Your Comment

Related Posts

Subscribe to new blogs