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

I’ve found another hint in the graph of the solar power production. During the time of charging the solar power went up to exactly 1 KW/h.

Yes, looking at it the templates…“Grid To Battery” is not considered. That requires some changing of formulas and if then else statements. A bit of a puzzle, which I need to find a quiet hour for. It can all be figured out based on the solaredge_m1_ac_power and solardege_ac_power sensors, but I need to figure it out.

If you like…have a go at it…see which one of us figures it out first…:wink:

Actually…since I don’t have any records of these effects on my side, could you post the history graphs of these sensors:

  • solaredge_m1_ac_power
  • solardege_ac_power
  • solaredge_battery1_power

I should be able to figure it out…I hope…

Of course, no problem. Here they come:

I will also look into this. Maybe in the evening.

I thought a bit about the diagrams.
Please correct me if I’m wrong, but this is what I think:

solaredge_m1_ac_power is the overall power. If it is positive, then power is exportet to the grid. If it is negative, power is imported from the grid. From this graph we can’t know where the power comes from.

solaredge_ac_power: is the power of the soler panels. I think it also includes power from the battery, but I’m not entirely sure.

solaredge_batter1_power is positive if the battery is charging and negative if it is discharging

If this right so far?

Correct, to repeat it and add some information:
solaredge_m1_ac_power is the overall power. If it is positive, then power is exportet to the grid. If it is negative, power is imported from the grid. From this graph we can’t know where the power comes from
Correct: this is the value from the clamp meter in your circuit breaker cabinet.

solaredge_batter1_power is positive if the battery is charging and negative if it is discharging
Correct…

solaredge_ac_power: is the power of the soler panels. I think it also includes power from the battery, but I’m not entirely sure.
Correct but…as you stated it includes the battery. So when the battery is charging the amount of power going into the battery is actually substracted from the actual solar production. When the battery is discharging, the discharge power is seen as positive in this sensor. That is what makes it a bit complicated. Here I used different formulas to calculate the actual power coming from my panels.

So…we need some more “if then else” statements to cope with the charging of the battery from the grid. So basically, if solaredge_m1_ac_power is negative and solaredge_battery1_power is positive, it is charging from the grid.

I think I actually need to start making an Excel table to list all the posibilities and the corresponding sensors.

The final detail I have in my current formulas: It happens every now and then that the modbus connection drops for a few seconds, when this happens, the values drop to 0. If I don’t deal with that in the formulas, the energy dashboard starts showing real strange values. But that is the last thing to add. First point is get all the different scenarios listed.

As a start:
Solar Panels produce power:

  • Battery is charging
  • House is consuming
  • Power is exported to grid

Solar Panels produce power:

  • Battery is full
  • House is consuming
  • Power is exported to grid

Solar Panel produce power:

  • Battery is empty
  • House is consuming
  • Power is imported from the grid

Solar Panels produce power:

  • Battery is discharging
  • House is consuming
  • No grid power

Solar Panels produce power:

  • Battery is discharging
  • House is consuming
  • Power is imported from grid

Solar Panels Do Not produce power:

  • Battery is discharging
  • House is consuming
  • Power is imported

Solar Panels Do Not produce power:

  • Battery is empty
  • House is consuming
  • Power is imported

Solar Panels Do Not produce power (this I do not have currently:

  • Battery is charging
  • House is consuming
  • Power is imported

Now it is a matter of adding the right sensors to these scenarios… Or maybe there are still more scenarios I forgot…

In all these scenarios we basically need to calculate:

  • solar to house
  • solar to battery
  • solar to grid
  • battery to house
  • grid to house
  • grid to battery

All based on the 3 inputs:

  • ac power
  • m1 ac power
  • battery power

Maybe I can find some time tomorrow to figure it out, or maybe I am thinking too complicated…

1 Like

Good morning,
it´s me again.
i still get my solaredge integration not working.
several times i install and uninstall the solaredge modbus integration but all sensors are unknown.

i could cry.
how can i try that my modbus is working?

maybe it help to know my komponents.
solarEdge Inverter 10,0kW
3-phasig SE10K-RWS48BEN4

SolarEdge Energy Meter
Modbus Energi SE-MTR-3Y-400V-A

LG Energy RESU-Speicher
(Batterie) RESU10

oh man sometimes i think i´m to dumb for Homeassistent.
the decision to do mechanical engineering and not electrical engineering was probably the right one back then. :slight_smile:

Have you tried testing the TCP Modbus connection as described in the corresponding thread. Maybe the Modbus connection on your inverter is not activated, you would need the SetApp application with the installer login to enable that…

@Jeremia

I think I have the “Battery to Grid” issue figured out. I have changed my templates.yaml to deal with that (I think and hope), so this would be the correct one now:

sensors:
 #==============================
 #=== Solar Custom Card
 #==============================
  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
      {% elif ((states('sensor.solar_grid_to_battery_w') | 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) - (states('sensor.solar_grid_to_battery_w') | float(0)))}}"

  solar_grid_to_battery_w:
    friendly_name: Solar Grid To Battery W
    device_class: power
    unit_of_measurement: 'W'
    value_template: >
      {% if ((states('sensor.solaredge_ac_power') | float) <= 0) and ((states('sensor.solaredge_battery1_power') | float(0)) > 0) %}
        {{(states('sensor.solaredge_battery1_power') | float(0))}}
      {% else %}
        0
      {% endif %}
      
  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) }}"

I changed the “solar_production_w” and “house_consumption” sensors and added the “grid_to_battery”.

I have also update the config of the “Tesla Style Power Card” to include that:

type: custom:tesla-style-solar-power-card
name: Home Energy Flow
grid_to_house_entity: sensor.solar_imported_power_w
generation_to_grid_entity: sensor.solar_exported_power_w
generation_to_battery_entity: sensor.solar_charge_power_w
generation_to_house_entity: sensor.solar_production_to_house_w
battery_to_house_entity: sensor.solar_discharge_power_w
battery_extra_entity: sensor.solaredge_battery1_state_of_charge
grid_to_battery_entity: sensor.solar_grid_to_battery_w

It seems to look good, but time will tell I guess.

1 Like

OK that’s awesome. I’ve just added the config. Let’s see how it behaves. Maybe I have another interesting behavior, but we’ll see.

Statistics looking good for me so far… The small difference maybe because the energy dashboards only updates each hour.

The difference in production is what I expect because of the effect from the battery. Basically the energy dashboard shows me the real production, solaredge minus what was charged too the battery.


I think you have the same thing, which I don’t understand right now. Solaredge app shows 7.08 kw/h solar power for today, but the energy dashboard shows 11.3 kw/h. Do you know where the big difference comes from? Of course the energy dashboard is behind, but this looks like it is some ours in the future.

Yes, the difference is simply explained and the entire reason I set this up this way: When the battery is charging, the power going into the battery is not calculated as production according to solaredge. So let’s assume following:
You start the day with an empty battery and the sun start shining. At that moment, only the power you consume directly is counted as “production power”. The power going into the battery is not counted by solaredge. When the sun goes down and you do not produce anything, BUT you start using the power from your battery, solar edge counts this as production power. So in the evening, when the sun isn’t shining, you still see your “production” going up.
I do not like that effect, I want to understand how much my panels produce during the day, no matter what the power is used for. That is what I did with all the formulas.
So in the Energy Dashboard you will not see the Production Power increasing anymore when there is no sun. You do see how much energy is used from the battery then.
So basically, if at the end of the day, your battery is empty again, the production power between solaredge and the energy daashboard should be roughly the same again. However, if there is still energy left in the battery after midnight, it will start counting this as production the next day.

Again, I do not like that, I want to see the actual production for a single day, not depending on the battery and want to look at the battery seperately.

Does that make it clear why you see the differences?

Actually in my screenshots: 7 kW went into the battery, 2 kW was used, so netto I have about 5kW in the battery left. If I add that to the 7 kW Production according to SolarEdge, I get very close to the 11,5 kW Production according to the Energy Dashboard. The small difference is caused by the time I took the screenshots and how often the 2 systems actually update.

Ok, I think I got it and it does make sense what you’re describing. So at the end of the day (if the battery is discharged) solaredge monitoring and energy dashboard should almost match.
Unfortunately this is not the case for me.

My battery is discharged some ours ago. So the production is not changing for quite a while.
Solaredge monitoring is at 7,64 kw/h production for today.

And this is, what I did get from the Energy Dashboard.

image

We have a gap of around 0.6 kw/h. Or is this what you called a “small difference”. I think this can’t be updates of the different systems, because both of them are not changing anymore for some hours. If this is the usual difference, I think it is fine. If this would grow with higher production, I’ll check again if there is something to improve.

Thank you once again for changing the formulas. The daily from grid charging thing seems to be right now:

image

image

Also the energy flow looks perfectly right.

image

We have 8.6 kw/h from the grid. 8.5 kw/h was consumed by the house and 0.1 kw/h from the stupid battery. I’m looking forward how the daily production does look now.

Well that’s weird. Daily energy flow was fine before solar production started (see last post). Now after solar production started, it looks again like the battery is charged from solar power.

image

The 0.1 kw/h which did flow before from grid to battery are now from solar power to battery.

Yes, I wrote the author, I am actually now using a fork from the original tesla style card, which displays the lines ofsetted as in the Energy Dashboard.

But…happy that the “Grid to Battery” is now working correctly.

Now when it comes to Solar Production…yes, I also see the differences between SolarEdge and Energy Dashboard as you mentioned and this has been keeping me up last night…:wink:

I have been looking at the data, used to calculate the production, it is basically only calculated form “solaredge_ac_power” and “solaredge_battery1_power”. This is how it looks for me from yesterday:
1

Overall you can see that it is correct…once the battery is discharging (negative orange), the ac power goes up (blue)
4

When it is charging, it is the other way around, so basically Solar Production is always ac_power + battery1_power. This makes sure the production is calculated correctly.

Now why is there a difference between SolarEdge and the Energy Dashboard…I actually do not know. What I do see, if I start to look real close is this:
3

At this moment ac_power is 0 and battery power is still positive (discharging). So at this point of time taking ac_power+battery_power= ~1kW

This is strange because this would mean my house isn’t consuming anything, which is not correct. And the output from the battery So what I am assuming happens here, is that the modbus gives a wrong value causing the overall differences.

Now the question is…what causes this? I do see some “error connecting modbus” messages in the log every now and then, so I think that is the culprit. When this happens, the values jump to 0 briefly and this could cause discrepancies. The other question is what the effect is of only grabbing the values every 5 seconds (in my case, because that is how I set it up)… Do these effects add up to the differences, or…what is actually correct. How does SolarEdge calculate the values…do they store the data instantly on change and take the sum every 15 minutes to update the monitoring platform…? I really do not know.

I am pretty convinced the formulas I use now are correct, again…this graph and the formulas ran through mind last night and I cannot find a mistake there. So I think I cannot change much about it, maybe even shortening the modbus polling to 1 second would make it more accurate, but this of course come with a bigger strain on the database, so the question is what is better. Maybe I will change it and make sure not everything gets stored in the database, only the relevant sensors by excluding the rest, but I would need to try it out.

Another thing to consider is that I actually did see over a longer period of time, that the SolarEdge Monitoring also is not exact, I did see a difference between those values and the values on my actual meters, when I look at it over a year.

The change when it starts producing is correct: Once you produce power, your battery will be charged from that and not from the grid anymore.

Don’t forget that the bubbles you see flowing are based on the cumulative values over the day. When we are seeing the 0,1 kW/h (rounded) values, it is such small values, that just the tiniest bit of production is already more as what you charged from the grid. So therefore the bubble will start flowing from production to battery. I wouldn’t worry about that.

I found more evidence… I am now convinced the calculations are correct, but the values coming from the modbus sometimes have small errors. So this is coming directly from the inverter.

In this picture you can see that the battery is charging, so theoretically that would be production. However when there is production from the panels we always use it for consumption first, however in this picture ac_power is 0…which is a case which cannot be. My house always consumes something, so when there is sun, ac_power cannot be 0 and the battery did not charge from the grid at that point.

So…maybe I will create an issue with the author of the integration, but I think this is just something we cannot control. The Monitoring Platform probably deals with this internally, which is why you don’t see that effect there.

Anyhow…I will continue to look into this to get to the bottom of it.

I am using your template sensors, many thanks for that.

I also see some discrepancies in the data, when the battery is charging from AC + PV.
The sensor says 0 solar power but that is incorrect.