Custom Solar Power Card the Tesla Style (almost)

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

I don’t actually understand what is wrong? What is not working?

what is not working is :

  • I have a negative value
  • it doesnt show the house consumption
  • no production on solar pannel when they are producing
  • no info about energy exported
  • no ingo about energy imported

I really want to say you thank you for your time

I think this is because of my sensor code… it looks like text in green :

I changed for power card, much easier to parameter… thanks again!

I’m not sure your sensors.yaml is configured correctly.

How is it included in configuration.yaml? as a package or like sensor: !include sensors.yaml

Hola, yes it does, but finally change for other intégration :stuck_out_tongue_winking_eye:

Hi all.

Is there a way to resize this card? I have tried using CardMod to size the card, but that doesn’t make the text/graphics scale, and so they just run off the sides of the card.

Thanks for any suggestions!

1 Like

Who can help me out ?

I have a huawei inverter and battery.

For this card all values need to be positve. But my battery uses the same sensor ( [sensor.battery_charge_discharge_power] ) for battery discharging and charging. The valua gets positive when charging and negative when discharging.

Use some templates with min, max and abs functions to make two new sensors, one for charging one for charging.