Solaredge Modbus Configuration for Single Inverter and Battery

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.

I’ve just had a SolarEdge & StorEdge system set up. I’ve enabled modbus via TCP and have what looks like all the stats. Some of them don’t make any sense which makes me think some of the setup is wrong (e.g. it’s bright sunshine right now with no shading and our 5 kWp array is producing 400 W regardless of whether the sun is behind a cloud or not).

For example, m1_ac_power is always zero. I believe this is meant to show house consumption? If so, does that mean some CT clamp is missing or incorrectly wired?

EDIT: It looks like m1_ac_power is showing grid import/export and ac_power is showing house consumption. Haven’t yet figured out which stat is meant to show solar production. Given the battery discharge is just above the house consumption figure, I don’t think we’re producing anything currently.

Thank you! I will try your code and see if it works better (most of the time mine does seem to produce good results though, but sometimes when production is low I get strange values).

What I just noticed is that “Solar Panel Production” seems to be giving me random spikes when there is no sun at all. Do you have an idea what’s causing that?

It looks like those spikes started come in more often right after 20:00 (8pm), which is when I changed “my” code for your code. But that could just be a coincidence. Last night there were only very few spikes:

I’ve noticed a few “new” glitches myself recently. My house consumption drops to zero at times so I need to look at that. “Spikes” are often caused by the system trying to balance after a demand. Remember that the equipment is not perfect. When the house calls for power suddenly, eg when you turn on the kettle, that demand is immediately met by the grid because that’s always quickest to respond. Then the inverter realises it has power and jumps in. When that call for powed stops suddenly, eg when the kettle turns off, that power cannot suddenly stop. What you usually see is a short period of export, then the system settles down again. Likewise with panel production. The flow can seem to reverse for short periods while the system settles, giving you those strange spikes.

It’s always a good idea to have a copy of your “own” original code to go back to if you need to. I keep mine in a simple Notepad ++ file. It’s also useful for comparing code side by side.

Whenever I see an issue I copy the relevant piece of code into the Developer Tools > Template editor and watch what the results are. Then you an adjust the variables fo make sure it’s working before replacing code in the live version.

This morning my battery decided to switch back to “Disabled” a minute after being re-ebabled (sufficiently charged during off-peak, off-peak window ends).

This automation has been running flawlessly for a few weeks.

Anyone else seen this sort of thing happen?

Did the re-enable command fail or did the battery/inverter just decide to spontaneously change mode?

Yea, I do have a backup of “my” old code.

The spikes are fine, but it’s somewhat interesting that I get those spikes for “panel production”, at night, where there can’t be any panel production whatsoever. But I guess there is nothing I can do about that, as it is data coming via modbus from the SolarEdge system?

I do have an “issue” with your code now. The solar_grid_to_battery_w seems to be wrong, at least sometimes. Right now my battery is being charged my panel only, and I get the following:

image

The old code I was using was working, as far as I know. Do you know why that could be?

My old code:

      - name: "Solar Grid To Battery W"
        unique_id: solar_grid_to_battery_w
        unit_of_measurement: "W"
        state_class: measurement
        device_class: power
        icon: mdi:battery-positive
        state: >
          {% 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) %}

          {% if ((i1_ac_power + i2_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_i2_ac_power') | is_number and states('sensor.solaredge_b1_dc_power') | is_number}}

Your code:

      - name: "Solar Grid To Battery W"
        unique_id: solar_grid_to_battery_w
        unit_of_measurement: "W"
        state_class: measurement
        device_class: power
        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}}

I’ve discovered the glitches in the code. Two sections of code are wrong. If you replace them with these then the flow to the house and battery should be correct.

The two sectiosn of code are panel_to_house_w and panel_to_battery_w

Replace them with these:

- 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 + 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 }}
- 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') | float (0) * -1) %}
          {% 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 }}

The tricky bit with two inverters is that i1_dc_power often goes negative in value while the battery is charging. With the original section of code, this fools the flow into thinking the battery is charging from the grid. The new piece of code simply watches for i1_dc_power going negative and makes it positive again.

Hope that works for you now

1 Like

Thank you! I will use that and keep an eye on the flows :slight_smile:

1 Like

Unfortunately, that didn’t fix it. I will have to take a closer look when I find the time. Sun is shining, house car is charging, oven is on… but panel to house is 0 for a short period. House consumption somehow is 0 as well.

image

That’s a shame. Perhaps your setup is not quite the same as mine. Currently, the sun is shining, the battery is charging and the house is drawing power.

House Flow

I did notice with mine that once the battery was charged, the panels appeared to show no generation.

That’s next on my list.

All good fun!

Mostly my flows work fine with my current code, but sometimes in the mornings I do see some negative panel production flow. Might be the negative values for DC power on inverter 1.

Also, efficiency calculations seem to be wrong with my code, so I will maybe try to use those parts from your code and see how that goes.

I had to set battery efficiency to 100 % for now, but of course that’s not correct.

Looks like my latest glitch was a loss of the sensor. It went unknown for a short time. Back now and all looks okay.

Battery full again. Hot water on now.

House flow battery full

Interestingly, this card always shows the right values, even when the flow card looks wrong. Good to have them side by side for comparison.

Power flow battery full

UPDATE

Got it. Line 183 is

{{ ((i1_dc_power + i2_dc_power + b1_dc_power) * inverter_effectiveness) }}

it should be

{{ ((i1_dc_power + i2_dc_power + b1_dc_power) * inverter_efficiency) }}

I changed the original inverter_effectiveness to inverter_efficiency

Thanks for the update. I missed that, should have seen that.

I am now trying “your code” again to see if there are any glitches :smiley:

The “Power Flow” card is great, I do look at that sometime as well. Do you display an average of the two inverter efficiency values or just the efficiency or inverter 1?

@P6Dave

Could I suggest this as a tad cleaner (hopefully i copied the right post… ):

- 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 i_dc_power = (i1_dc_power + 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 i_ac_power = (i1_ac_power + 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 (i_dc_power < 0 and i_ac_power <= 0) %}
              {{ (i_dc_power - m1_ac_power) }}
            {% else %}
              {{ (i_ac_power - m1_ac_power) }}
            {% endif %}
          {% elif (b1_dc_power >= 0 and m1_ac_power <= 0) %}
            {% if (i_dc_power < 0 and i_ac_power  <= 0) %}
              {{ i_dc_power }}
            {% else %}
              {{ i_ac_power }}
            {% endif %}
          {% elif (b1_dc_power < 0) %}
            {% if (i_dc_power + b1_dc_power < 0) %}
              0
            {% else %}
              {{ ((i_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 }}

Basically i’ve just added to extra vars to hold i1_*_power so that it makes the addition etc later clearer

1 Like

Ooh, interesting. I’ll test that and see how it does. I do like a tidy bit of code :grinning_face_with_smiling_eyes:

Thanks.