Using Tesla Powerwall Data on the HA Energy Dashboard

Edit (9/3/2021): Much of what I described in my original post was done on Home Assistant 2019.8. The 2019.9 release improved things dramatically and made my PowerWall setup way more plug and play. There’s been a lot of discussion here since the 2019.9 release, so I figured I’d bring this post up-to-date

TL;DR: Make sure you’re on 2019.9 or newer when working with the Tesla Integration

Here’s what I did after upgrading to Home Assistant 2019.9

  • Grid Consumption: Powerwall Site Import
  • Return to grid: Powerwall Site Export
  • Solar Production: Powerwall Solar Export
  • Home Battery Storage:
    • Energy going in to the battery (kWh): Powerwall Battery Import
    • Energy coming out of the battery (kWh): Powerwall Battery Export

I was relieved to come back and see that @shanelord had set up his energy dashboard nearly exactly the same way and was seeing good results but had also set up the Power Load Export as an individual device, which I might be interested to check out!

So far, I’ve had pretty good results. Here’s a screenshot of my dashboard the day after my upgrade. There’s a gap (from 1:00 AM to 7:00 AM) on the graph because the integration needed me to re-authenticate to the Tesla Energy Gateway. I assume that the huge spike for 7:00AM was actually spread throughout that gap.

I’m trying to sort out why the CO2 Signal isn’t able to calculate the non-fossil energy consumption, I assume they’re not able to poll that data for my home. I may wind up just disabling it.

Altogether, I’m pretty excited about both releases. But especially excited at how much easier 2019.9 was to get working!

Here’s what I did back when I was using Home Assistant 2019.8:

I’m trying to get the Energy Dashboard setup to use the information that’s being polled by the Powerwall Integration.

Here’s some details:

  • HA Supervisor (supervisor-2021.06.8) and HA Core (core-2021.8.8) are both up-to-date with the latest versions.
  • Tesla Solar (11.2kW) and 3x Powerwall v2
  • Batteries’ inclusion on the Energy Dashboard is in a future release.

I created new sensors in my configuration.yaml:

sensor:
  - platform: template
    sensors:
      grid_return_kw:
        friendly_name: "Grid Return (kW)"
        device_class: power
        unit_of_measurement: kW
        value_template: "{{ states('sensor.powerwall_site_now') | float | min(0) | abs | round(4) }}"
          
      grid_consumption_kw:
        friendly_name: "Grid Consumption (kW)"
        device_class: power
        unit_of_measurement: kW
        value_template: "{{ states('sensor.powerwall_site_now') | float | max(0) | round(4) }}"
    
      powerwall_charging_kw:    
        friendly_name: "Powerwall Charging (kW)"
        device_class: power
        unit_of_measurement: kW
        value_template: "{{ states('sensor.powerwall_battery_now') | float | min(0) | abs | round(4) }}"
        
      powerwall_discharging_kw:    
        friendly_name: "Powerwall Discharging (kW)"
        device_class: power
        unit_of_measurement: kW
        value_template: "{{ states('sensor.powerwall_battery_now') | float | max(0) | round(4) }}"

  - platform: integration
    source: sensor.powerwall_solar_now
    name: energy_solar

  - platform: integration
    name: energy_totalConsumption
    source: sensor.powerwall_load_now    

  - platform: integration
    name: energy_grid_consumption
    source: sensor.grid_consumption_kw
    
  - platform: integration
    name: energy_grid_return
    source: sensor.grid_return_kw
    
  - platform: integration
    source: sensor.powerwall_charging_kw
    name: energy_powerwall_charging

  - platform: integration
    source: sensor.powerwall_discharging_kw
    name: energy_powerwall_discharging

I’ve set up the Energy Dashboard using

  • Grid Consumption: energy_grid_consumption
  • Return to grid: energy_grid_return
  • Solar Production: energy_solar

My electric plan charges and buys back at a static rate, so I used the static price option for both–but I’m not too concerned about tracking costs, yet.

After waiting a few hours and looking at the dashboard, I have a few questions:

Q: Did I do a good job? :stuck_out_tongue:
A: TBD

Q: Are the totals in the Energy Distribution today card cumulative for the entire day?
A: I think so.

Q: Do I need to create two different sensors for grid consumption and return to grid? If so, can anyone offer pointers on how to do conditional logic to determine that?
A: I think the answer to this is yes. I’ve created a few template sensors to split up the battery for charging and discharging. I’ve also split up the grid for consumption from and returning to the grid. Those seem to be working well

Q: Is there anything that I haven’t done yet that other Tesla Power customers and/or energy enthusiasts would suggest?
A: reply down below!

I’d take a screenshot of my Energy Dashboard, but I’ve tried so many different things the past 24 hours, it’s a bit of a mess and I don’t trust it!

Edit (8/27 11:21AM CDT):: I tinkered a bit last night, since there’s no replies yet–I figured I’d update this with the current state.

2 Likes

Nice job. I’ve been wanting to get the “Energy” tracking working with my Powerwall since the feature was announced.
Clearly I’ve missed something though since I’m not getting any numbers through on the Energy panel.
I’ve got the Tesla Powerwall integration working, and I’ve copied and pasted your entries into the configuration.yaml file, and set up the dashboard using the instructions you posted, but all the values on the Energy tab show as 0. Any ideas what I’ve missed?

Edit: maybe I just need to wait. I see the message “It can take up to 2 hours for new data to arrive after you configure your energy dashboard”

Any ideas what I’ve missed?

Well, I’m far from an expert. I didn’t have much luck, which lead to my post here and a question on the HA Discord, but didn’t really get anything back.

But you are correct, it’ll take 1-2 hours before you start seeing data on the dashboard itself.

As I understand it, for a sensor to work with the Energy dashboard it needs the following attributes:

  • state_class: measurement
  • last_reset:
  • unit_of_measurement: a positive value expressed in kWh
  • device_class: energy

If you look at the sensors (energy_solar, energy_totalConsumption, energy_grid_consumption, energy_grid_return, energy_powerwall_charging, and energy_powerwall_discharging) in Developer Tools, you should hopefully be able to see these attributes.

Depending on the state of your energy system, you should also see the value for the State increasing incrementally as the day goes by.

For each sensor, I wound up:

  1. Setting up a condition with my Tesla Solar&Powerwall (ex: create the circumstances for excess production returning to the grid) and waiting for that condition to come true.
  2. Create the template and integration sensor(s) needed for that condition.
  3. Use the Developer tools to make sure the sensors have the attributes and are behaving the way I expected.
  4. Add the sensor to the energy dashboard
  5. Wait a couple hours to see if the dashboard also behaved how I expected.
  6. Move on to the next condition.

It took a few days. Creating the right circumstances for the events are kind of difficult–especially if the weather’s not cooperating.

Today the new 2021.9 version was released and a bunch of new sensors are available out of the box:

However, I don’t really know the difference between all these “Import” and “export” sensors. Also I don’t know where to properly configure each sensor:

  • Battery (import/export)
  • Load (Import / Export)
  • Site (Import / Export)

Hope to find some ideas here :slight_smile:

Thank you guys!

I believe load import and export are relative to battery discharging and charging respectively.
Site import / export is grid in/out.
Solar export is solar.

No idea on ‘battery.’ At the moment, nothing is showing up for me on the energy dashboard, but apparently it can take an hour or two, so we’ll see.

Is there anything in particular I need to do to “enable” these new sensors for lack of a better word? I’ve upgraded to 2021.9 and rebooted a couple times, as well as deleting and re-adding the Tesla Powerwall integration, however the energy_exported_(in_kW) and energy_imported_(in_kW) attributes are still attributes and haven’t been moved into their own sensors, so they’re still not showing up in the energy dashboard.

Actually never mind, apparently it didn’t actually update to 2021.9, and now the update apparently isn’t even available anymore.

I use docker, and that installed just fine.

It would be good to get some setup documentation for this. If I use my Fronius feed for solar it just assumes my house is consuming it rather than a mix of battery and house, so I’m trying the Powerwall feeds.

Edit: Changed my initial setting of “Powerwall Solar Import” to “Powerwall Solar Export”

Currently I am trying:

Home Battery Storage
Energy going into the battery: Powerwall Battery Import
Energy coming out of the battery: Powerwall Battery Export

Solar Panels
Solar production energy: Powerwall Solar Export

Electricity grid
Grid Consumption: Powerwall Site Import
Return to Grid: Powerwall Site Export

Individual devices
Powerwall Load Import

Not sure if this right or wrong… won’t know for 2 hours or so…

I do have these concerning messages down the side of the energy dashboard:
Grid neutrality could not be calculated
Self consumed solar energy couldn’t be calculated
Consumed non-fossil energy couldn’t be calculated

3 Likes

For anybody seeing the same issue as me, issuing a ha core update --version 2021.9.0 command succeeded, even though the update utility showed the latest version as being 2021.8.8

Just wanted to mention that I just used @shanelord’s config and it works great - the Powerwall load export is not an individual device, but I have other individual devices (via Kasa plugs) that I’m tracking that way.

1 Like

Yep - this works well. Took me a bit to realise the animation of power flows represent total values for the day so far, not instantaneous data like the Tesla app.

Absolutely. The animations really do not make sense. The graphs values are for total energy over a period of time, whereas the animation would be helpful to convey real time flow (as done in the Tesla app).

For my setup, I had to use Solar Export, not Solar Import. Are you still using Import?

Next stop is getting the instantaneous charging values that hit my mqtt server via teslamate to be energy consumption sensors so they appear as distinct loads. (Anyone else done this yet?)

That might be it. I had issues with it and went back to my direct feed from my Fronius Inverter : “Energy total Fronius Inverter”

Upgrading my solar array soon to Enphase so will have to work it out again at the point :slight_smile:

Yeah, sorry, I used the solar export, not import. Works great!

Even ended up setting up my tariffs correctly :slight_smile:

Ahha. I have two separate inverters (Enphase and a legacy system with a poor API), both clamped with the Powerwall setup, so I rely on the solar reading on the Powerwall for the sum of the two.

Related (not strictly Powerwall, but I suspect many will have both Powerwall and Tesla vehicles), I have Teslamate reporting vehicles to HA via MQTT, so I added:

 - platform: integration
     name: "Tesla 1 Charge Supplied"
     source: sensor.tesla_1_charge_energy_added
     round: 2
     method: left

with state attributed modified to have the right classes for this to be added as an individually monitored device in the energy dashboard:

 last_reset: '1970-01-01T00:00:00+00:00'
 state_class: 'total_increasing'
 device_class: energy

I need to test on a longer charging session, as I see this sensor report 0.25kWh whereas total energy supplied via Teslamate was 0.63kWh (via reading of the sensor value. I don’t see anything graphed yet in the dashboard)

Although valuable this integration was really tricky to understand which sensors to use (not “Now”) and how Import/Export works since not every sensor will have actual values. This thread helped me tremendously (especially knowing that the readings in the distribution graphic are NOT instantaneous. The one edit to note is that if you do want to use the “Useage” / Load capability then you need to use Import and not Export as shown here:

I dont have a Tesla Powerwall but i do have something similar - Pylontech.

It seems im getting the same results as you were, with the whole Grid Neutrality error over to the right hand side…

So just to clarify…
Home Battery Storage
Energy going into the battery: kWh continuous count of energy that has charged the battery?
Energy coming out of the battery: kWh continuous count of energy that has discharged the battery?

Solar Panels
Solar production energy: kWh continuous count of solar energy made?

Electricity grid
Grid Consumption: kWh count of energy you have taken from the grid?
Return to Grid: kWh count of energy you have given back to the grid?

Individual devices
kWh continuous count of the total loads that you have consumed?

@Michael_Borohovski mind sharing your setup with tariffs? I’m trying to set mine up for peak/off peak. All the sensors exist and seem be collecting data at the times I want them too, but I can’t seem to get them to all show in the energy configuration. Right now for example I can see export/import peak but not export/import offpeak. I’m very perplexed.