Tesla Fleet and the Energy Dashboard
If you’ve reached this document, then (like me) you are looking for an integration that allows you to use the Energy dashboard with the Tesla Fleet integration for Home Assistant … only to find that it doesn’t work with the Energy dashboard out of the box. Below is my method to get everything running and get a dashboard that looks something like this.
*Dashboard example, on a cloudy day (can you tell when we used our electric oven and stove?)
To follow my steps, you have to follow the Tesla Fleet instructions to get started. By the end of the instructions you should have a Tesla Fleet integration with one device. My steps include components your system may or may not have. Ignore any components that you do not need; the Energy dashboard will display data for any components that you supply sensors for.
Get the Entity ID of Each Sensor
Begin by noting the names of three sensors: Battery Power, Grid Power, and Solar Power. Get these names by following these steps:
***Note: If you do not see any values here and Tesla Fleet has been operating long enough to expect figures to be generated, the sensors we create will not have any values either. No values here indicate a connectivity issue with the Tesla API or with Tesla Fleet operating properly. Resolve any issues preventing the built-in sensors from reading data before proceeding.
Create the Necessary Helpers
The next step is to create a Template to help us prepare the data for the Energy dashboard. The Energy Dashboard expects a positive input on
To provide these figures, we will begin with creating helpers to split the single sensor we have into two (one for energy leaving the sensor, one for energy entering the sensor).
These steps will be done for both Battery Power and Grid Power to create positive-only readings for the sensors. Note that there are different equations based on which helper we are creating.
*NOTE*: You should be able to see a value under the Preview section near the bottom. If you do not, you may have something filled in wrong, or the equation is not referencing your sensor properly.
*NOTE 2*: The number you see in Preview should be positive. If it is negative, check the equation you are using.
This is an example of my sensors:
Sensor | Sensor Name |
Battery | sensor.my_home_battery_power |
Grid Power | sensor.my_home_grid_power |
Solar Panels | sensor.my_home_solar_power |
Creating the Integral sensors
These steps will create the sensors used in the Energy Dashboard, which will take our power consumption in kW and measure it over time, converting it to kWh. Follow these steps to create the following sensors:
To create these sensors, do the following for each one:
Configure the Energy Dashboard
Congratulations, you have the sensors necessary to fill out the Energy Dashboard with a solar system and battery! If your actual system has other components, your list of sensors will be different than what you see below. If you used my naming convention, you will want to fill in the following fields:
Electricity grid
Grid consumption: Grid Import kWh
Return to grid: Grid Export kWh
Solar Panels
Solar production: Solar Panels kWh
Home battery storage
Battery System
Energy going in to the battery: Powerwall 3 Charging kWh
Energy coming out of the battery: Powerwall 3 Discharging kWh
This is my configuration to see energy information show up on the dashboard for my grid usage, battery usage, and solar production; your configuration may be different. I found that it takes at least one full hour for data to show up, since it updates hourly. This means it could take up to two hours for the dashboard to show any data.
Topics of Interest
Part of the difficulty in getting Tesla Fleet talking to the Energy dashboard has to do with how each implementation processes sensor data.
Tesla Fleet, for instance, presents the raw data from the Tesla API, where a single sensor, such as your Grid Power, shows how many kilo-Watts are currently traveling towards your home or away from it. Tesla Fleet shows power moving from the grid towards the home as a positive number, and power moving from the home towards the grid as a negative number.
On the other hand, the Energy dashboard expects a separate sensor for each input. Power moving towards the home and power moving towards the grid are treated as two separate sensors. To make things more difficult, the Energy dashboard expects these figures to be positive, which presents a challenge when preparing data for the Energy dashboard.
The first step in preparing the data presented by Tesla Fleet for use in the Energy dashboard is to create two sensors from one in a way that no sensor gives a negative number (you will see an error in that case). We do this with two equations.
To extract only the positive number, we want to read the current value from the sensor using states(‘sensor name’), which will do nothing for us as it is since this value could become negative. Our formula currently looks like this:
{{ states(‘sensor name’) }}
To ensure that we always have a positive value, we use the max function: [value1, value2] | max. By setting value1 to the sensor value, and value2 to 0, we ensure that the lowest value passed will always be 0. Our formula has now changed to this:
{{ [states(‘sensor name’), 0 ] | max }}
To ensure that this value always includes any fractional value, we tell the software to always include the decimal fraction by using a programming method called type casting. The code would look something like value | float(0). Now our formula has evolved:
{{ [states(‘sensor name’)|float(0), 0 ] | max }}
For good measure, we always want to compare two values of the same type, so we change 0 (which could be interpreted as an integer) into 0.0 (explicitly telling the software to use a floating point value). We finally arrive at the formula that works well at getting all the positive values from the sensor:
{{ [ states('sensor name') | float(0), 0.0 ] | max }}
Next, we need to extract all the negative values, and present them as positive values. Since we already have a formula that extracts the positive values, we multiply the value by -1 right before comparing it to 0.0, which converts our negative values into positive ones (notice the use and placement of the parenthesis to apply the multiplication of the sensor value and negative one). The equation to extract the negative values is therefore:
{{ [ ( -1 * states('sensor name')|float(0)), 0.0 ] | max }}
These sensors are the basis for the actual sensors the Energy dashboard uses. So far we have broken out sensors that give an instantaneous measurement in kilowatts, which is a measure of power. I’ll skip the physics explanation here, suffice it to say that the Energy dashboard is concerned with measuring energy, not power. In this case, energy is a measure of power over time, as denoted by the change from kW to kWh, or kilowatts to kilowatt-hour.
The measurement of energy is done using a math method called integration. Home Assistant provides a sensor that does this math for us, and all we have to do is give it the sensor to measure, and provide a few settings on how to present that data once it’s done doing its math. Using the Integral sensor, and integrating using the left Riemann sum, provides the measure of power used over time that the Energy dashboard needs.