UPDATED! SolarEdge Modbus full setup guide with Energy Dashboard integration for Installations with Battery connected

UPDATE (March 1st): Added utility meters for more stats.
UPDATE (August 10th): Configuration without battery can be found here, thanks to @SgtBatten :UPDATED! SolarEdge Modbus full setup guide with Energy Dashboard integration for Installations with Battery connected - #306 by SgtBatten

I completely redid the integration and calculation of the sensors and am very happy with the results I have now.

Purpose:
I don’t like how Solaredge reports the production and usage statistics. When I use the default cloud based integration, or the sensors provided by the modbus integration directly, I do not see my true panel production. The reason for this is that Solaredge does not count charging of the connected battery into the production, but only the discharging. This means I get a distorted image about my production.
I spend a lot of time actually analyzing all the sensors, dependencies and actual consumption in house to get to my correct result.

Notes:
You will see differences in some situations. Mainly when discharging of the battery is involved. The reason for this is that both the battery and the inverter have a certain effectiveness (Wirkungsgrad in German). I found out how I can calculate these from the available sensors, so they are taking into account. That means for example:
My battery has a maximum output of 5 kW, however on the AC side of the inverter (that what actually goes into the house) there is only maximum 4,7 kW. This is due to the losses we have from both the battery and the inverter. Actually the inverter normally is pretty stable at 98%, the battery output however varies between as low as 60% and as high as 96%. Solaredge chooses to ignore this which leads to the effect that the House Consumption and the “Usage of Battery” in the monitoring platform are actually both too high. It doesn’t matter that much, since the import and export values are correct, but I like to see the real values.
You may need to wait a day or so before the utilty meters actually have values before you can add them to the Energy Dashboard
If you had the previous version of my integration setup, you may need to reset some statistics. Go to “Developer Tools - Statistics” and use the “Fix Issue” if these are available. Another option to really start clean is of course to delete your database…

Changes to the previous version of my integration:

  • Packaged the sensor setup in a new “energy.yaml” file
  • Redid all the sensors for the Tesla Style card
  • Included Battery and Inverter effectivness sensors
  • Making sure that minor deviations are ignored
  • Probably a lot more minor things

I will keep working on this, since there is also a request from @stephanschuster (further below in the thread) so you can expect more updates in the future. However, it will be additions to this setup, not a complete rework anymore.

So…to the setup:

I am using this integration:

which is available through HACS. For the setup and installation just follow the instructions. There is an option to select the interval in which it should update, I use 3 seconds for this, since I like to see almost instant values. It does put a strain on the SD card, since the database will grow fast. So…I chose to use the recorder configuration to only include the entities I need. On top of that I now have an SSD connected to my Raspberry and run HASS on there.

I then have the Tesla Style Power card from here:

This is the result:
image

Next I have the Power distribution card from here:

Looks like this:
image

This is how my Energy Dashboard now looks after a sunny day:

Following configuration, sensors and templates:

configuration.yaml:

homeassistant:
  packages:
    energy: !include energy.yaml

create a new file called “energy.yaml” in a subfolder called “packages” of your config directory with following contents:

template:
  - sensor:
    - name: "Solar Selfconsumption Ratio"
      unique_id: solar_selfconsumption_ratio
      icon: mdi:percent-outline
      state: >
        {% if (((states('sensor.solar_panel_to_house_daily')| float(0)) + (states('sensor.solar_battery_in_daily')| float(0)) + (states('sensor.solar_exported_power_daiy')| float(0))) <= 0) %}
          0
        {% else %}
          {{((((states('sensor.solar_panel_to_house_daily')| float(0)) + (states('sensor.solar_battery_in_daily')| float(0))) / ((states('sensor.solar_panel_to_house_daily')| float(0)) + (states('sensor.solar_battery_in_daily')| float(0)) + (states('sensor.solar_exported_power_daily')| float(0)))) * 100) | round (0) }}
        {% endif %}
    - name: "Solar Autarkie Ratio"
      unique_id: solar_autarkie_ratio
      icon: mdi:percent-outline
      state: >
        {% if ((states('sensor.solar_house_consumption_daily') | float(0)) <= 0) %}
          0
        {% else %}
          {{((1 - ((states('sensor.solar_imported_power_daily') | float(0)) / (states('sensor.solar_house_consumption_daily') | float(0)))) * 100 ) | round (0)}}   
        {% endif %}  
    
    - name: "Solar Inverter Effectiveness"
      unique_id: solar_inverter_effectiveness
      icon: mdi:percent-outline
      unit_of_measurement: '%'
      state: >
        {% if ((states('sensor.solaredge_dc_power') | float(0)) < 100) or ((states('sensor.solaredge_ac_power') | float(0)) < 100)%}
          {{(states('sensor.solar_inverter_effectiveness'))}}
        {% else %}
          {% if is_state('sensor.solar_inverter_effectiveness', 'unknown') %}
            1
          {% elif ((states('sensor.solaredge_ac_power') | float(0)) <= 0) %}
            {{(states('sensor.solar_inverter_effectiveness'))}}
          {% elif ((states('sensor.solaredge_dc_power') | float(0)) <= 0) %}
            {{(states('sensor.solar_inverter_effectiveness'))}}
          {% else %}
            {{(states('sensor.solaredge_ac_power') | float(0)) / (states('sensor.solaredge_dc_power') | float(0))}}
          {% endif %}
        {% endif %}
        
    - name: "Solar Battery Effectiveness"
      unique_id: solar_battery_effectiveness
      icon: mdi:percent-outline
      unit_of_measurement: '%'
      state: >       
        {% if (((states('sensor.solaredge_dc_power') | float(0)) + (states('sensor.solaredge_battery1_power') | float(0))) <= 0 ) %}
          {% if ((states('sensor.solaredge_battery1_power')| float(0)) >= 0) %}
            {{(states('sensor.solar_battery_effectiveness'))}}
          {% elif ((states('sensor.solaredge_dc_power') | float(0)) <= 0) %}
            {{(states('sensor.solar_battery_effectiveness'))}}  
          {% else %}
            {{1 - ((((states('sensor.solaredge_battery1_power') | float(0)) * -1) - (states('sensor.solaredge_dc_power') | float(0))) /  ((states('sensor.solaredge_battery1_power') | float(0)) * -1))}}
          {% endif %} 
        {% elif is_state('sensor.solar_battery_effectiveness', 'unknown') %}
          1
        {% elif is_state('sensor.solar_battery_effectiveness', 0) %}
          1
        {% else %}
          {{(states('sensor.solar_battery_effectiveness'))}}
        {% endif %}

    - name: "Solar Panel Production W"
      unique_id: solar_panel_production_w
      unit_of_measurement: 'W'
      icon: mdi:solar-power
      state: >  
        {% if ((states('sensor.solaredge_dc_power') | float(0)) + (states('sensor.solaredge_battery1_power') | float(0)) <= 0) %}
          0
        {% elif (is_state('sensor.solaredge_dc_power', 'unknown')) or (is_state('sensor.solaredge_battery1_power', 'unknown'))%}
          0
        {% else %}
          {{((states('sensor.solaredge_dc_power') | float(0)) + (states('sensor.solaredge_battery1_power') | float(0)))}}
        {% endif %}      

    - name: "Solar Panel To House W"
      unique_id: solar_panel_to_house_w
      unit_of_measurement: 'W'
      icon: mdi:solar-power
      state: > 
        {% if ((states('sensor.solaredge_battery1_power') | float(0)) >= 0) and ((states('sensor.solaredge_m1_ac_power') | float(0)) > 0) %}
          {{(states('sensor.solaredge_ac_power') | float(0) - states('sensor.solaredge_m1_ac_power') | float(0))}}
        {% elif ((states('sensor.solaredge_battery1_power') | float(0)) >= 0) and ((states('sensor.solaredge_m1_ac_power') | float(0)) < 0) %}
          {{states('sensor.solaredge_ac_power') | float(0)}}
        {% elif ((states('sensor.solaredge_battery1_power') | float(0)) < 0)%}
          {% if ((states('sensor.solaredge_dc_power') | float(0) + states('sensor.solaredge_battery1_power') | float(0)) < 0 ) %}
            0
          {% else %}
            {{((states('sensor.solaredge_dc_power') | float(0)) + (states('sensor.solaredge_battery1_power') | float(0))) * (states('sensor.solar_inverter_effectiveness') | float(0))}}
          {% endif %}   
        {% else %}
          0
        {% endif %}  
 
    - name: "Solar Grid To House W"
      unique_id: solar_grid_to_house_w
      unit_of_measurement: 'W'
      icon: mdi:transmission-tower-export
      state: > 
        {% if ((states('sensor.solaredge_m1_ac_power') | float(0)) <= 0) %}
          {{((states('sensor.solaredge_m1_ac_power') | float(0)) *-1)}}
        {% else %}
          0
        {% endif %}

    - name: "Solar Panel To Grid W"
      unique_id: solar_panel_to_grid_w
      unit_of_measurement: 'W'
      icon: mdi:solar-power
      state: >  
        {% if ((states('sensor.solaredge_m1_ac_power') | float(0)) > 0) %}
          {{(states('sensor.solaredge_m1_ac_power') | float(0))}}
        {% else %}
          0
        {% endif %}   

    - name: "Solar Battery To House W"
      unique_id: solar_battery_to_house_w
      unit_of_measurement: 'W'
      icon: mdi:battery-negative
      state: >   
        {% if ((states('sensor.solaredge_battery1_power') | float(0)) < 0) %}
          {{((states('sensor.solaredge_battery1_power') | float(0)) * -1) * (states('sensor.solar_battery_effectiveness')| float(0)) * (states('sensor.solar_inverter_effectiveness')| float(0))}}
        {% else %}
          0
        {% endif %} 

    - name: "Solar Panel To Battery W"
      unique_id: solar_panel_to_battery_w
      unit_of_measurement: 'W'
      icon: mdi:solar-power
      state: >    
        {% if ((states('sensor.solaredge_battery1_power') | float(0)) > 0) %}
          {% if ((states('sensor.solar_grid_to_battery_w') | float(0)) > 0) %}
            0
          {% else %}
            {{(states('sensor.solaredge_battery1_power') | float(0))}}
          {% endif %} 
        {% else %}
          0
        {% endif %}
 
    - name: "Solar Grid To Battery W"
      unique_id: solar_grid_to_battery_w
      unit_of_measurement: 'W'
      icon: mdi:battery-positive
      state: >    
        {% if (is_state('sensor.solaredge_ac_power', '0')) and ((states('sensor.solaredge_battery1_power') | float(0)) > 0) %}
          {{(states('sensor.solaredge_battery1_power') | float(0))}}
        {% else %}
          0
        {% endif %} 

    - name: "Solar Battery In W"
      unique_id: solar_battery_in_w
      unit_of_measurement: 'W'
      icon: mdi:battery-positive
      state: >           
        {{(states('sensor.solar_grid_to_battery_w') | float(0)) + (states('sensor.solar_panel_to_battery_w') | float(0))}}  

    - name: "Solar House Consumption W"
      unique_id: solar_house_consumption_w
      unit_of_measurement: 'W'
      icon: mdi:home
      state: >             
        {{(states('sensor.solar_panel_to_house_w') | float(0)) + (states('sensor.solar_battery_to_house_w') | float(0)) + (states('sensor.solar_grid_to_house_w') | float(0))}}  

    - name: "Solar Imported Power W"
      unique_id: solar_imported_power_w
      unit_of_measurement: 'W'
      icon: mdi:transmission-tower-export
      state: >          
        {% if ((states('sensor.solaredge_m1_ac_power') | float(0)) <= 0) %}
          {{((states('sensor.solaredge_m1_ac_power') | float(0)) *-1)}}
        {% else %}
          0
        {% endif %}       

    - name: "Solar Exported Power W"
      unique_id: solar_exported_power_w
      unit_of_measurement: 'W'
      icon: mdi:transmission-tower-import
      state: >            
        {% if ((states('sensor.solaredge_m1_ac_power') | float(0)) > 0) %}
          {{(states('sensor.solaredge_m1_ac_power') | float(0))}}
        {% else %}
          0
        {% endif %}        

    - name: "Solar Lifetime Production"
      unique_id: solar_lifetime_production
      unit_of_measurement: 'MWh'
      icon: mdi:solar-power
      state: >    
        {{(((states('sensor.solaredge_ac_energy_kwh') | float(0)) / 1000) | round (2))}}
                 
sensor:
  - platform: integration
    source: sensor.solar_panel_production_w
    method: left
    unit_prefix: k
    name: solar_panel_production_kwh 
  - platform: integration
    source: sensor.solar_battery_to_house_w
    method: left
    unit_prefix: k
    name: solar_battery_out_kwh 
  - platform: integration
    source: sensor.solar_battery_in_w
    method: left
    unit_prefix: k
    name: solar_battery_in_kwh 
  - platform: integration
    source: sensor.solar_house_consumption_w
    method: left
    unit_prefix: k
    name: solar_house_consumption_kwh 
  - platform: integration
    source: sensor.solar_imported_power_w
    method: left
    unit_prefix: k
    name: solar_imported_power_kwh 
  - platform: integration
    source: sensor.solar_exported_power_w
    method: left
    unit_prefix: k
    name: solar_exported_power_kwh 
  - platform: integration
    source: sensor.solar_panel_to_house_w
    method: left
    unit_prefix: k
    name: solar_panel_to_house_kwh

  - platform: statistics
    name: "Solar Battery Effectiveness Average"
    unique_id: solar_battery_effectiveness_average
    state_characteristic: mean
    sampling_size: 1200
    max_age:
      hours: 24
    entity_id: sensor.solar_battery_effectiveness

  - platform: statistics
    name: "Solar Inverter Effectiveness Average"
    unique_id: solar_inverter_effectiveness_average
    state_characteristic: mean
    sampling_size: 1200
    max_age:
      hours: 24
    entity_id: sensor.solar_inverter_effectiveness

    
utility_meter:
  solar_panel_production_daily:
    source: sensor.solar_panel_production_kwh
    name: Solar Panel Production Daily
    cycle: daily
  solar_battery_in_daily:
    source: sensor.solar_battery_in_kwh
    name: Solar Battery In Daily
    cycle: daily 
  solar_battery_out_daily:
    source: sensor.solar_battery_out_kwh
    name: Solar Battery Out Daily
    cycle: daily
  solar_house_consumption_daily:
    source: sensor.solar_house_consumption_kwh
    name: Solar House Consumption Daily
    cycle: daily 
  solar_imported_power_daily:
    source: sensor.solar_imported_power_kwh
    name: Solar Imported Power Daily
    cycle: daily 
  solar_imported_power_daily_solaredge:
    source: sensor.solaredge_m1_imported_kwh
    name: Solar Imported Power Daily Solar Edge
    cycle: daily 
  solar_exported_power_daily:
    source: sensor.solar_exported_power_kwh
    name: Solar Exported Power Daily
    cycle: daily
  solar_panel_to_house_daily:
    source: sensor.solar_panel_to_house_kwh
    name: Solar Panel To House Daily
    cycle: daily

  solar_panel_to_house_weekly:
    source: sensor.solar_panel_to_house_kwh
    name: Solar Panel To House Weekly
    cycle: weekly
  solar_imported_power_weekly:
    source: sensor.solar_imported_power_kwh
    name: Solar Imported Power Weekly
    cycle: weekly 
  solar_house_consumption_weekly:
    source: sensor.solar_house_consumption_kwh
    name: Solar House Consumption Weekly
    cycle: weekly 
  solar_panel_production_weekly:
    source: sensor.solar_panel_production_kwh
    name: Solar Panel Production Weekly
    cycle: weekly
  solar_battery_in_weekly:
    source: sensor.solar_battery_in_kwh
    name: Solar Battery In Weekly
    cycle: weekly 
  solar_battery_out_weekly:
    source: sensor.solar_battery_out_kwh
    name: Solar Battery Out Weekly
    cycle: weekly
  solar_exported_power_weekly:
    source: sensor.solar_exported_power_kwh
    name: Solar Exported Power Weekly
    cycle: weekly
    
  solar_panel_to_house_monthly:
    source: sensor.solar_panel_to_house_kwh
    name: Solar Panel To House Monthly
    cycle: monthly
  solar_imported_power_monthly:
    source: sensor.solar_imported_power_kwh
    name: Solar Imported Power Monthly
    cycle: monthly 
  solar_house_consumption_monthly:
    source: sensor.solar_house_consumption_kwh
    name: Solar House Consumption Monthly
    cycle: monthly 
  solar_panel_production_monthly:
    source: sensor.solar_panel_production_kwh
    name: Solar Panel Production Monthly
    cycle: monthly
  solar_battery_in_monthly:
    source: sensor.solar_battery_in_kwh
    name: Solar Battery In Monthly
    cycle: monthly 
  solar_battery_out_monthly:
    source: sensor.solar_battery_out_kwh
    name: Solar Battery Out Monthly
    cycle: monthly
  solar_exported_power_monthly:
    source: sensor.solar_exported_power_kwh
    name: Solar Exported Power Monthly
    cycle: monthly
    
  solar_panel_to_house_yearly:
    source: sensor.solar_panel_to_house_kwh
    name: Solar Panel To House Yearly
    cycle: yearly
  solar_imported_power_yearly:
    source: sensor.solar_imported_power_kwh
    name: Solar Imported Power Yearly
    cycle: yearly 
  solar_house_consumption_yearly:
    source: sensor.solar_house_consumption_kwh
    name: Solar House Consumption Yearly
    cycle: yearly 
  solar_panel_production_yearly:
    source: sensor.solar_panel_production_kwh
    name: Solar Panel Production Yearly
    cycle: yearly
  solar_battery_in_yearly:
    source: sensor.solar_battery_in_kwh
    name: Solar Battery In Yearly
    cycle: yearly 
  solar_battery_out_yearly:
    source: sensor.solar_battery_out_kwh
    name: Solar Battery Out Yearly
    cycle: yearly
  solar_exported_power_yearly:
    source: sensor.solar_exported_power_kwh
    name: Solar Exported Power Yearly
    cycle: yearly

Configuration for the Tesla Style Card:

type: custom:tesla-style-solar-power-card
name: Home Energy Flow
grid_to_house_entity: sensor.solar_grid_to_house_w
generation_to_grid_entity: sensor.solar_panel_to_grid_w
generation_to_battery_entity: sensor.solar_panel_to_battery_w
generation_to_house_entity: sensor.solar_panel_to_house_w
battery_to_house_entity: sensor.solar_battery_to_house_w
grid_to_battery_entity: sensor.solar_grid_to_battery_w
battery_extra_entity: sensor.solaredge_battery1_state_of_charge

Configuration of the Power Distribution Card:


type: custom:power-distribution-card
title: ''
entities:
  - decimals: 2
    display_abs: true
    name: solar
    unit_of_display: adaptive
    icon: mdi:solar-power
    producer: true
    entity: sensor.solar_panel_production_w
    preset: solar
  - decimals: 2
    display_abs: true
    name: grid
    unit_of_display: adaptive
    icon: mdi:transmission-tower
    entity: sensor.solaredge_m1_ac_power
    preset: grid
    threshold: ''
    icon_color:
      bigger: ''
      equal: ''
      smaller: ''
    invert_value: true
  - decimals: 2
    display_abs: true
    name: home
    unit_of_display: W
    consumer: true
    icon: mdi:home-assistant
    entity: sensor.solar_house_consumption_w
    preset: home
    threshold: ''
    icon_color:
      bigger: ''
      equal: ''
      smaller: ''
    invert_value: true
  - decimals: 2
    display_abs: true
    name: battery
    unit_of_display: W
    consumer: true
    icon: mdi:battery-outline
    producer: true
    entity: sensor.solaredge_battery1_power
    preset: battery
    threshold: ''
    icon_color:
      bigger: ''
      equal: ''
      smaller: ''
    invert_value: true
center:
  type: bars
  content:
    - preset: autarky
      name: autark
      bar_color: green
      bar_bg_color: ''
      entity: sensor.solar_autarkie_ratio
    - preset: ratio
      name: selbst
      bar_color: blue
      bar_bg_color: ''
      entity: sensor.solar_selfconsumption_ratio
animation: none

Configuration of the Energy Dashboard:

Have fun… Look forward to the feedback on this work.

26 Likes

This post was obsolete and could cause confusion.

1 Like

Hi
Trying to install the integration but it doesn’t get detected even by copying the folder into custom components.

Does it work with non set app inverters too ?
(Like the SE6000H)

I have almost the same setup as you and got both the energy dashboard as the Tesly style card working.
I think 1 thing is missing, you can also charge / discharge the battery to the grid, but I have no idea how to calculate this value. Because in that case, you have 2 variables: battery to grid and the house itself…
Any suggestions ?

I do not charge or discharge the battery to grid, because I have different rates: selling power gives me 0,09€/kWh and buying costs me 0,29€/kWh…

With the template framework it must be possible to calculate the required flows. It is a bit of a puzzle and figuring out in which state you get which value, but with similar things as I did in the template.yaml it must be possible…

I am trying to get this working - but cannot get the modbus integration working. Could anyone confirm if modbus tcp can work over Wifi? Or is it really only exposed on the ethernet port?

I use it over wifi and it works well.

Couple of test points.

Can you ping the IP address of your inverter? Checks network connectivity eth or wifi.

Can you telnet into port 1502 on your inverter?
Checks MODBUS interface is setup.

If both of those tests pass this integration should work for you.

1 Like

We discussed this point last week here:

Perhaps, it can help you.

This post is obsolete, see the first post for latest instructions

1 Like

@Heimel: Maybe, this is what you are searching for?

Frist: Thank you @Remko!

I’m trying to adapt your latest config, but getting Errors and Warning. Am i doing something wrong? Had modified the configuration.yaml and added/importet the sensor.yaml and template.yaml… is there something missing? Do you have any Hints?

thx, sash

Logger: homeassistant.helpers.template
Source: helpers/template.py:1254
First occurred: 23:40:21 (4 occurrences)
Last logged: 23:40:21

Template warning: 'float' got invalid input 'unknown' when rendering template '{% if ((states('sensor.solaredge_m1_ac_power') | float) <= 0) %} {{(states('sensor.solaredge_m1_ac_power') | float*-1)}} {% else %} 0 {% endif %}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2022.1
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:73
Integration: Template (documentation, issues)
First occurred: 23:40:21 (2 occurrences)
Last logged: 23:40:21

TemplateError('ZeroDivisionError: float division by zero') while processing template 'Template("{{(((((states('sensor.solar_house_consumption_daily') | float(0)) - (states('sensor.solar_imported_power_daily') | float(0))) / ((states('sensor.solar_production_daily') | float(0)) + (states('sensor.battery_power_out_kwh_daily') | float(0)))) * 100 ) )| round (0)}}")' for attribute '_attr_native_value' in entity 'sensor.solar_selfconsumption_ratio'
TemplateError('ZeroDivisionError: float division by zero') while processing template 'Template("{{((1 - (states('sensor.solar_imported_power_daily') | float(0) / states('sensor.solar_house_consumption_daily') | float(0))) * 100 ) | round (0)}}")' for attribute '_attr_native_value' in entity 'sensor.solar_autarkie_ratio'
Logger: homeassistant.components.utility_meter.sensor
Source: components/utility_meter/sensor.py:295
Integration: Utility Meter (documentation, issues)
First occurred: 23:40:11 (3 occurrences)
Last logged: 23:40:11

Could not restore state <unknown>. Resetting utility_meter.Solar Production Daily
Could not restore state <unknown>. Resetting utility_meter.Battery Power In kWh Yearly
Could not restore state <unknown>. Resetting utility_meter.Battery Power Out kWh Yearly
Logger: homeassistant.components.integration.sensor
Source: components/integration/sensor.py:132
Integration: integration (documentation, issues)
First occurred: 23:40:11 (3 occurrences)
Last logged: 23:40:11

Could not restore last state: [<class 'decimal.ConversionSyntax'>]
Logger: homeassistant.components.template.config
Source: components/template/config.py:89
Integration: Template (documentation, issues)
First occurred: 23:40:11 (1 occurrences)
Last logged: 23:40:11

The entity definition format under template: differs from the platform configuration format. See https://www.home-assistant.io/integrations/template#configuration-for-trigger-based-template-sensors

Sorry for the late reply. Could you please post the relevant contents of the configuration files? I guess there are some things missing…
Some of the warnings are ok, but the ones about the utility meters are not

Sure @Remko
Sorry for my late Answer. I still having these Issues, here are my configs. If you need - let me know!

configuration.yaml

utility_meter:
  solar_production_daily:
    source: sensor.solar_production_kwh
    name: Solar Production Daily
    cycle: daily
  solar_battery_power_in_kwh_yearly:
    source: sensor.battery_power_in_kwh
    name: Battery Power In kWh Yearly
    cycle: yearly
  solar_battery_power_out_kwh_yearly:
    source: sensor.battery_power_out_kwh
    name: Battery Power Out kWh Yearly
    cycle: yearly
  solar_imported_power_daily:
    source: sensor.solaredge_m1_imported_kwh
    name: Solar Imported Power Daily
    cycle: daily
  solar_exported_power_daily:
    source: sensor.solaredge_m1_exported_kwh
    name: Solar Exported Power Daily
    cycle: daily

sensor.yaml

  - platform: integration
    source: sensor.solar_charge_power_w
    method: left
    unit_prefix: k
    name: battery_power_in_kwh
  - platform: integration
    source: sensor.solar_discharge_power_w
    method: left
    unit_prefix: k
    name: battery_power_out_kwh
  - platform: integration
    source: sensor.solar_production_w
    method: left
    unit_prefix: k
    name: solar_production_kwh

template.yaml

sensor:
  - name: Solar Exported Power Total kWh
    unique_id: solar_exported_power_total_kwh
    state_class: total_increasing
    device_class: energy
    unit_of_measurement: 'kWh'
    state: >
      {% if ((states('sensor.solaredge_m1_exported_kwh') | float(0)) < 100) %}
      {% else %}
        {{(states('sensor.solaredge_m1_exported_kwh') | float(0))}}
      {% endif %}

  - name: Solar Imported Power Total kWh
    unique_id: solar_imported_power_total_kwh
    state_class: total_increasing
    device_class: energy
    unit_of_measurement: 'kWh'
    state: >
      {% if ((states('sensor.solaredge_m1_imported_kwh') | float(0)) < 100) %}
      {% else %}
        {{(states('sensor.solaredge_m1_imported_kwh') | float(0))}}
      {% endif %} 

sensors:
  solar_selfconsumption_ratio:
    friendly_name: Solar Selfconsumption Ratio
    value_template: "{{(((((states('sensor.solar_house_consumption_daily') | float(0)) - (states('sensor.solar_imported_power_daily') | float(0))) / ((states('sensor.solar_production_daily') | float(0)) + (states('sensor.battery_power_out_kwh_daily') | float(0)))) * 100 ) )| round (0)}}"
  solar_autarkie_ratio:
    friendly_name: Solar Autarkie Ratio
    value_template: "{{((1 - (states('sensor.solar_imported_power_daily') | float(0) / states('sensor.solar_house_consumption_daily') | float(0))) * 100 ) | round (0)}}"        

  solar_production_w:
    friendly_name: Solar Production W
    device_class: power
    unit_of_measurement: 'W'
    value_template: >
      {% if ((states('sensor.solaredge_ac_power') | float(0)) + (states('sensor.solaredge_battery1_power') | float(0)) <= 0) %}
        0
      {% else %}
        {{((states('sensor.solaredge_ac_power') | float(0) + states('sensor.solaredge_battery1_power') | float(0)) )}}
      {% endif %}

  solar_production_to_house_w:
    friendly_name: Solar Production To House W
    device_class: power
    unit_of_measurement: 'W'
    value_template: "{{((states('sensor.solar_production_w') | float(0)) - (states('sensor.solar_exported_power_w') | float(0)) - (states('sensor.solar_charge_power_w') | float(0)))}}"  
      
  solar_house_consumption_w:
    friendly_name: Solar House Consumption W
    device_class: power
    unit_of_measurement: 'W'
    value_template: "{{(((states('sensor.solar_production_w') | float(0)) - (states('sensor.solar_exported_power_w') | float(0))) + (states('sensor.solar_discharge_power_w') | float(0)) - (states('sensor.solar_charge_power_w') | float(0)) + (states('sensor.solar_imported_power_w') | float(0)))}}"
      
  solar_imported_power_w:
    friendly_name: Solar Imported Power W
    device_class: power
    unit_of_measurement: 'W'
    value_template: >
      {% if ((states('sensor.solaredge_m1_ac_power') | float) <= 0) %}
        {{(states('sensor.solaredge_m1_ac_power') | float*-1)}}
      {% else %}
        0
      {% endif %}
      
  solar_exported_power_w:
    friendly_name: Solar Exported Power W
    device_class: power
    unit_of_measurement: 'W'
    value_template: >
      {% if ((states('sensor.solaredge_m1_ac_power') | float(0)) > 0) %}
        {{(states('sensor.solaredge_m1_ac_power') | float(0))}}
      {% else %}
        0
      {% endif %}

  solar_charge_power_w:
    friendly_name: Solar Charge Power W
    device_class: power
    unit_of_measurement: 'W'
    value_template: >
      {% if ((states('sensor.solaredge_battery1_power') | float(0)) > 0) %}
        {{(states('sensor.solaredge_battery1_power') | float(0))}}
      {% else %}
        0
      {% endif %}
      
  solar_discharge_power_w:
    friendly_name: Solar Discharge Power W
    device_class: power
    unit_of_measurement: 'W'
    value_template: >
      {% if ((states('sensor.solaredge_battery1_power') | float(0)) < 0) %}
        {{(states('sensor.solaredge_battery1_power') | float(0)*-1)}}
      {% else %}
        0
      {% endif %}
    
  solar_production_lifetime_mwh:
    friendly_name: Solar Lifetime Production
    device_class: energy  
    unit_of_measurement: 'MWh'
    icon_template: mdi:solar-power
    value_template: "{{ ((states('sensor.solaredge_ac_energy_kwh') | float(0)) / 1000) | round (2) }}"

Energy Dashboard Config

I hope, that my answer helps to find the issues :slight_smile:

Just to add that I have the same problems as @s_ash … I’d actually set aside some time today to post my config as per @Remko 's request but then saw that @s_ash beat me to it by about sixty minutes :slight_smile:

Please let me know if I can help with testing / debugging. Confirmed that my setup is the same as above.

2 Likes

I have also the same hardware setup, same configuration and the same problem :upside_down_face:
If i can be of any help for testing or debugging, i’m happy to help!

I did make some minor changes to my config, do get a few warnings and every now and then some errors when it loses connection, but that is ok. The connection automatically restores and the overall data is coming through and I get everything displayed the way it should be. I’ll go through this over the next couple of days and post the correct config.
I’ll need a few days, but will get back to this.

4 Likes

Thank you for all the effort, much appreciated :slight_smile: !

I have just read through this and I have two questions.

do I need to have the SolarEdge API installed first, with will then give me the sensors links within HA.
and my second question, as I have a GivEnergy Battery then will this also work this this, as long as I have the right API for GivEnergy ?

This post is obsolete, see the first post for latest instructions

3 Likes

Thank you! First: most is working - i think.

First quation: Where did you define “sensor.solar_production_kwh” - you are using it in the Energy Dashboard. In your config files i couldn’t find the definition. Perhaps you could give me a Hint! :slight_smile:

Will give an more detailed Feedback after experiencing some more.