Solaredge Modbus Configuration for Single Inverter and Battery

I did that at the very beginning, but Home Assistant said there was an error in the configuration. So I couldn’t restart. Something with the meters…

Will check later and tell you the exact error message.

Yes, please do, because that is the exact config I am using now. Off you encounter an error I want to understand that.

Maybe… Just maybe it has something to do with some of the long term statistics Homeassistant saves. It may help cleaning those as well. And…make sure you don’t have anything entities left after deleting the initial integration. Clean up before reconfigure…

Any errors after that… Let me know and we’ll figure it out

It works now. I had to remove everything from the official HA-Energy dashboard.

What do I need to adjust? And where do I do that? Tariffs? What else?

I’d think tariffs is the only thing to change…

1 Like

One more question:

How can I rename
“Solar Battery Out Yearly” and “Solar Battery In Yearly”

I tried by simply changing the name in energy_utilities.yaml - but it didn’t work.

# Electricity Battery
  solar_battery_from_grid_yearly:
    source: sensor.solar_grid_to_battery_kwh
    name: Solar Battery Imported Yearly
    cycle: yearly
  solar_battery_from_panels_yearly:
    source: sensor.solar_panel_to_battery_kwh
    name: Solar Battery Generated 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

I discovered two mistakes in the energy_stats.yaml

  - sensor:
    - name: "Solar Selfconsumption Ratio"
      unique_id: solar_selfconsumption_ratio
      icon: mdi:percent-outline
      state: >
        {% set panel_to_house_daily = states('sensor.solar_panel_to_house_daily') | float(0) %}
        {% set battery_in_daily = states('sensor.solar_battery_in_daily') | float(0) %}
        {% set exported_power_daiy = states('sensor.solar_exported_power_daiy') | float(0) %}

        {% if (panel_to_house_daily + battery_in_daily + exported_power_daiy <= 0) %}
          0
        {% else %}
          {{ ((panel_to_house_daily + battery_in_daily) / (panel_to_house_daily + battery_in_daily + exported_power_daiy) * 100) | round (1) }}
        {% endif %}

    - name: "Solar Autarkie Ratio"
      unique_id: solar_autarkie_ratio
      icon: mdi:percent-outline
      state: >
        {% set house_consumption_daily = states('sensor.solar_house_consumption_daily') | float(0) %}
        {% set imported_power_daily = states('sensor.solar_imported_power_daily') | float(0) %}

        {% if (house_consumption_daily <= 0) %}
          0
        {% else %}
          {{ (1 - (imported_power_daily / house_consumption_daily) * 100) | round (1) }}
        {% endif %}

At the Solar Selfconsumption Ratio you just need to correct all three “daiy” to “daily” (3x the l is missing).
At the Solar Autarkie Ratio you need to insert brackets (Klammern?):

Before:
{{ (1 - (imported_power_daily / house_consumption_daily) * 100) | round (1) }}

After:
{{ ((1 - (imported_power_daily / house_consumption_daily)) * 100) | round (1) }}

Then both sensors work as they should.

That is how I would rename them. Did you reload the config in Dev tools?

If that doesn’t work you can edit any entity friendly name directly.

I just used the template sensors from here: Template Sensors for Power and Energy · WillCodeForCats/solaredge-modbus-multi Wiki · GitHub

Works perfectly with the Energy dashboard and “power-flow-card-plus” card.

Really nice configuration which works really well with SE modbus. However, I have the same issue mentioned a few times above, which I can’t see a response to. I’m using the latest repo on GH…

Dashboard will remain blank unless ‘edit dashboard’ - ‘raw configuration editor’ are selected and the editor is closed. Any suggestions as to why this occurs?

I’ve discovered a ‘bug’ in the battery_to_house power flow.

I started exporting from our battery to the grid during the Octopus Flux Peak Export time and initially, the power flow seemed to be all over the place. Then I realised that the battery_to_house figure doesn’t account for exporting from the battery to the grid. Here’s what it looks like on both power flow cards when exporting from the battery:

We have a 4kW inverter and as you can see, the top power flow shows the correct output from the battery, but shows the house consumption as too high by the same amount as the battery output. The lower power flow shows the same size flow from battery_to_grid as battery_to_house, hence the battery output figure appearing to be double what it actually is.

I have a fix that compensates for this, which considers that the only time there should be flow from battery to grid is when directly exporting from battery to grid. This can be done at any time, but the main consideration is that any time there is sufficient solar, then there should be zero flow from battery to house.

Anyway, here’s my fix. I’m sure someone will come up with a more eloquent solution :grin:

{% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float(0) %} 
{% set battery_effectiveness = states('sensor.solar_battery_effectiveness') | float(0) %} 
{% set inverter_effectiveness = states('sensor.solar_inverter_effectiveness') | float(0) %} 
{% set panel_production_w = states('sensor.solar_panel_production_w') | float(0) %} 
{% set house_consumption_w = states('sensor.solar_house_consumption_w') | float (0) %}
{% set battery_to_grid_w = states('sensor.solar_battery_to_grid_w') | float (0) %}
  
{% if battery_to_grid_w >= 0 and panel_production_w > house_consumption_w %}
  0
{% elif b1_dc_power < 0 %} 
  {{ (b1_dc_power * -1 * battery_effectiveness * inverter_effectiveness) }}
{% else %}
    0
{% endif %}

@ryanm101 just in case you missed my comment in your repo (I’m Daverover66 on Github), the change above is to the battery_to_house flow, not to the battery_to_grid flow :grimacing:

I was also looking at the battery stats code you created for time to full and time to empty. Do you have a way of dealing with the division by zero error when the battery is full, or indeed empty for time to empty

UPDATE!

Right, now I’m starting to doubt myself. I implemented the above change into the battery_to_house section and this is the result when the battery started discharging:

Solaredge app showing this:

Maybe I’ll just leave the coding to people who know what they’re doing :roll_eyes::confused:

Sorry for the long post, but I’m like a :dog2: with a :bone: so I’ve been having another play today.

This is my power flow with 1.9kW of generation and power flowing to the house to meet demand with the remainder charging the battery.

Now, if I switch to maximise export by discharging the battery to the grid, this happens

At the grid: -3.95kW is correct
At the battery: -1.68kW is about correct, perhaps a touch low when compared to the SE app
At the panels: 4.5kW is too high
At the house: 2.2kW is too high

In terms of flows, I think:

battery_to_grid :heavy_check_mark:
battery_to_house :heavy_check_mark:
panel_to_grid :x:
panel_to_house :x:

Which is making house_consumption_w and panel_production_w wrong.

Working my way anti-clockwise around the flow diagram, having sorted battery_to_grid and battery_to_house , next to sort is panel_to_house . I think my biggest problem is that I have a 2 inverter system configured as a master and slave affair. So in my panel_to_house section, I’ve added both inverter outputs and created an i_total_dc_power and an i_total_ac_power . The battery is connected to inverter #1, so when charging and discharging the battery only has an effect on inverter #1. I need help figuring out how to differentiate between when to use i_total_dc_power and i1_dc_power . This is my yaml for the panel_to_house . Excuse the extra symbols. When I’m trying to figure out what’s going on I drop the relevant section of yaml into the template editor and mark each section with a different symbol so I know which result is being displayed. My area of concern is the bottom section marked with a £ sign as this is where the result ends up when the battery is discharging, either to the house or to the grid.

{% set i1_dc_power = states('sensor.solaredge_i1_dc_power') | float (0)%} 
{% set i2_dc_power = states('sensor.solaredge_i2_dc_power') | float (0)%} 
{% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float (0)%} 
{% set i_total_dc_power = i1_dc_power + i2_dc_power %}
{% set i1_ac_power = states('sensor.solaredge_i1_ac_power') | float (0)%} 
{% set i2_ac_power = states('sensor.solaredge_i2_ac_power') | float (0)%} 
{% set i_total_ac_power = i1_ac_power + i2_ac_power %}
{% set m1_ac_power = states('sensor.solaredge_m1_ac_power') | float(0) %} 
{% set inverter_effectiveness = states('sensor.solar_inverter_effectiveness) | float(0) %} 

{% if (b1_dc_power >= 0 and m1_ac_power > 0) %} 
  {% if (i_total_dc_power < 0 and i_total_ac_power <= 0) %} 
    {{ (i_total_dc_power - m1_ac_power) }} 
  {% else %} 
    {{ (i_total_ac_power - m1_ac_power) }} 
  {% endif %} 
{% elif (b1_dc_power >= 0 and m1_ac_power <= 0) %} 
  {% if (i_total_dc_power < 0 and i_total_ac_power  <= 0) %} 
    {{ i_total_dc_power }} 
  {% else %} 
    {{ i_total_ac_power }} 
  {% endif %} 
{% elif (b1_dc_power < 0) %} 
  {% if (i_total_dc_power + b1_dc_power < 0) %} 
    0
  {% else %} 
    {{ (i_total_dc_power + b1_dc_power * inverter_effectiveness) }} £
  {% endif %}    
{% else %} 
  0 
{% endif %}     

So that last

{{ (i_total_dc_power + b1_dc_power * inverter_effectiveness) }}

is the bit that is wrong. What I can’t figure is do I either need to adjust this to make it correct, or do I need another section to determine what to do when the battery is discharging to the grid, and if it’s the latter, how to I maintain the right figure when the battery is discharging to the house only.

If anyone has the time or inclination to have a good look at this I’d be grateful.

In my case there is house consumption, this is a given as i’ll never have 0.
There is then sources:
Panel->house
Battery->house
Grid->house.

If i’m exporting then Grid->house MUST be 0.
So the question then becomes where am i exporting from…
Well we can track our panel production.
So panel prod - house consumption = panel export.
if panel export is 0 or neg then 100% export is battery else battery export is total export - panel export

I was wary of using house_consumption_w in the panel_to_house section because panel_to_house is part of the calculation for house_consumption_w so wanted to avoid creating a circular argument.

Not necessarily. When the battery is charging, then not all excess panel production is export, so would need to also factor in the polarity and value of b1_dc_power.

This little section of code works for panel_to_house when exporting from the battery. I figured using the inverter storage mode was an easy way to determine if the battery was discharging:

{% if i_total_dc_power + b1_dc_power < 0 %} 
{% elif b1_dc_power < 0 and storage_mode == "Discharge to Maximize Export" %} 
  {{ ((i_total_ac_power ) - exported_power_w)}} £
{% else %}
  {{ (i_total_ac_power + b1_dc_power * inverter_effectiveness) }} %
{% endif %}    

I’m just trying to figure out how to incorporate it into the relevant part of the panel_to_house section. Thought I had it, but when panel_production_w dropped to zero last night my amended panel_to_house started increasing negatively ie flowing in the wrong direction :roll_eyes:, so I need to read up a bit more on nested if/elif/else statements to figure out the logical path to zero when there is no panel production.

Do the opposite. Start with 0 as the default output and then use if to override it.

1 Like

Blockquote
DAVSDavid Shaw

21d

Really nice configuration which works really well with SE modbus. However, I have the same issue mentioned a few times above, which I can’t see a response to. I’m using the latest repo on GH…

Dashboard will remain blank unless ‘edit dashboard’ - ‘raw configuration editor’ are selected and the editor is closed. Any suggestions as to why this occurs?

Blockquote

Bump, to see if this can be solved…

Many thanks for the great integration

I have two SE inverters - SE5000H and SE5000 plus a StorEdge with an LG battery connected to the 5000.

I want to be able to charge from grid. I can change the setting in HA for the SE5000 but keeps on immediately resetting itself to Maximise Self Consumption. Have tried changing which unit is Master /Slave, disconnecting from monitoring, plus pretty much every other setting I can think of but still stubbornly does same thing.

Everything else working ok and can see on panel the battery starting to charge so seems to be something at the inverter.

Any ideas as to how I can fix ?

Many thanks in advance for any ideas / suggestions.

Have you set the Storage Control Mode to Remote Control? These are my storage settings, ignore the Storage Command Mode as I’m currently discharging to the grid. That would usually be MSC.

After reading your post, I also switched to Remote Control for the first time and played with the options it provides. REALLY cool!

However - since yesterday (when I first activated it), my SolarEdge App doesn’t show any “self consumption” anymore in the statistical data. Is this normal? I probably can’t get this back, right?

Thank you in advance!

I see the same thing since 2 days. I did already change the option earlier though, so I think it is actually something wrong on solar edge side…

1 Like