Custom Solar Power Card the Tesla Style (almost)

See the github documentation:

# extra values to show as text above icons
battery_extra_entity: sensor.battery_charge
house_extra_entity: sensor.current_temperature
generation_extra_entity: sensor.percent_cloud_coverage
grid_extra_entity: sensor.monthly_feed_in
1 Like

The problem with increasing the font size is that everything has to be rearrenged and since this is a pixel calculated card it’s a nightmare to do that. I tried just making the text bigger but the text just goes beyond the bubbles.

Does anyone have some template sensors for figuring out where your power is going from each source to match the way the card is supposed to be configured?

generation_to_grid_entity
generation_to_battery_entity
generation_to_house_entity
grid_to_battery_entity
grid_to_house_entity
battery_to_grid_entity
battery_to_house_entity

I made an issue with the dev (Recommended setup for combined power reporting? · Issue #96 · reptilex/tesla-style-solar-power-card · GitHub) but still a bit still not clear as the template sensors he responded with don’t match the way the card is made.

Maybe someone who knows coding better than me can extract the logic from the HA energy card? frontend/hui-energy-distribution-card.ts at b7bd7c1065d2c77e0531b34e6bc328d3ce95d1ad · home-assistant/frontend · GitHub

What logic do you want to know? The entities required are very clear. generation_to_grid is what goes from solar to grid, generation_to_house is what goes from solar to your consumption. What is unclear to you? The way they are added or subtracted? Your question is not very clear.

You’re a legend mate!! I spent a fair bit of time but couldn’t display correct values (if I fixed one thing, then the other broke). With your code (after changing the sensor entities), it works so good so far.
Edit: My inverter is Fronius Primo 8.2 kW.

I’m not sure why you’re confusing my question as asking for additional clarification on what your entities mean. It’s not. You’ve done a great job naming them in such a way that’s very clear what they are. But as I pointed out in the GH issue, what I’m looking for help with is the template logic you need to have to get the correct number showing for each one of the entities your card requires as an input.

For example, my system doesn’t tell me how much of my solar generation is generation_to_battery_entity vs generation_to_house_entity vs generation_to_grid_entity. I just get one number that is total generation.

I think that the built in energy dashboard figures this out on it’s own. If I’m navigating the code correctly, it’s on this page: frontend/hui-energy-distribution-card.ts at 9b0b2c5b71b77049441b2832a030b55059ca645a · home-assistant/frontend · GitHub. Unfotunately, I can’t read code, so that why I’m here looking for some help.

@reptilex - any thoughts?

@poldim What I find works well is to use the ‘Developer Tools: TEMPLATE’ to get my template rules correct:

Which then allows me to setup the custom card simply:

type: custom:tesla-style-solar-power-card
generation_extra_entity: sensor.solax_970448be_today_s_energy
grid_extra_entity: sensor.imported_today_kwh
house_extra_entity: sensor.consumption_today_kwh
grid_consumption_entity: sensor.grid_consumption
house_consumption_entity: sensor.house_consumption
grid_to_house_entity: sensor.grid_consumption
generation_to_grid_entity: sensor.grid_feed_in
generation_to_house_entity: sensor.solar_consumption
generation_icon: mdi:solar-power
appliance1_consumption_entity: sensor.ev_power
appliance1_extra_entity: sensor.duka_battery_sensor
appliance2_consumption_entity: sensor.all_power_sensors
grid_entity: sensor.grid_consumption
house_entity: sensor.house_consumption
generation_entity: sensor.solar_yield

Processing: Screen recording 2022-01-20 10.33.52.webm

image

What values do your relevant sensors provide and can you format them in a similar fashion to above?

That’s exactly what I’ve been trying to do, but can’t nail the logic. Whenever I make a template sensor that works correctly for the current scenario, I look at it later that day or the next day and it’s broken. It’s a game of whack-a-mole and I’m not winning


What makes my installation more complex is the batteries and TOU offsetting I use. Before 12 I run the house on the grid and send all PV to charge the batteries, after 12 it stops using the grid and uses a combination of solar and battery to support the house until 9.

Here’s an example of my sensor:

      - name: "Powerflow Solar to House"
        state: >-
              {% set solar = states('sensor.solark_pv1_input_power') | int(0) %}
              {% set grid = states('sensor.solark_grid_external_total_power') | int(0) %}
              {% set house = states('sensor.solark_load_power') | int(0) %}
              {% set battery = states('sensor.solark_battery_power') | int(0) %}
              {% set battery_charging = states('sensor.powerflow_battery_charge') | int(0) %}
              {% set battery_discharging = states('sensor.powerflow_battery_discharge') | int(0) %}
              {% if solar > 10 %}
                  {% if ( solar - battery_charging ) / solar < 0.1  and grid > 20 %}
                      {{ grid }}
                  {% elif grid < 50 %}
                      {{  solar - battery_charging  }}
                  {% else %}
                      {{ solar }}
                  {% endif %}
              {% else %}
                  0
              {% endif %}
        device_class: power
        unit_of_measurement: W

Hi Andrew, did you have any luck with the stock powerwall templates on the github and ‘grid to battery’ and ‘battery to grid’ sensors? any help would be appreciated.

Has anyine used this card together with https://github.com/wlcrs/huawei_solar?

I would be interested in the Template sensors that would be needed for that integration to support this card.

These are the templates I am using for my system (without battery). Let me know if you are able to use them in your setup.

Explanation:

  1. The grid consumption must be multiplied by -1 because the active_power_2 sensor from the huawei_solar integration is negative when importing and positive when exporting, whereas for the solar power card you need it the other way around.
  2. the grid_feed_in sensor represents the PV output to grid, so it is equal to active_power_2 when exporting, but needs to be set to 0 when importing from grid.
  3. the solar_consumption sensor is
  • equal to the output power of the inverter when active_power_2 is positive (you are importing, so you consume all the PV power)
  • the difference between the inverter output power and the export value (your are exporting, so you consume less then the production)
grid_consumption:
        friendly_name: Power imported from grid
        device_class: power
        unit_of_measurement: W
        value_template: >-
          {{ states('sensor.active_power_2') |multiply (-1) }}

grid_feed_in:
        friendly_name: PV output to grid
        device_class: power
        unit_of_measurement: W
        value_template: >-
          {% if states('sensor.active_power_2')|float > 0 %}
          {{ states('sensor.active_power_2') |float }}
          {% else %}
          {{ 0 }}
          {% endif %}

 solar_consumption:
        friendly_name: PV power self consumption
        device_class: power
        unit_of_measurement: W
        value_template: >-
          {% if states('sensor.active_power_2')|float < 0 %}
          {{ states('sensor.active_power')|float }}
          {% else %}
          {% set self_consumption = states('sensor.active_power') |float - states('sensor.active_power_2') |float %}
          {{ self_consumption }}
          {% endif %}

By the way, I am curious: how do you connect to your Huawei inverter for the integration?
Thanks.

There is an integration for reading and writing to the Huawei inverter: Integration Solar inverter huawei 2000L - #1440 by domelek

maybe this is ok for who use charge Luna2000 from grid?

# sensor grid to battery
- platform: template
  sensors:
    grid_to_battery:
      friendly_name: "Grid to Battery"
      unit_of_measurement: "W"
      value_template: >-
        {% set ap2 = states('sensor.active_power_2') | int %}
        {% set bdd = states('sensor.charge_discharge_power') | int %}
        {% set ip = states('sensor.input_power') | int %}
        {% set ap1 = states('sensor.active_power') | int %}
        {% if ap2 < 0 and bdd > 0 and ip <= 0 and ap1 > 0 %}
          {{ (-1 * ap) | int }}
        {% else %}
          {{ (0) }}
        {% endif %}

exellent mod/addon

Is there a way to move the icons to a different location?

For example my batt logo is at the bottom wanted it at the top

this is my code

‘’’
generation_icon: ‘mdi:solar-power’
house_without_appliances_values: 1
show_w_not_kw: 0
#threshold_in_k: 1
show_gap: true

###Grid Power###
grid_to_house_entity: sensor.smart_meter_electricity_import
grid_to_battery_entity: sensor.solax_battery_power_charge
###Solar Power###
generation_to_grid_entity: sensor.solax_grid_export
generation_to_battery_entity: sensor.solax_battery_power_charge
generation_to_house_entity: sensor.solax_pv_total_power_2

###Battery Power###
battery_to_house_entity: sensor.solax_battery_power_charge
battery_to_grid_entity: sensor.solax_battery_power_charge

        # extra values to show as text above icons
        #battery_extra_entity: sensor.solax_x1h_batpower
        #house_extra_entity: sensor.kitchen_thermostat_current_temperature
        generation_extra_entity: sensor.openweathermap_cloud_coverage
        #grid_extra_entity: sensor.smart_meter_electricity_import_today
        
        # optional appliances with consumption and extra values
        appliance1_consumption_entity: sensor.psl_247045_current_energy_2
        appliance1_extra_entity: sensor.i3_120_charging_status 
        #appliance2_consumption_entity: sensor.heating_consumption
        #appliance2_extra_entity: sensor.heating_operation

‘’’

My solar (yellow sun icon value) uses the sesnor “sensor.solax_pv_total_power_2” this is the total my PV is producing in real time, that works fine.
However it then messes with the blue House icon value. The blue house icon should be showing the load of what the house is using in real time. This should use the sensor “sensor.solax_house_load” but there is no where to put that sensor in the above code?

Happy to buy someone a beer who can help/program.

Presume the blue house icon is just taking the solar now reading and not the actual “house load”

As you can see the realtime House load read house is different from the blue icon

I think the calc its doing is SOLAR GEN + GRID IN = blue house logo value, but the house load is way higher but its not aware of that because no sensor for it used in the above code. How can i code in the house load sensor??

Hello every one,

I have some problem for tesla parameters and not able to find out, sure it’s a tip but not clue
 may i ask your knoledge please?

bubble

And here is my code :

# Sensor solar energy card

- platform: template
  sensors:


    meter_export_to_grid:
        friendly_name: energie exportée
        device_class: power
        unit_of_measurement: W
        value_template: >-
          {% if states('sensor.grid_active_power')|float > 0 %}
          {{ states('sensor.grid_active_power') |float }}
          {% else %}
          {{ 0 }}
          {% endif %}


    meter_import_from_grid:
        friendly_name: energie importée
        device_class: power
        unit_of_measurement: W
        value_template: >-
          {% if states('sensor.grid_active_power')|float < 0 %}
          {{ states('sensor.grid_active_power') |float }}
          {% else %}
          {{ 0 }}
          {% endif %}


    house_total_comsumption:
        friendly_name: consommation maison
        device_class: power
        unit_of_measurement: W
        value_template: >-
          {states('sensor.active_power')|float} + {states('sensor.grid_active_power')|float}


    house_comsumption_from_fv:
        friendly_name: auto comsommation des panneaux
        device_class: power
        unit_of_measurement: W
        value_template: >-
          {states('sensor.active_power')|float} - {states('sensor.meter_export_to_grid')|float}

Many thks to all of you!!!

You appear to be using the wrong entities for the card.

e.g your entities for import and export are backwards.

thanks, I did change on the parameters but still something wrong. could you please help me with that code ? or maybe the sensor code


type: custom:tesla-style-solar-power-card
name: Pilou solar
generation_to_grid_entity: sensor.meter_export_to_grid
house_entity: sensor.house_total_comsumption
grid_to_house_entity: sensor.meter_import_from_grid
generation_to_house_entity: sensor.house_comsumption_from_fv
Grid_entity: sensor.meter_import_from_grid
show_w_not_kw: 1

many thks