Custom Solar Power Card the Tesla Style (almost)

Great work! Love this card!

Opened a couple of PR’s with contributions :wink:

Saw that and already implemented a few things on the new version, will try to get to merging at least one today or tomorrow

Hi all,

i have got a question in regards to this card. I have implemented the card into HA successfully. My solarlog is providing the data for the sensors used but it provides only one sensor for:

grid_consumption_entity
grid_feed_in_entity

So if the value is negative it we are taking power from the grid and if positive we are injecting power to the grid. Basicaly this means the animation is not working for me when taking power from grid.
Is there a way to get that fixed? I already thought of a template sensor that is inverting the value when minus. But i have no clue how to do that… is there someone who could help me with that or even has a better idea of solving this?

Greetings

Use templates to divide your sensor. I’m working on a version that will allow this to be used with one. But it’s tricky to have both working.

1 Like

I’m hoping somebody can help with a template. I’ve been trying to split my grid flow and battery flow into two separate sensors so I can have import and export both positive and I’ve failed miserably. I’ve just started by doing a couple of simple parts of what is needed to try to learn more about templates but what I’ve written seems to result in being Unavailable. I’ve done quite a bit of reading about templates and looked through the forum but clearly missed something fundamental.

Below are three things I’ve set so far, only the first works. I realise the code does not do all I need it to do, I’d just like to get the second and third bit’s working before I go further.

  - platform: template
    sensors:
#  flow into house (working)
      zappi_grid_import:
        friendly_name: "ZGrid Import"
        unique_id: "zgrid_import"
        unit_of_measurement: 'kW'
        value_template: "{{ set zappi_grid_import = states.sensor.myenergi_zappi_grid | round(1) }}"
#  Flow into grid (not working)
      zappi_grid_export:
        friendly_name: "ZGrid Export"
        unique_id: "zgrid_export"
        unit_of_measurement: 'kW'
        value_template: "{% set zappi_grid_export = sensor.myenergi_zappi_grid | float %}
                         {% if zappi_grid_export > 0 %}
                            zappi_grid_export | round(1)
                         {% else %}
                           0
                         {% endif %}"
# Flow from battery  (not working)
      battery_consumption:
        friendly_name: "PW2 cons"
        value_template: '{% set batter_cons = sensor.powerwall_battery_now | int %}
                        {% if batter_cons > 0 %}
                            {{ batter_cons | int }}
                        {% else %}
                            0
                        {% endif %}'
        device_class: power
        unit_of_measurement: W

I think your grid_export is missing {{ }} around “zappi_grid_export | round(1)”
and battery_consumption should work but you don’t need the int filter on the first line.
This is what I did:

battery_consumption:
        value_template: '{% set batter_cons = states.sensor.solarsensors.attributes["total_dc_power"] - states.sensor.solarsensors.attributes["power_dc1"] - states.sensor.solarsensors.attributes["power_dc2"] | int %}
                        {% if batter_cons > 0 %}
                            {{ batter_cons | int }}
                        {% else %}
                            0
                        {% endif %}'
        device_class: power
        unit_of_measurement: W
      battery_charging:
        value_template: '{% set batter_cons = (states.sensor.solarsensors.attributes["total_dc_power"] - states.sensor.solarsensors.attributes["power_dc1"] - states.sensor.solarsensors.attributes["power_dc2"]) | int %}
                        {% if batter_cons < 0 %}
                            {{ (batter_cons * -1) | int }}
                        {% else %}
                            0
                        {% endif %}'
        device_class: power
        unit_of_measurement: W 

Try some parenthesis for the right side of the “=” maybe just in case

Try this, it`s working for me:

 grid_consumption:
    friendly_name: "Grid Consumption"
    unit_of_measurement: 'W'
    value_template: >
      {% if states('sensor.power_meter_active_power') | int > 0 %}
        0
      {% else -%}
        {{ (states('sensor.power_meter_active_power') | int) | abs }} 
      {% endif %}      

  grid_feed_in:
    friendly_name: "Grid Feed In"
    unit_of_measurement: 'W'
    value_template: >
      {% if states('sensor.power_meter_active_power') | int > 0 %}
        {{ states('sensor.power_meter_active_power') }}
      {% else -%}
        0
      {% endif %}

I have just one sensor (power_meter_active_power) for both consumption/feed in power from/to the grid, and I have solved the question with the templates above. Hope it will help you.

Please help. I did a manual Installation of the card and ended up with an animation which don’t show the battery.ana
my config:
grid_consumption_entity: sensor.grid_consumption
grid_to_battery_entity: sensor.grid_to_battery
battery_charge_entity: sensor.battery_charge
battery_consumption_entity: sensor.battery_consumption
house_consumption_entity: sensor.house_consumption
type: ‘custom:tesla-style-solar-power-card’

Looks like I needed: “battery_charging_entity: sensor.battery_charging” for the battery to show. Even thou I don’t have a solar panel at this stage.

Hi @Er_Mano ,
I used your script and I think I am almost there, but all these sensors keep confusing me.
I use mqtt to get the solar panel sensor in HA, and a P1 connection to my smart meter to read the values.

image

The card shows:

image

What Am I missing?

Hi @Robbie-65.
You need to receive data from 5 sensors if you want this card working properly, and I see just 3… I miss the grid_feed_in_entity (the watts you are exporting to the grid) and the solar_consumption_entity (the dot that slide down the line towards the house icon).
What I have:

You have to create a template with the code I wrote in my first post:

grid_feed_in:
    friendly_name: "Grid Feed In"
    unit_of_measurement: 'W'
    value_template: >
      {% if states('sensor.power_meter_active_power') | int > 0 %}
        {{ states('sensor.power_meter_active_power') }}
      {% else -%}
        0
      {% endif %}

where you have to replace my power_meter_active_power for your smartmeter_house_146. Just note that I got negative readings from my smart meter when I am exporting energy to the grid.

For the solar_consumption_entity I have the same sensor than for the solar_yield_entity, as you can see. I guess you have properly integrated the other 3 sensors in your HA. Try and tell me.

Hi @Er_Mano,
Thanks for your clear reply.
One step further :slight_smile:
image
image

The dot is moving from the orange solar panel, down to the grid on the left.
That does not seem right.
What about the house consumption sensor? I choose the reading from my smart meter, but that should be the smartmeter minus the solar panels, because my smartmeter reading include the solar panels.
I should create a separate template which substracs these ?
I only have two “real” sensors, 1 for my solar panels, and 1 for my smartmeter.

And my solar sensor shows NA because it is dark now, would be nice if it would show 0. I found a template trick for that, but apparently that does not function correctly.

Rob

Update:
I swapped the two grid sensors, and now the blue dot is moving in the richt direction.

Lets see what happens tomorrow when the sun is shining.

image
image

You are absolutely rigth, you have to substrac the smartmeter reading from the solar panels reading. In my case:

house_consumption:
        friendly_name: "Consumo Vivienda"
        unit_of_measurement: 'W'
        value_template: "{{ ((states.sensor.sun2000l_3ktl.state | int) - (states.sensor.power_meter_active_power.state | int)) }}"

I just have one sensor, the inverter. All the others are attributes of it (daily yield, total yield, voltage, current, inverter temperature, power meter active power,…), made sensors thanks to the templates.

I had to make some adjustments to the template and because, the smartmeter can show a negative value, the trick to calculate the House Consumption seems to be to add (+) both values.
(add a negative value would result in subtraction)

I now have this, will check tomorrow, because the sun will shine again. :slight_smile:

# Solar panels ('sensor.inverter_instant_power') always positive

# Smartmeter P1 ('sensor.smartmeter_house_146')  
# can be positive (grid Consumption) or negative (grid feed in)
    
# Make sure that solar panels show 0 and not NA if dark
  - platform: template
    sensors:
      pv_power_numeric:
        value_template: "{{ states('sensor.inverter_instant_power') | float }}"
        unit_of_measurement: "W"
        
# Make sure that Grid Feed In is always positive
      grid_feed_in:
         friendly_name: "grid feed In"
         unit_of_measurement: 'W'
         value_template: >
           {% if states('sensor.smartmeter_house_146') | int > 0 %}
             0
           {% else -%}
             {{ (states('sensor.smartmeter_house_146') | int) | abs }} 
           {% endif %}
  
# Make sure that grid consumption in is always positive
      grid_consumption:
         friendly_name: "grid consumption"
         unit_of_measurement: 'W'
         value_template: >
           {% if states('sensor.smartmeter_house_146') | int > 0 %}
             {{ states('sensor.smartmeter_house_146') }}
           {% else -%}
             0
           {% endif %}
           
# house consumption is smartmeter plus solar panels   (smartmeter can be negative)        
      house_consumption:
         friendly_name: "house consumption"
         unit_of_measurement: 'W'
         value_template: "{{ ((states.sensor.smartmeter_house_146.state | int) + (states.sensor.Inverter_Instant_Power.state | int)) }}"

Love this card!

Is there any way to style the color of the icons and circles to match my current theme?

Hey! Glad you like it. The colours should be matched to your standard theme colors since they are defined as variables from your theme:

  color: var(--primary-text-color);
  border-color: var(--primary-text-color);

The used variables are:

  • –primary-text-color
  • –warning-color
  • –success-color
  • –info-color

Check whether your theme is defining those. Should normaly be the case.

Thanks a bunch, will check it out!

Hi All,

Has anyone successfully set this card up for a SolarEdge inverter. I have most of the card working but can’t seem to get the grid to display correctly

type: 'custom:tesla-style-solar-power-card'
house_consumption_entity: sensor.solaredge_power_consumption
grid_consumption_entity: sensor.solaredge_grid_power
grid_feed_in_entity: sensor.solaredge_template_panels_2_grid
solar_consumption_entity: sensor.solaredge_template_current_solarpower
solar_yield_entity: sensor.solaredge_solar_power

image


I’m pretty sure I have 3 out of the five correct

  • house_consumption_entity: sensor.solaredge_power_consumption
  • grid_consumption_entity: sensor.solaredge_grid_power
  • solar_yield_entity: sensor.solaredge_solar_power

I just need to work on the grid feed-in and solar consumption

This is what I come up with

for the grid_feed_in_entity:

      solaredge_template_panels_2_grid:
        friendly_name: 'Panels 2 Grid'
        value_template: >-
          {{ '%0.1f' | format (states('sensor.solaredge_solar_power') | float - 
                                states('sensor.solaredge_power_consumption') | float ) }}
        unit_of_measurement: 'kW' 

for the solar_consumption_entity:

      solaredge_template_current_solarpower:
        friendly_name: 'Current Solar Power'
        value_template: '{{(states.sensor.solaredge_current_power.state | float / 1000) | round(2)}}'
        unit_of_measurement: 'kW' 

Am I close?

2 Likes

I’m really bad with those strformat functions, so I try to avoid them. Shouldn’t this work just as well?

solaredge_template_panels_2_grid:
        friendly_name: 'Panels 2 Grid'
        value_template: >-
          {{  (states('sensor.solaredge_solar_power') | float - 
                                states('sensor.solaredge_power_consumption') | float ) | round(1) }}
        unit_of_measurement: 'kW' 

Apart from that are you sure you are not mixing W and kW there somewhere, meaning the original solaredge sensors are all just W?

1 Like

Thank you @reptilex for your reply

I’ve doubled checked and can confirm that all sensors used for this card are presenting in kW. I have now adjusted my “solaredge_template_panels_2_grid” sensor to reflect your example, the value looks correct in HA.

image

It seems the flow is now working but the display is still showing the value not rounded
image

Any other ideas?