Solaredge Modbus Configuration for Single Inverter and Battery

It seems like you didn’t install this or didn’t reload/clear browser cache:

The conversion to GBP should not be an issue normally.

Hi, how did you add the additional panels above and below house consumption?

Inked4f3d1d71d040052c277ed1d22fc93907a0726a18

Hi,

I’ve added this in the Card Config:

appliance1_consumption_entity: sensor.heath_pump_power
appliance2_consumption_entity: sensor.alfen_real_power_sum
appliance2_extra_entity: sensor.car_battery_level
appliance1_icon: mdi:heat-pump-outline
appliance2_icon: mdi:car-sports

It’s in the docs of the Tesla Style Solar Power Card: GitHub - reptilex/tesla-style-solar-power-card: Home assistant power card mimicking the one tesla provides for the powerwall app.

Tim

2 Likes

Thank you so much, I missed that! :v:

I tried looking through this thread but haven’t seen anything regarding my question, so I’ll try… :slight_smile:

Does anyone have a setup of two intervers (one master, connected to the network via ethernet), one slave inverter connected via RS485 to the master, one modbus meter connected and one battery (BYD LVS) connected to the master inverter.

Unfortunately, I haven’t been able to use the home-assistant-solaredge-modbus integration, as it expects the secondary inverter to have modbus id 2…

In my case (and if I remember correctly that’s the recommended setup. might be wrong though) my master inverter has modbus id 1, the slave has modbus id 3. I think the modbus meter has modbus id 2.

If at all possible I don’t want to change the modbus ids of the SolarEdge installation, because I’m afraid of messing up the system and it not being able to properly communicate and send data to SolarEdge :slight_smile:

I do use modbus-proxy in HA, and both openWB and evcc (both electric vehicle software that i can use to control my ev charger) are able to connect to the system and they don’t have a problem with my modbus id setup.

Does anyone have a usable solution? Can I set up the home-assistant-solaredge-modbus multiple times to the same inverter? Will the sensor names be usable by the scripts/configurations/templates provided in this thread or will I have to work through all of them, because I will have the “same” sensors twice (once for the first inverter, once for the second inverter)?

Thank you in advance!

Edit: I tried adding the integration twice, both times with the IP of the master inverter, first time with modbus ID 1, second time with modbus ID 3, but it won’t let me, as it’s the same IP address. So I’m not sure what to do.

Ok, I was impatient, and I think I was able to successfully change the modbus id of my slave inverter from 3 to 2 without damaging anything :slight_smile: Now I’ll have to try and change the plattform code to support two inverters. Haven’t found a version with two inverters and a battery in this thread yet.

I was able to successfully change the code to support my two inverters with battery.

I am still fairly new to Home Assistant and have a problem with the statistics for the sensors created with the code from this thread. Somehow they don’t get stored correctly.

I’m trying to create a graph for sensor.solar_house_consumption_w and solar_panel_production_w and others, but somehow they don’t get updated in the statistis view and they seem to never get updated anymore. I have no idea why that is.

I added device_class: power to the sensors, like this:

      - name: "Solar House Consumption W"
        unique_id: solar_house_consumption_w
        unit_of_measurement: "W"
        device_class: power
        icon: mdi:home
        state: >
          {% set panel_to_house_w = states('sensor.solar_panel_to_house_w') | float(0) %}
          {% set battery_to_house_w = states('sensor.solar_battery_to_house_w') | float(0) %}
          {% set grid_to_house_w = states('sensor.solar_grid_to_house_w') | float(0) %}

          {{ (panel_to_house_w + battery_to_house_w + grid_to_house_w) }}

but the sensor data doesn’t get stored.

image

It seems to have worked last night for a short period, but not afterwards. It’s the same for the production sensor.

I reloaded the yamls, restarted HA… I can shortly see a change in the graph, but right away it goes back to that value that it had all night (~900 watts).

What am I doing wrong? :frowning:

Edit:

Me again. I think I found the issue. The package code from above contains a section

recorder:
  include:
    entities:

So far, my HA seems to have been storing history for all of my entities, I don’t have a section to “include entities” anywhere in my configuration, so I believe that when I added the package code for SolarEdge, only those entities listed there got history data stored in the database and everything else was ignored.

I removed that recorder section and now I think everything is back to normal…

Correct. I do not include everything in recording, because it is an enourmous amount of data with a 3 second update interval.

Interesting to read your post. We have a setup similar to yours in that we have 2 inverters and 1 battery.

I’d also noticed the flow seems to go wild when charging the battery from the grid so I’ll try your revised code for that.

The other thing I noticed was that when charging the battery from solar only, the flow would often change from ‘Panel to Battery’ to ‘Grid to Battery’. Took me a while to figure out what was going on but I noticed that i1_dc_power was going negative due to the additional power coming from i2_dc_power. Your solution to that seems a touch more eloquent than mine, but essentially all I did was look out for i1_dc_power going negative, and if it did, multiply it by -1 to make it positive again. That works for us.

This is my code for the relevant flow:

- name: "Solar Grid To Battery W"
        unique_id: solar_grid_to_battery_w
        unit_of_measurement: "W"
        icon: mdi:battery-positive
        state: >
          {% set i1_ac_power = states('sensor.solaredge_i1_ac_power') | float(0) %}
          {% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float(0) %}

          {% if i1_ac_power < 0 %}
            {% set i1_ac_power = (i1_ac_power * -1) %}
            {% else %}  
              {% set i1_ac_power = (states('sensor.solaredge_i1_ac_power') | float(0)) %}
              {% endif %}  
              {% if (i1_ac_power <= 0 and b1_dc_power > 0 ) %}
                {{ b1_dc_power }}
                {% else %}
                  0
                  {% endif %}

I will, however, try yours and see if that works for my system.

Thanks for sharing.

I have a similar or maybe even the same issue. I also have two inverters and a battery. When the battery is being charged, the ‘Solar Panel To House W’ calculation that I adapted for two inverters seems to give a too high value, therefore making the house consumption in the card higher than it actually is and also in the card the solar production is higher than it actually is.

I tried “fixing” that by changing the code from

      - name: "Solar Panel To House W"
        unique_id: solar_panel_to_house_w
        unit_of_measurement: "W"
        icon: mdi:solar-power
        state: >
          {% 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 i1_ac_power = states('sensor.solaredge_i1_ac_power') | float(0) %}
          {% set i2_ac_power = states('sensor.solaredge_i2_ac_power') | float(0) %}
		  {% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float(0) %}
          {% 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 ((i1_dc_power + i2_dc_power) < 0 and (i1_ac_power + i2_ac_power) <= 0) %}
              {{ ((i1_dc_power + i2_dc_power) - m1_ac_power) }}
            {% else %}
              {{ ((i1_ac_power + i2_ac_power) - m1_ac_power) }}
            {% endif %}
          {% elif (b1_dc_power >= 0 and m1_ac_power <= 0) %}
            {% if ((i1_dc_power + i2_dc_power) < 0 and (i1_ac_power + i2_ac_power) <= 0) %}
              {{ (i1_dc_power + i2_dc_power) }}
            {% else %}
              {{ (i1_ac_power + i2_ac_power) }}
            {% endif %}
          {% elif (b1_dc_power < 0) %}
            {% if ((i1_dc_power + i2_dc_power) + b1_dc_power < 0) %}
              0
            {% else %}
              {{ (((i1_dc_power + i2_dc_power) + b1_dc_power) * inverter_effectiveness) }}
            {% endif %}   
          {% else %}
            0
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_i1_dc_power') | is_number and states('sensor.solaredge_i2_dc_power') | is_number and states('sensor.solaredge_i1_ac_power') | is_number and states('sensor.solaredge_i2_ac_power') | is_number and states('sensor.solaredge_b1_dc_power') | is_number and states('sensor.solaredge_m1_ac_power') | is_number }}

to this:

     - name: "Solar Panel To House W"
        unique_id: solar_panel_to_house_w
        unit_of_measurement: "W"
        state_class: measurement
        device_class: power
        icon: mdi:solar-power
        state: >
          {% 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 i1_ac_power = states('sensor.solaredge_i1_ac_power') | float(0) %}
          {% set i2_ac_power = states('sensor.solaredge_i2_ac_power') | float(0) %}
          {% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float(0) %}

          {% 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) %}
            {{ ((i1_dc_power + i2_dc_power) - m1_ac_power) }}
          {% elif (b1_dc_power >= 0 and m1_ac_power <= 0) %}
            {{ (i1_dc_power + i2_dc_power) }}
          {% elif (b1_dc_power < 0) %}
            {% if ((i1_dc_power + i2_dc_power) + b1_dc_power < 0) %}
              0
            {% else %}
              {{ (((i1_dc_power + i2_dc_power) + b1_dc_power) * inverter_effectiveness) }}
            {% endif %}   
          {% else %}
            0
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_i1_dc_power') | is_number and states('sensor.solaredge_i2_dc_power') | is_number and states('sensor.solaredge_i1_ac_power') | is_number and states('sensor.solaredge_i2_ac_power') | is_number and states('sensor.solaredge_b1_dc_power') | is_number and states('sensor.solaredge_m1_ac_power') | is_number }}

So basically I always just add up the dc power values, which seems to produce more realistic values when the battery is being charged (very close if not identical to what SolarEdge displays in its portal). I fear that it’s not a correct/complete fix though. as this morning I did see that I was seeing negative values in the card from the solar side.

So I might have to make the ac values positive again as well? Not sure…

Edit:

Just looking at the original code for ‘Solar Panel To House W’, it might be that it’s wrong from my end to just sum up the two values in

{% if ((i1_dc_power + i2_dc_power) < 0 and (i1_ac_power + i2_ac_power) <= 0) %}

Does anyhow have a correct calculation for two inverters (connected my RS485), one of them hybrid, with a battery connected?

So, having figured most of this out and getting it to work just about right for our setup here, there are still a couple of niggles I’d like to sort out.

  1. Battery Efficiency - I’ve actually changed the name of this to Battery Efficiency as I feel that’s a better description of what the bar is trying to show. I’m happy to be corrected if someone cares to explain why it is effectiveness and not efficiency. Anyway, my issue is that this figure often drops to quite low values and as a consequence, because solar_battery_to_house uses battery_effectiveness, when this figure is very low, the flow to the house from the battery is wrong. Has anyone else experienced this? I can’t actually figure out where the entity solar_battery_effectiveness is calculated. It just seems to appear. Here’s the code from my energy.yaml
- name: "Solar Battery Efficiency"
  unique_id: solar_battery_efficiency
  icon: mdi:percent-outline
  unit_of_measurement: "%"
  state: >
    {% set i1_dc_power = states('sensor.solaredge_i1_dc_power') | float(0) %}
    {% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float(0) %}
    {% set battery_efficiency = states('sensor.solar_battery_efficiency') %}
    {% if (is_state('sensor.solar_battery_efficiency', 'unknown') or ('sensor.solar_battery_efficiency' == 0)) %}
      1
    {% elif (i1_dc_power + b1_dc_power <= 0) %}
      {% if (b1_dc_power >= 0 or i1_dc_power <= 0) %}
        {{ battery_efficiency }}
      {% else %}
        {{ (1 - ((b1_dc_power * -1 - (i1_dc_power)) / b1_dc_power * -1)) }}
     {% endif %}
    {% else %}
      {{ battery_efficiency }}
    {% endif %}
  availability: >
    {{ states('sensor.solaredge_i1_dc_power') | is_number and states('sensor.solaredge_i1_ac_power') | is_number and states('sensor.solaredge_b1_dc_power') | is_number }}
  1. Since the update of HA to 2023.03 apart from my battery gauge, the two other places where the battery is displayed shows the battery state of charge to several decimal places. That’s despite the entity precision being set to one decimal place. Can anyone help with that, becasue as far as I can tell, anywhere the battery state of energy is displayed it uses sensor.solaredge_b1_state_of_energy

I’d be extremely grateful if anyone could help with either, or both, of these issues.

Thanks.

The translation is just me…my mistake probably…:wink: As to the behaviour…yes that is correct. I was able to calculate this value based on DC OUtput and AC Availabilty. And it is pretty scary to how ineffective the battery actually is. I am sure SolarEdge does not want to display this, because customers would start to ask questions.

With two inverters, I seem to have quite a few problems. Not sure how to calculate battery efficiency with those two. Right now my battery is being used, and efficiency is 0, so there is no flow to the house, which is not correct.

Again, if someone has a complete code for a two inverter setup (connected via RS485/modbus), please share :slight_smile:

Indeed, I might just ask those questions the next time I attend a Solaredge webinar.

I can get round the issue by restarting HA, which always seems to bring the value back up to 100% or just under. Has to be a full restart though. Reloading the YAML configuration doesn’t seem to work.

Hi
Please forgive me if this is not the correct way to approach you, but I’m a total noob with HA, and want to understand what I want to do is possible before I get too ‘invested’. The reason for raeching out was because I’ve seen many of your posts and you seem to be doing a lot of what I am hoping to achive, but wanted to check first…
I have a SolarEdge inverter and battery system, and want to be able to optimise battery charging based on Solcast data for the next day. Basically, I want to charge the battery overnight (cheaper rate here in the UK), but only for as long (or as slowly) as required to get me past whatever the minimum battery level is forecast to be, based on time-dependent estimated house consumption and the time-dependent solar PV forecast.
So, my questions are:

  1. Is the above possible using HA? i.e. combining Solcast data AND estimated house consumption data AND current battery level during the cheaper overnight period to optimise (minimise) battery charging?
  2. I would be wanting run HA on an Apple Mac that stays on permanently, but is allowed to sleep. Will HA run continuously in the backgorund, or do I need a different machine?
    Thanks in advance for your help with this, Please do let me know if you need any more information from me to respond. “Help me to help you…!”
    Very best regards
    Spence

I don’t do any of that personally, maybe someone else who does will be able to help.

Thanks for your response - much appreciated

Here is my configs:

some caveats:

  • Mostly tested but still a bit of a WIP
  • I’ve noticed some issues with the tariffs in that my offpeak can increase slightly during peak… I think it is an HA bug but it’s only a few pence a day so not so worried i need to fix it right now.

All comments/PRs/issues accepted

This is my energy.yaml for our 2 inverter 1 battery set up. We have Inverter 1 as leader and Inverter 2 as follower. The battery is connected to Inverter 1. all connected via RS485/modbus.

template:
  - 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_daily = states('sensor.solar_exported_power_daily') | float(0) %}

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

      - name: "Inverter 1 Production"
        unique_id: inverter_1_production
        icon: mdi:solar-power
        unit_of_measurement: "W"
        state_class: "measurement"
        device_class: "power"
        state: >
          {% set inverter_1_dc_output = states('sensor.solaredge_i1_dc_power') | float (0) %}
          {% set battery_output = states('sensor.solaredge_b1_dc_power') | float (0) %}
          {% set inverter_1_production_discharging = battery_output + inverter_1_dc_output %}
          {% set inverter_1_production_charging = inverter_1_dc_output + battery_output %}

          {% if (battery_output >=0) %}
            {{ inverter_1_production_charging }}
          {% else %}
            {{ inverter_1_production_discharging }}
          {% endif %}

        availability: >
          {{ states('sensor.solaredge_i1_dc_power') | is_number and states('sensor.solaredge_b1_dc_power') | is_number }}
          
      - name: "Solar Selfsufficiency Ratio"
        unique_id: solar_selfsufficiency_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 %}

      - name: "Solar Inverter Efficiency"
        unique_id: solar_inverter_efficiency
        icon: mdi:percent-outline
        unit_of_measurement: "%"
        state: >
          {% 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 i1_ac_power = states('sensor.solaredge_i1_ac_power') | float(0) %}
          {% set i2_ac_power = states('sensor.solaredge_i2_ac_power') | float(0) %}
          {% set inverter_efficiency = states('sensor.solar_inverter_efficiency') %}

          {% if (is_state('sensor.solar_inverter_efficiency', 'unknown')) %}
            1
          {% elif ((i1_dc_power + i2_dc_power) <= 100 or (i1_ac_power + i2_ac_power)  <= 100) %}
            {{ inverter_efficiency }}
          {% else %}
            {{ (i1_ac_power + i2_ac_power ) / (i1_dc_power + i2_dc_power) }}
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_i1_dc_power') | is_number and states('sensor.solaredge_i1_ac_power') | is_number }}
  
      - name: "Inverter 1 Efficiency"
        unique_id: inverter_1_efficiency
        icon: mdi:percent-outline
        unit_of_measurement: "%"
        state: >
          {% set i1_dc_output = states('sensor.solaredge_i1_dc_power') | float(0) %}
          {% set i1_ac_output = states('sensor.solaredge_i1_ac_power') | float(0) %}
          {% set inverter_1_efficiency = states('sensor.inverter_1_efficiency') %}

          {% if (is_state('sensor.inverter_1_efficiency', 'unknown')) %}
            1
          {% elif (i1_dc_output < 100 or i1_ac_output  < 100) %}
            {{ inverter_1_efficiency }}
          {% else %}
            {{ (i1_ac_output ) / (i1_dc_output) }}
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_i1_dc_power') | is_number and states('sensor.solaredge_i1_ac_power') | is_number }}

      - name: "Inverter 2 Efficiency"
        unique_id: inverter_2_efficiency
        icon: mdi:percent-outline
        unit_of_measurement: "%"
        state: >
          {% set i2_dc_output = states('sensor.solaredge_i2_dc_power') | float (0) %}
          {% set i2_ac_output = states('sensor.solaredge_i2_ac_power') | float (0) %}
          {% set inverter_2_efficiency = states('sensor.inverter_2_efficiency') %}

          {% if (is_state('sensor.inverter_2_efficiency', 'unknown' )) %}    
            1
          {% elif (i2_dc_output < 100 or i2_ac_output < 100) %} 
            {{ inverter_2_efficiency }} 
          {% else %}  
            {{ (i2_ac_output) / (i2_dc_output) }}
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_i2_dc_power') | is_number and states('sensor.solaredge_i2_ac_power') | is_number }}

      - name: "Solar Battery Efficiency"
        unique_id: solar_battery_efficiency
        icon: mdi:percent-outline
        unit_of_measurement: "%"
        state: >
          {% set i1_dc_power = states('sensor.solaredge_i1_dc_power') | float(0) %}
          {% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float(0) %}
          {% set battery_efficiency = states('sensor.solar_battery_efficiency') %}
          
          {% if (is_state('sensor.solar_battery_efficiency', 'unknown') or ('sensor.solar_battery_efficiency' == 0)) %}
            1
          {% elif (i1_dc_power + b1_dc_power <= 0) %}
            {% if (b1_dc_power >= 0 or i1_dc_power <= 0) %}
              {{ battery_efficiency }}
            {% else %}
              {{ (1 - ((b1_dc_power * -1 - (i1_dc_power)) / b1_dc_power * -1)) }}
            {% endif %} 
          {% else %}
            {{ battery_efficiency }}
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_i1_dc_power') | is_number 
          and states('sensor.solaredge_i1_ac_power') | is_number 
          and states('sensor.solaredge_b1_dc_power') | is_number }}

      - name: "Solar Panel Production W"
        unique_id: solar_panel_production_w
        unit_of_measurement: "W"
        icon: mdi:solar-power
        state: >
          {% 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)%}

          {% if (is_state ('sensor.solaredge_i1_dc_power' + 'sensor.solaredge_i2_dc_power', 'unknown') or is_state ('sensor.solaredge_b1_dc_power','unknown')) %}
            0
          {% elif (i1_dc_power + i2_dc_power + b1_dc_power <= 0) %}
            0
          {% else %}
            {{ i1_dc_power + i2_dc_power + b1_dc_power }}
          {%  endif %}
        availability: >
          {{ states('sensor.solaredge_i1_dc_power') | is_number and states('sensor.solaredge_i2_dc_power') | is_number and states('sensor.solaredge_b1_dc_power') | is_number }}

      - name: "Solar Panel To House W"
        unique_id: solar_panel_to_house_w
        unit_of_measurement: "W"
        icon: mdi:solar-power
        state: >
          {% 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 i1_ac_power = states('sensor.solaredge_i1_ac_power') | float(0) %}
          {% set i2_ac_power = states('sensor.solaredge_i2_ac_power') | float(0) %}
          {% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float(0) %}
          {% set m1_ac_power = states('sensor.solaredge_m1_ac_power') | float(0) %}
          {% set inverter_efficiency = states('sensor.solar_inverter_efficiency') | float(0) %}

          {% if (b1_dc_power >= 0 and m1_ac_power > 0) %}
            {% if (i1_dc_power < 0 and i1_ac_power <= 0) %}
              {{ ((i1_dc_power + i2_ac_power) - m1_ac_power) | float (0) | round (2) }}
            {% else %}
              {{ ((i1_ac_power + i2_ac_power) - m1_ac_power) | float (0) | round (2) }}
            {% endif %}
          {% elif (b1_dc_power >= 0 and m1_ac_power < 0) %}
            {% if ((i1_dc_power + i2_dc_power) < 0 and (i1_ac_power + i2_ac_power) <= 0) %}
              {{ (i1_dc_power + i2_dc_power) | float (0) | round (2) }}
            {% else %}
              {{ (i1_ac_power + i2_ac_power) | float (0) | round (2)}}
            {% endif %}
          {% elif (b1_dc_power < 0) %}
            {% if (i1_dc_power + i2_dc_power + b1_dc_power < 0 )%}            
              0
            {% else %}
              {{ ((i1_dc_power + i2_dc_power + b1_dc_power) * inverter_efficiency) }}
            {% endif %}   
          {% else %}
            0
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_i1_dc_power') | is_number and states('sensor.solaredge_i2_dc_power') | is_number and states('sensor.solaredge_i1_ac_power') | is_number and states('sensor.solaredge_i2_ac_power') | is_number and states('sensor.solaredge_b1_dc_power') | is_number and states('sensor.solaredge_m1_ac_power') | is_number }}

      - name: "Solar Panel To Battery W"
        unique_id: solar_panel_to_battery_w
        unit_of_measurement: "W"
        icon: mdi:solar-power
        state: >
          {% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float(0) %}
          {% set grid_to_battery_w = states('sensor.solar_grid_to_battery_w') | float(0) %}
          {% set i1_dc_power = states('sensor.solaredge_i1_dc_power') | float(0) %}
          
          {% if i1_dc_power < 0 %}
            {% set i1_dc_power = states('sensor.solaredge_i1_dc_power') * -1 | float (0) %}
          {% else %}
            {% set i1_dc_power = states('sensor.solaredge_i1_dc_power') | float(0) %}
          {% endif %}

          {% if (b1_dc_power > 0) %}
            {% if (grid_to_battery_w > 0) %}
              0
            {% else %}
              {{ b1_dc_power }}
            {% endif %} 
          {% else %}
            0
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_b1_dc_power') | is_number }}
        
      - name: "Solar Panel To Grid W"
        unique_id: solar_panel_to_grid_w
        unit_of_measurement: "W"
        icon: mdi:solar-power
        state: >
          {% set panel_production_w = states('sensor.solar_panel_production_w') | float(0) %}
          {% set exported_power_w = states('sensor.solar_exported_power_w') | float(0) %}

          {% if (exported_power_w > 0 and panel_production_w > 0) %}
            {% if (exported_power_w > panel_production_w) %}
              {{ panel_production_w }}
            {% else %}
              {{ exported_power_w }}
            {% endif %}
          {% 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: >
          {% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float(0) %}
          {% set battery_efficiency = states('sensor.solar_battery_efficiency') | float(0) %}
          {% set inverter_efficiency = states('sensor.solar_inverter_efficiency') | float(0) %}

          {% if (b1_dc_power < 0) %}
            {{ (b1_dc_power * -1 * battery_efficiency * inverter_efficiency) | float(0) | round (2)}}
          {% else %}
            0
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_b1_dc_power') | is_number }}
          
      - name: "Solar Battery To Grid W"
        unique_id: solar_battery_to_grid_w
        unit_of_measurement: "W"
        icon: mdi:solar-power
        state: >
          {% set exported_power_w = states('sensor.solar_exported_power_w') | float(0) %}
          {% set panel_to_grid_w = states('sensor.solar_panel_to_grid_w') | float(0) %}

          {% if (exported_power_w > panel_to_grid_w) %}
            {{ exported_power_w - panel_to_grid_w }}
          {% 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: >
          {% set m1_ac_power = states('sensor.solaredge_m1_ac_power') | float(0) %}

          {% if (m1_ac_power <= 0) %}
            {{ (m1_ac_power * -1) }}
          {% else %}
            0
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_m1_ac_power') | is_number }}
          
      - name: "Solar Grid To Battery W"
        unique_id: solar_grid_to_battery_w
        unit_of_measurement: "W"
        icon: mdi:battery-positive
        state: >
          {% set i1_ac_power = states('sensor.solaredge_i1_ac_power') | float(0) %}
          {% set b1_dc_power = states('sensor.solaredge_b1_dc_power') | float(0) %}

          {% if i1_ac_power < 0 %}
            {% set i1_ac_power = (i1_ac_power * -1) %}
            {% else %}  
              {% set i1_ac_power = (states('sensor.solaredge_i1_ac_power') | float(0)) %}
              {% endif %}  
              {% if (i1_ac_power <= 0 and b1_dc_power > 0 ) %}
                {{ b1_dc_power }}
                {% else %}
                  0
                  {% endif %}
        availability: >
          {{ states('sensor.solaredge_i1_ac_power') | is_number and states('sensor.solaredge_b1_dc_power') | is_number}}

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

          {{ (grid_to_battery_w + panel_to_battery_w) }}

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

          {{ (panel_to_house_w + battery_to_house_w + grid_to_house_w) }}

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

          {% if (m1_ac_power < 0) %}
            {{ (m1_ac_power * -1) }}
          {% else %}
            0
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_m1_ac_power') | is_number}}

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

          {% if (m1_ac_power > 0) %}
            {{ (m1_ac_power) }}
          {% else %}
            0
          {% endif %}
        availability: >
          {{ states('sensor.solaredge_m1_ac_power') | is_number }}
          
      - name: "Solar Lifetime Production"
        unique_id: solar_lifetime_production
        unit_of_measurement: "MWh"
        icon: mdi:solar-power
        state: >
          {% set ac_energy_i1_kwh = states('sensor.solaredge_i1_ac_energy_kwh') | float(0) %}
          {% set ac_energy_i2_kwh = states('sensor.solaredge_i2_ac_energy_kwh') | float(0) %}
          {{ (((ac_energy_i1_kwh + ac_energy_i2_kwh) / 1000) | round (2)) }}
        availability: >
          {{ states('sensor.solaredge_i1_ac_energy_kwh') | is_number }}

      - name: "Solar Accounting Cost Rate"
        unique_id: solar_accounting_cost_rate
        icon: mdi:cash-plus
        unit_of_measurement: "£/kWh"
        state: >
          0.12

      - name: "Solar Accounting Compensation Rate"
        unique_id: solar_accounting_compensation_rate
        icon: mdi:cash-minus
        unit_of_measurement: "£/kWh"
        state: >
          0.041

      - name: "Solar Accounting Total Daily"
        unique_id: solar_accounting_total_daily
        icon: mdi:currency-gbp
        unit_of_measurement: "£"
        state: >
          {% set cost = (states('sensor.solar_imported_power_daily') | float(0)) * (states('sensor.solar_accounting_cost_rate') | float(0)) %}
          {% set compensation = (states('sensor.solar_exported_power_daily') | float(0)) * (states('sensor.solar_accounting_compensation_rate') | float(0)) %}
          {{ (cost - compensation) | round(2) }}

      - name: "Solar Accounting Total Weekly"
        unique_id: solar_accounting_total_weekly
        icon: mdi:currency-gbp
        unit_of_measurement: "£"
        state: >
          {% set cost = (states('sensor.solar_imported_power_weekly') | float(0)) * (states('sensor.solar_accounting_cost_rate') | float(0)) %}
          {% set compensation = (states('sensor.solar_exported_power_weekly') | float(0)) * (states('sensor.solar_accounting_compensation_rate') | float(0)) %}
          {{ (cost - compensation) | round(2) }}

      - name: "Solar Accounting Total Monthly"
        unique_id: solar_accounting_total_monthly
        icon: mdi:currency-gbp
        unit_of_measurement: "£"
        state: >
          {% set cost = (states('sensor.solar_imported_power_monthly') | float(0)) * (states('sensor.solar_accounting_cost_rate') | float(0)) %}
          {% set compensation = (states('sensor.solar_exported_power_monthly') | float(0)) * (states('sensor.solar_accounting_compensation_rate') | float(0)) %}
          {{ (cost - compensation) | round(2) }}

      - name: "Solar Accounting Total Yearly"
        unique_id: solar_accounting_total_yearly
        icon: mdi:currency-gbp
        unit_of_measurement: "£"
        state: >
          {% set cost = (states('sensor.solar_imported_power_yearly') | float(0)) * (states('sensor.solar_accounting_cost_rate') | float(0)) %}
          {% set compensation = (states('sensor.solar_exported_power_yearly') | float(0)) * (states('sensor.solar_accounting_compensation_rate') | float(0)) %}
          {{ (cost - compensation) | round(2) }}

      - name: "Solar Inverter Efficiency Int"
        unique_id: solar_inverter_efficiency_int
        icon: mdi:percent-outline
        unit_of_measurement: "%"
        state: >
          {{ ((states('sensor.solar_inverter_efficiency') | float(0)) * 100) | round(2) }}

      - name: "Inverter 1 Production Int"
        unique_id: inverter_1_production_int
        icon: mdi:solar-power
        unit_of_measurement: "W"
        state: >
          {{ (states('sensor.inverter_1_production') | float(0)) | round(2) }}

      - name: "Inverter 1 Efficiency Int"
        unique_id: inverter_1_efficiency_int
        icon: mdi:percent-outline
        unit_of_measurement: "%"
        state: >
          {{ ((states('sensor.inverter_1_efficiency') | float(0)) * 100) | round (2) }}

      - name: "Inverter 2 Efficiency Int"
        unique_id: inverter_2_efficiency_int
        icon: mdi:percent-outline
        unit_of_measurement: "%"
        state: >
          {{ ((states('sensor.inverter_2_efficiency') | float(0)) * 100) | round (2) }}


      - name: "Solar Battery Efficiency Int"
        unique_id: solar_battery_efficiency_int
        icon: mdi:percent-outline
        unit_of_measurement: "%"
        state: >
          {{ ((states('sensor.solar_battery_efficiency')| float(0)) * 100) | round(2) }}

      - name: "Solar Inverter Efficiency Average Int"
        unique_id: solar_inverter_efficiency_average_int
        icon: mdi:percent-outline
        unit_of_measurement: "%"
        state: >
          {{ ((states('sensor.solar_inverter_efficiency_average') | float(0)) * 100) | round(2) }}

      - name: "Solar Battery Efficiency Average Int"
        unique_id: solar_battery_efficiency_average_int
        icon: mdi:percent-outline
        unit_of_measurement: "%"
        state: >
          {{ ((states('sensor.solar_battery_efficiency_average')| float(0)) * 100) | 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 Efficiency Average"
    unique_id: solar_battery_efficiency_average
    state_characteristic: mean
    sampling_size: 1200
    max_age:
      hours: 24
    entity_id: sensor.solar_battery_efficiency

  - platform: statistics
    name: "Solar Inverter Efficiency Average"
    unique_id: solar_inverter_efficiency_average
    state_characteristic: mean
    sampling_size: 1200
    max_age:
      hours: 24
    entity_id: sensor.solar_inverter_efficiency

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

I’ve added a few extras to this to show production and efficiency for each inverter. Hope this helps.

1 Like

Hi @Remko. I think I owe you an apology.

I’d previously said that your battery and inverter effectiveness should actally be battery and inverter efficiency. However, looking back through your excellent other thread

https://community.home-assistant.io/t/updated-solaredge-modbus-full-setup-guide-with-energy-dashboard-integration-for-installations-with-battery-connected/340956/149

I now realise what you’re trying to achieve, which is to show how effective the battery is at meeting the house demand for power and also how effective the inverter is at doing the same.

What I don’t understand yet is that when the battery effectiveness falls to say 50%, which it can do, and the house is demanding 3kW, for example, where is the additional power coming from to meet that demand? The power flow shows the reduced power to the house, but it doesn’t show what is making up the difference. If I put the kettle on and the house consumption rises to over 3kW, at 50% effectiveness, the battery would need to provide 6kW. The SE battery can only provide the inverter plate value, which in my case is 4kW, but all that happens is the flow values are lower. I hope that makes sense. It’s clearly a tricky thing to demonstrate.