Converting Tesla Solar watts sensor to kWh correctly

I’m using the HACS Tesla integration: GitHub - alandtse/tesla: Tesla custom integration for Home Assistant. This requires a refresh token be generated by third-party apps to login. and it provides the solar energy in watts:

The energy dashboard needs this in kWh, and I’ve tried a variety of methods to get it to match what Tesla’s own iOS app says my system produced - but it’s always slightly off.

I’ve tried the typical “integration” sensor with various method settings, no luck.

I tried this other method involving multiple sensors:

sensor:
  - platform: average
    name: Average Solar Power
    start: "{{ today_at('00:00') }}"
    end: "{{ now() }}"
    entities: sensor.my_home_solar_power
template:
  - sensor:
      # Daily Solar Energy
      - name: Daily Solar Energy
        device_class: energy
        state_class: total_increasing
        state: "{{ (float(states('sensor.average_solar_power'), default = 0.0) * ((now() - today_at('00:00')).total_seconds() / 3600) / 1000) | round(2) }}"
        unit_of_measurement: kWh

But that is off too. I’m not quite sure what to try next, or if I’m out of luck until someone queries kWh directly from Tesla’s solar API or something.

Any help would be appreciated. Thanks!

Hi, Were you able to get it working? I have Tesla Solar through the Tesla Custom Integration and can’t get the solar production to show up in the Energy Dashboard. Any help would be appreciated. Thanks!

There are two Tesla Powerwall integrations, the Custom integration from HACS which uses the Tesla cloud API. The native Home Assistant integration connects to your powerwall over your local network. You can use both at the same time.

The native Home Assistant powerwall integration has energy sensors which are suitable for use with the Energy dashboard.

i dont have a powerwall, just Tesla solar. when I install the native app, it asks for Powerwall access first…

I have the custom HACS integration, but I am having a hard time getting the entity properly working in the Energy dashboard, I used the Integration - Riemann sum integral but the sensor is either showing as kkWh or now “unavailable”.

I honestly dont really know what Im doing, I used chatgbt and it suggested to add this to configuration.yaml:
template:

  • sensor:
    • name: “Tesla Solar Production Energy”
      unique_id: “tesla_solar_production_energy”
      unit_of_measurement: “kWh”
      state: “{{ states(‘sensor.tesla_solar_production’) | float * 1000 }}”
      attributes:
      device_class: “energy”
      state_class: “total”
      icon: “mdi:chart-histogram”
      friendly_name: “Tesla Solar Production Energy”

any help would be greatly appreciated