Rewritten Tesla Style Solar Power Card

Try posting your configuration maybe we can figure it out.

Hi All,
I am no doubt missing something really simple here but I am not getting any solar generation data displaying on the card - it is always 0. I would really appreciate some help.

My card is configured as follows:

type: custom:tesla-style-solar-power-card
house_entity: sensor.powerwall_load_now
grid_entity: sensor.tesla_card_grid_consumption
battery_entity: sensor.tesla_card_battery_consumption
generation_to_grid_entity: sensor.tesla_card_grid_feed_in
generation_to_house_entity: sensor.tesla_card_solar_consumption
generation_to_battery_entity: sensor.tesla_card_battery_charging_inside
battery_to_house_entity: sensor.tesla_card_battery_consumption
grid_to_house_entity: sensor.tesla_card_grid_consumption
battery_extra_entity: sensor.powerwall_charge

and my template sensors are;

template:
  - sensor:
    - name: "Tesla Card Grid Consumption"
      unique_id: 'tesla_card_grid_consumption'
      state: "{{ states('sensor.powerwall_site_now') | float | max(0) | round(1) }}"
      device_class: power
      unit_of_measurement: kW

    - name: "Tesla Card Grid Feed In"
      unique_id: 'tesla_card_grid_feed_in'
      state: "{{ states('sensor.powerwall_site_now') | float | min(0) | abs | round(1) }}"
      device_class: power
      unit_of_measurement: kW

    - name: "Tesla Card Solar Consumption"
      unique_id: 'tesla_card_solar_consumption'
      state: "{{ ((states('sensor.powerwall_solar_now') | float) - (states('sensor.tesla_card_grid_feed_in') | float ) - (states('sensor.tesla_card_battery_charging_inside') | float) ) | round(1) }}"
      device_class: power
      unit_of_measurement: kW

    - name: "Tesla Card Battery Consumption"
      unique_id: 'tesla_card_battery_consumption'
      state: "{{ states('sensor.powerwall_battery_now') | float | max(0) | round(1) }}"
      device_class: power
      unit_of_measurement: kW

    - name: "Tesla Card Battery Charging Inside"
      unique_id: 'tesla_card_battery_charging_inside'
      state: "{{ states('sensor.powerwall_battery_now') | float | min(0) | abs | round(1) }}"
      device_class: power
      unit_of_measurement: kW```


I am getting this error in my logs however;

* Template warning: 'float' got invalid input 'unavailable' when rendering template '{{ states('sensor.powerwall_site_now') | float | max(0) | round(1) }}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2021.12
* Template warning: 'float' got invalid input 'unavailable' when rendering template '{{ states('sensor.powerwall_site_now') | float | min(0) | abs | round(1) }}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2021.12
* Template warning: 'float' got invalid input 'unavailable' when rendering template '{{ ((states('sensor.powerwall_solar_now') | float) - (states('sensor.tesla_card_grid_feed_in') | float ) - (states('sensor.tesla_card_battery_charging_inside') | float) ) | round(1) }}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2021.12
* Template warning: 'float' got invalid input 'unavailable' when rendering template '{{ states('sensor.powerwall_battery_now') | float | max(0) | round(1) }}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2021.12
* Template warning: 'float' got invalid input 'unavailable' when rendering template '{{ states('sensor.powerwall_battery_now') | float | min(0) | abs | round(1) }}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2021.12


![image|214x500](upload://sfs1Jxas7ihEkBgV95xDzNTZMIe.png)

Thanks in advance!
JDFB

Are there values listed under your Tesla Powerwall entities? (in devices)

Yeah it seems your powerwall is either not connected yet to home assistant or at least not with that name

Thanks for the reply - All connected and data is correctly displaying for each sensor…`I just can’t work it out!

cheers.

On your home assistant go to: /developer-tools/state when you have some sun and do a screenshot of the result when you type in the entity ‘sensor.powerwall_solar_now’ you should get a result. Otherwise you do have a powerwall installed correctly but the sensor name is not preceded by powerwall but by something else. At least it seems like that from the error. You can find your entities there and you might just need to change the name of powerwall to whatever it is called on your installation. This is an error I have not seen yet though.

Thanks for the reply.
State appears correct which is why I am so confused!

image

Hello

Can someone share the templates (or full config) to integrate de new Fronius oficial integration?

Thanks!

I have a little challange, the animations and figures do not work when exporting the battery to the grid; hope this helps?

image

I have the stock templates, I think basically it struggles with battery to grid concept -

template:

  • sensor:
    • name: “Tesla Card Grid Consumption”
      unique_id: ‘tesla_card_grid_consumption’
      state: “{{ states(‘sensor.powerwall_site_now’) | float | max(0) | round(1) }}”
      device_class: power
      unit_of_measurement: kW
    • name: “Tesla Card Grid Feed In”
      unique_id: ‘tesla_card_grid_feed_in’
      state: “{{ states(‘sensor.powerwall_site_now’) | float | min(0) | abs | round(1) }}”
      device_class: power
      unit_of_measurement: kW
    • name: “Tesla Card Solar Consumption”
      unique_id: ‘tesla_card_solar_consumption’
      state: “{{ ((states(‘sensor.powerwall_solar_now’) | float) - (states(‘sensor.tesla_card_grid_feed_in’) | float ) - (states(‘sensor.tesla_card_battery_charging_inside’) | float) ) | round(1) }}”
      device_class: power
      unit_of_measurement: kW
    • name: “Tesla Card Battery Consumption”
      unique_id: ‘tesla_card_battery_consumption’
      state: “{{ states(‘sensor.powerwall_battery_now’) | float | max(0) | round(1) }}”
      device_class: power
      unit_of_measurement: kW
    • name: “Tesla Card Battery Charging Inside”
      unique_id: ‘tesla_card_battery_charging_inside’
      state: “{{ states(‘sensor.powerwall_battery_now’) | float | min(0) | abs | round(1) }}”
      device_class: power
      unit_of_measurement: kW

I need to have a ‘tesla_card_battery_to_grid’ entity, any help would be appreciated, many thanks

Hi,

@reptilex Thanks for making this card.

I think I finally have it setup the way I want it.
I have an Enphase Envoy and lets just say it wasn’t exactly plug and play getting this card to work with the envoy sensors.
For some reason I had to create a new sensor which i called “Consumption Net” that subtracts the grid import power from the current_power_consumption so it can be used as the “generation_to_house_entity”.
As a side note, the enphase envoy does not provide ‘grid import power’ sensors.
I needed to create that as well.

image

Things I had to add in the configuration.yaml do to get it looking like this:

template:
  - sensor:
        name: Grid Import Power
        state_class: measurement
        icon: mdi:transmission-tower
        unit_of_measurement: W
        device_class: power
        state: >
            {{ [0,
               states('sensor.envoy_SERIALNUMBER_current_power_consumption') | int -
               states('sensor.envoy_SERIALNUMBER_current_power_production') | int ]
               | max }}

  - sensor:
        name: Power Wheel House Consumption Net
        state_class: measurement
        icon: mdi:transmission-tower
        unit_of_measurement: W
        device_class: power
        state : >
            {{ states('sensor.envoy_SERIALNUMBER_current_power_consumption') | int -
               states('sensor.grid_import_power') | int }}

  - sensor:
        name: Power Wheel Energy Production
        state_class: measurement
        icon: mdi:transmission-tower
        unit_of_measurement: kWh
        device_class: energy
        state : >
            {{ (states('sensor.envoy_SERIALNUMBER_today_s_energy_production') | int /
               1000) | round(0) }}

  - sensor:
        name: Power Wheel Energy Consumption
        state_class: measurement
        icon: mdi:transmission-tower
        unit_of_measurement: kWh
        device_class: energy
        state : >
            {{ (states('sensor.envoy_SERIALNUMBER_today_s_energy_consumption') | int /
               1000) | round(0) }}

Card Config

type: custom:tesla-style-solar-power-card
generation_to_grid_entity: sensor.grid_export_power
grid_to_house_entity: sensor.grid_import_power
generation_to_house_entity: sensor.power_wheel_house_consumption_net
grid_extra_entity: sensor.today_energy_total_cost
house_extra_entity: sensor.power_wheel_energy_consumption
generation_extra_entity: sensor.power_wheel_energy_production
appliance1_consumption_entity: sensor.sonoff_identifier_power
appliance1_icon: mdi:pool
appliance1_extra_entity: sensor.pool_pump_duration_24h
energy_flow_diagramm: 1
energy_flow_diagramm_line_factor: 2

my figures all reverted to 0 as shown in this card with the 2022 core updates.
I had to remove the min an max from some of my value_templates to get the integration to work again

@Gregory_Peck do you know which entries you had to remove min/max from?

In the end I had to move min(0) and max(0) to the other side of float operation (LHS). You may also have to change float to read float(0)

  tesla_card_grid_feed_in:
    friendly_name: "Tesla Card Grid Feed In"
    value_template: "{{ states('sensor.powerwall_site_now') | min(0) | float(0) | round(1) }}"
    device_class: power
    unit_of_measurement: kW

image

Thanks Greg!

Hi,
I’m trying to convert my power-wheel-card into this testla-style-solar-power-card. As it’s far more beautiful and matching the HA Energy dashboard.
I just have the actual solar production, the actual grid power consumption en the actual grid power production entities available.

Any idea how to convert them into the tesla-style-solar-power-card as I don’t succeed. Based on the 3 entities he should be able to calculate the house consumption I suppose (as the power-wheel-card does).

This is my config in power-wheel-card:

type: custom:power-wheel-card
title: Energievebruik
solar_power_entity: sensor.actuele_opbrengst_zonnepanelen_kw
grid_power_consumption_entity: sensor.power_consumption
grid_power_production_entity: sensor.power_production
power_decimals: 3

I am testing the following config:

type: custom:tesla-style-solar-power-card
name: Actueel energieverbruik
grid_to_house_entity: sensor.power_consumption
generation_entity: sensor.actuele_opbrengst_zonnepanelen_kw
generation_to_grid_entity: sensor.power_production

Many thanks

Edit:
Got it working. I added a new sensor generation_to_house which I calculate using a template: total generation sunpanels - grid power production

All working fine now! Great card! Thanks for all hard work!

I would be interested to see some more of what you did Greg, I’ve just moved from a 2021 version of core and hass to the latest (2022.3) and the my results are more like random numbers. I think I must have something seriously wrong…
Card Definition:
type: custom:tesla-style-solar-power-card
house_entity: sensor.powerwall_load_now
grid_entity: sensor.xtesla_grid_consumption
battery_entity: sensor.xtesla_battery_consumption
generation_entity: sensor.powerwall_solar_now
generation_to_grid_entity: sensor.xtesla_grid_feed_in
generation_to_house_entity: sensor.xtesla_solar_consumption
generation_to_battery_entity: sensor.xtesla_battery_charging
battery_to_house_entity: sensor.xtesla_battery_consumption
grid_to_house_entity: sensor.xtesla_grid_consumption
grid_to_battery: sensor.xtesla_grid_to_battery
battery_extra_entity: sensor.powerwall_charge
appliance1_consumption_entity: sensor.myenergi_zappi_diverted
appliance1_extra_entity: sensor.niro_ev_19_ev_battery

These are working correctly

My Sensors, which were working OK until this update. I’ve moved the max(0) min(0) as shown in Greg’s post resulting in numbers rather than 0s but the numbers are wrong. For example discharge from battery to house was just showing as 8kWh when the Powerwall can only run at 5kWh and at the time the house was using less than 1kWh.

  • platform: template
    sensors:

  xtesla_grid_consumption:
    friendly_name: "Grid Import"
    value_template: "{{ states('sensor.powerwall_site_now') | max(0) | float | round(1) }}"
    device_class: power
    unit_of_measurement: kW

  xtesla_grid_feed_in:
    friendly_name: "Grid Export"
    value_template: "{{ states('sensor.powerwall_site_now') | min(0) | float | abs | round(1) }}"
    device_class: power
    unit_of_measurement: kW

  xtesla_solar_consumption:
    friendly_name: "Solar Consumption"
    value_template: "{{ ((states('sensor.powerwall_solar_now') | float(default=0)) - (states('sensor.xtesla_grid_feed_in') | float(default=0) ) - (states('sensor.xtesla_charging') | float(default=0)) ) | round(1) }}"
    device_class: power
    unit_of_measurement: kW

  xtesla_battery_consumption:
    friendly_name: "PW2 Consumption"
    value_template: "{{ states('sensor.powerwall_battery_now') | max(0) | float | round(1) }}"
    device_class: power
    unit_of_measurement: kW

  xtesla_battery_charging:
    friendly_name: "PW2 charge"
    value_template: "{{ states('sensor.powerwall_battery_now') | min(0) | float | abs | round(1) }}"
    device_class: power
    unit_of_measurement: kW

Here is my card config

type: custom:tesla-style-solar-power-card
name: Power Flow
house_entity: sensor.tesla_card_load
grid_entity: sensor.tesla_card_grid_consumprtion
battery_entity: sensor.tesla_card_battery_consumption
generation_entity: sensor.entire_site_solar_generation
generation_to_grid_entity: sensor.tesla_card_grid_feed_in
generation_to_house_entity: sensor.tesla_card_solar_consumption
generation_to_battery_entity: sensor.tesla_card_battery_charging_inside
battery_to_house_entity: sensor.tesla_card_battery_consumption
grid_to_house_entity: sensor.tesla_card_grid_consumprtion
battery_extra_entity: sensor.powerwall_charge
house_extra_entity: sensor.weatherbit_apparent_temperature
generation_extra_entity: sensor.weatherbit_cloud_coverage
grid_extra_entity: sensor.daily_powerwall_site_export_kwh
appliance1_consumption_entity: sensor.how_many_live_kw_going_into_cars_now
appliance1_extra_entity: sensor.how_many_kwh_went_into_cars_today
appliance2_consumption_entity: sensor.hot_water_at_home_live_kw
appliance2_extra_entity: sensor.daily_power_hot_water
appliance2_icon: mdi:water-boiler
hide_inactive_lines: 1
change_house_bubble_color_with_flow: 1
energy_flow_diagramm: 0
energy_flow_diagramm_line_factor: 5
threshold_in_k: 1
view_layout:
  position: main

Sensor templates, please excuse the typo in the word consumption on one sensor. I have a complex setup here with separate solar systems ontop of what the powerwall is connected to, as I have 3 phase. Hopefully it can help

#
      tesla_card_load:
        friendly_name: "Tesla Card Load Value"
        unit_of_measurement: "kW"
        value_template: "{{ ( 0 - ( 0 - ( states('sensor.powerwall_site_now')) | float(0) + states('sensor.powerwall_battery_reverse') | float(0) - states('sensor.entire_site_solar_generation') | float(0) )) | round(1)  }}"
#
      tesla_card_grid_consumprtion:
        friendly_name: "Tesla Card Grid Consumption"
        value_template: "{{ states('sensor.powerwall_site_now') | float(0) | round(1) }}"
        device_class: power
        unit_of_measurement: kW
#
      tesla_card_grid_feed_in:
        friendly_name: "Tesla Card Grid Feed In"
        value_template: "{{ states('sensor.powerwall_site_now') | min(0) | float(0) | round(1) }}"
        device_class: power
        unit_of_measurement: kW        
#
      tesla_card_solar_consumption:
        friendly_name: "Tesla Card Solar Consumption"
        value_template: "{{ ((states('sensor.entire_site_solar_generation') | float) - (states('sensor.tesla_card_grid_feed_in') | float(0) ) - (states('sensor.tesla_card_battery_charging_inside') | float) ) | round(1) }}"
        device_class: power
        unit_of_measurement: kW        
#
      tesla_card_battery_consumption:
        friendly_name: "Tesla Card Battery Consumption"
        value_template: "{{ states('sensor.powerwall_battery_now') | float(0) | round(1) }}"
        device_class: power
        unit_of_measurement: kW

Thanks Gregory, Started comparing and already made a few improvements in my definitions which looks like I’ve fixed grid and house. More to do.

Can I ask, what is powerwall_battery_reverse?

Many thanks

Sure, it just swaps above zero for below,
Eg -5440w becomes 5440w or vice versa

Depending on the integration or calculation required, the opposite of the Tesla battery sensor reading sensor might be useful.