Rewritten Tesla Style Solar Power Card

Thanks this is working very well for me now, with SolarEdge (15 mins), various power monitoring plugs around the house and of course the car. Next step, switch to SolarEdge ModBus to get realtime updates.

I really like this card. Thank you for all the great work. I had it up and running with the old version with my Fronius inverter. It worked perfect. However I am lost now. Maybe someone who is using Fronius can share their code.

Hi,

Let me share this :slight_smile:

This is my card, I have a Fronius Symo 3-phase inverter. At the big red dot I have 3x PZEM004t CT-clamp meters. (importance is that this also could be in the grid entry point, but then the below ± operations must be modified accordingly.)
2021-04-16 103901
Card base config:

type: 'custom:tesla-style-solar-power-card'
grid_to_house_entity: sensor.grid_cons_pac
generation_to_grid_entity: sensor.grid_solar_pac
generation_to_house_entity: sensor.house_solar_pac
grid_entity: sensor.grid_cons_pac
house_entity: sensor.house_pac
generation_entity: sensor.solar_pac

Template sensors base config to make this work:

  - platform: template
    scan_interval: 15
    sensors:
      house_pac:
        value_template: >-  ### House power, I have 3 phase power line, *PAC is for Power AC ###
            {{ (( states('sensor.ac1_power') | int ) + ( states('sensor.ac2_power') | int ) + ( states('sensor.ac3_power') | int )) }}
      grid_pac:
        value_template: >- ### Calculated power grid, sensor.solar_pac is the output of my Fronius inverter, I have this entity defined in MODBUS config ###
            {{ ( states('sensor.house_pac') | int ) - ( states('sensor.solar_pac') | int ) }}
      grid_solar_pac:
        value_template: >- ### This is to not to go negative, as this is an absolute value and makes no sense if we're getting power into solar generator ###
          {% if (states('sensor.solar_pac') | int ) >= ( states('sensor.house_pac') | int ) %}
            {{ ((states('sensor.solar_pac') | int ) - ( states('sensor.house_pac') | int )) | int }}
          {% else %}
            {{ 0 | int }}
          {% endif %}
      grid_cons_pac:
        value_template: >- ### Same here, because we need grid-to-house, and house is not generating anything ###
          {% if  (states('sensor.solar_pac') | int ) >= ( states('sensor.house_pac') | int ) %}
            {{ 0 | int }}
          {% else %}
            {{ (( states('sensor.house_pac') | int ) - (states('sensor.solar_pac') | int )) | int }}
          {% endif %}
      house_solar_pac:
        value_template: >- ### Solar generation consumed by house ###
            {{ ((states('sensor.solar_pac') | int ) - ( states('sensor.grid_solar_pac') | int )) | int }}

I have a Fronius Symo and using the integration by Safepay in HACS. These are the templated sensors I needed to make the rewritten card work:

current_generation_to_grid:
  value_template: >
          {% if states("sensor.fronius_relative_autonomy") | float > 99 %}
          {{ '%.1f' | format ((states("sensor.fronius_panel_status") | float) - (states("sensor.current_consumed_positive") | float)) }}
          {% else %}
          0
          {% endif %}
  friendly_name: 'Current generation to grid'
  unit_of_measurement: kW

current_generation_to_house:
  value_template: >
          {% if states("sensor.fronius_relative_self_consumption") | float == 100 %}
            {{ states("sensor.fronius_panel_status") | float | round(2) }}
          {% elif states("sensor.fronius_relative_self_consumption") | float > 0 %}
            {{ states("sensor.current_consumed_positive") | float | round(2) }}
          {% else %}
          0
          {% endif %}
  friendly_name: 'Current generation to house'
  unit_of_measurement: kW

current_grid_to_house:
  friendly_name: 'Current use from grid'
  unit_of_measurement: 'kW'
  value_template: >
          {% if states('sensor.fronius_grid_usage') | float < 0 %}
          0
          {% else %}
          {{ states("sensor.fronius_grid_usage") }}
          {% endif %}

current_consumed_positive:
  friendly_name: 'House load'
  unit_of_measurement: 'kW'
  value_template: '{{ states("sensor.fronius_house_load") | float * -1 }}'

and the card configuration (without any extra sensors):

type: 'custom:tesla-style-solar-power-card'
name: Electricity
generation_icon: 'mdi:solar-power'

grid_to_house_entity: sensor.current_grid_to_house
generation_to_grid_entity: sensor.current_generation_to_grid
generation_to_house_entity: sensor.current_generation_to_house

grid_entity: sensor.fronius_grid_usage
house_entity: sensor.fronius_house_load
generation_entity: sensor.fronius_panel_status

I was very abscent from the forum for a while seems to me you all got fronius working. I have added some new features and have started with the visual configuration, but it’s a slow process. Hopefully this will be better next month.

1 Like

I have this updating now over ModBus now (every 5 seconds), so the resolution is great!

Hi @markpurcell, are you able to share your code? i’m having an issue where my solar is feeding both the house and grid at the same rate (Solar & Grid values should be half or what they are - image below has the correct values) - i feel that i’m missing something:

So the Solar and the House are both feeding the grid which should not be the case, only the solar should be feeding the gird. The house should only be getting power from the grid only if the solar is below the house usage.

image
Solar feeds the house & grid, house is also feeding the grid which is incorrect

config:

name: test
type: 'custom:tesla-style-solar-power-card'
generation_to_house_entity: sensor.modbus_sma_pv_power
generation_to_grid_entity: sensor.modbus_sma_pv_power
grid_to_house_entity: sensor.power_total

image
Solar feeds the house and excess power goes to the grid

config:

type: 'custom:tesla-style-solar-power-card'
grid_consumption_entity: sensor.power_total
generation_to_house_entity: sensor.modbus_sma_pv_power
house_consumption_entity: sensor.current_power_usage
grid_to_house_entity: sensor.power_total
house_extra_entity: sensor.home_temp_max_0
generation_extra_entity: sensor.modbus_sma_temperature
grid_extra_entity: sensor.energy_total
grid_entity: sensor.power_total
generation_entity: sensor.modbus_sma_pv_power
house_entity: sensor.current_power_usage

It’s not critical, but if i can get my image to look like the top one i’d be happy - but if not possiable i’ll have to leave it as the lower image.

Hope this makes sense :slight_smile:

Thanks for your guidance on this one.

1 Like

Pedro,

I had the same issue.

You need to use some templates to ensure you don’t get negative values:

When grid_to_house is positive you are importing to grid, however if it is negative you need to set it to zero and set that value to generation_to_grid.

Here are some of my template rules, which you will need to modify for sma.

# This is used for Telsa Solar / Consumption power distribution card  
# https://community.home-assistant.io/t/custom-solar-power-card-the-tesla-style-almost/220705/95

    # sensor used to show power flow from Panels to Grid, but shows a negative at night   
    solaredge_template_panels_2_grid_day:
      friendly_name: 'Panels 2 Grid during daylight'
      value_template: >-
        {{ (states('sensor.solaredge_solar_power') | float - 
                              states('sensor.solaredge_power_consumption') | float ) | round(2) }}
      unit_of_measurement: 'kW' 
      device_class: "power"

    # shows the current grid power being fed from the grid to the house and doesn't allow it to show a negative number only positive numbers  
    solaredge_template_curent_grid_consumption:
      friendly_name: 'Consumption'
      unit_of_measurement: kW        
      device_class: power
      value_template: >-
        {% if states('sensor.solaredge_grid_power')|float < 0 %}
          0
        {% else %}
          {{ states('sensor.solaredge_grid_power') }}
        {% endif %}

    # sensor used to show power flow from Panels to Grid and doesn't allow it to show a negative number only positive numbers
    solaredge_template_panels_2_grid:
      friendly_name: 'Panels 2 Grid'
      unit_of_measurement: 'kW' 
      device_class: "power"
      value_template: >-
        {% if states('sensor.solaredge_template_panels_2_grid_day') | float > 0 %}
          {{ states('sensor.solaredge_template_panels_2_grid_day') }}
        {% else -%}
          0
        {% endif %}        

    # shows the solar power being fed to the house and doesn't allow it to show a negative number only positive numbers 
    solaredge_template_curent_solar_consumption:
      friendly_name: 'Solar 2 House'
      unit_of_measurement: kW        
      device_class: power
      value_template: >-
        {% if states('sensor.solaredge_template_panels_2_grid_day') | float > 0 %}
          {{ states('sensor.solaredge_power_consumption') }}
        {% else -%}
          {{ (states('sensor.solaredge_power_consumption')| float - states('sensor.solaredge_grid_power')| float) }}
        {% endif %}

Great thanks Mark i’ll give that go,

Which entities from Solaredge Modbus TCP do you use? I have only 22 entities from Modbus…

This is a great card, just wondering if it is possible to add more appliances?
Ie maybe 3 more ?

Hi everyone…disclaimer, i am a home assistant user and reasonably technical but in no way a dev.

Got a new solaredge SE6000H inverter, panels, optimisers, solaredge immersion diverter and solaredge modbus. Get all the stats i need on the app but its via cloud with 15min refresh. Just set up TCP Modbus as i thought getting info from the inverter real time would be great…(want to set up some node red to turn on/off boiler hot water in favour of solar excess via immersion diverter to make use of excess energy), however i dont see any metrics from my modbus box…only the inverter. The kind of thing i am looking for is export to grid, grid consumption etc…(all visible on my app) but not via TCP modbus. Am i being stupid or is this a genuine limitation? any help would be great. thanks

Its ok, answered my own question in the end, realised i had not ticked the Meter 1 option in the solaredge TCP modbus integration setup…now got access to lots more information. thanks anyway

Sadly that is not as easy as it should and I won’t be adding more appliances for now. Maybe you want to group them with templates and show groups like “appliances” and “climate”

Thanks, all good great card as it is anyway

Hey what a really great work!
I got stuck with my configuration and cannot figure out my mistake: My PV is an LG ESS HOME System. It serves four main values via MQTT: Load_power (sum of all house consumption), PV_Total_Power (like name says), GRID_Power (like name says), Battery_DC_Power (like name says). But additionally I have to cope with “directions” telling me if the value is from or to house, from or to battery, from or to grid.
Since the directions come as 0 or 1, I tried calculating as simple as possible with template sensors.

But even the simplies configuration seems to be incorrect: In the evening (PV is zero, battery is empty) I simply have GRID buying.
So I assume, that the numbers beneath the bubbles house and grid show exactly the same vaule?
GRID bubble shows 573Wh, HOUSE bubble shows 5,7kWh. The numbers are relating 1:10.
What am I doing wrong?

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