Solar Edge Modbus integration combined with the new Energy Dashboard

I have been working on setting up the SolarEdge Modbus integration and creating the right sensors etc for this platform to be able to get almost live updates in my Lovelace Dashboard and also use this data to feed the new Energy Page in the latest Homeassistant updates. I took me a while to get everything working properly, so I thought I could share my setup here. I am really happy with this integration since now I have one less dependency on cloud data. All the required information gets read directly inside my own home network and on top of that the information is almost live.

Hopefully someone else can use this information too…

This is what I wanted to have live updates on:
image

So in the confguration.yaml I defined the modbus integration and create utility meters for my different sensors.

In the sensors.yaml I used the integration platform to calculate Wh based on the live updates from the modbus sensors in W. Also here are the seperate modbus integration sensors. Still working on the “Battery State” sensor to figure out what the numbers mean (I know that battery_state 3 is charging)

And then in the template.yaml I did some if then else statements to create a sensor for imported energy and exported energy. The modbus gives me only one sensor for the power grid which has values which are positive or negative. I wanted to seperate these in a dedicated import and export sensor.

So all that led to the following configs:

configuration.yaml

solaredge_modbus:
    name: 'SolarEdge Modbus'
    host: ip adress of inverter
    port: 1502
    scan_interval: 3 
    read_meter1: true 
    read_meter2: false
    read_battery: true
    
utility_meter:
  solar_imported_power_daily:
    source: sensor.solar_imported_power_kwh
    name: Solar Imported Power Daily
    cycle: daily 
  solar_imported_power_weekly:
    source: sensor.solar_imported_power_kwh
    name: Solar Imported Power Weekly
    cycle: weekly 
  solar_imported_power_monthly:
    source: sensor.solar_imported_power_kwh
    name: Solar Imported Power Monthly
    cycle: monthly 
  solar_imported_power_yearly:
    source: sensor.solar_imported_power_kwh
    name: Solar Imported Power Yearly
    cycle: yearly 
    
  solar_exported_power_daily:
    source: sensor.solar_exported_power_kwh
    name: Solar Exported Power Daily
    cycle: daily 
  solar_exported_power_weekly:
    source: sensor.solar_exported_power_kwh
    name: Solar Exported Power Weekly
    cycle: weekly 
  solar_exported_power_monthly:
    source: sensor.solar_exported_power_kwh
    name: Solar Exported Power Monthly
    cycle: monthly 
  solar_exported_power_yearly:
    source: sensor.solar_exported_power_kwh
    name: Solar Exported Power Yearly
    cycle: yearly 

  solar_production_daily:
    source: sensor.solar_production_kwh
    name: Solar Production Daily
    cycle: daily 
  solar_production_weekly:
    source: sensor.solar_production_kwh
    name: Solar Production Weekly
    cycle: weekly 
  solar_production_monthly:
    source: sensor.solar_production_kwh
    name: Solar Production Monthly
    cycle: monthly 
  solar_production_yearly:
    source: sensor.solar_production_kwh
    name: Solar Production Yearly
    cycle: yearly 
    
  solar_house_consumption_daily:
    source: sensor.solar_house_consumption_kwh
    name: Solar House Consumption Daily
    cycle: daily 
  solar_house_consumption_weekly:
    source: sensor.solar_house_consumption_kwh
    name: Solar House Consumption Weekly
    cycle: weekly 
  solar_house_consumption_monthly:
    source: sensor.solar_house_consumption_kwh
    name: Solar House Consumption Monthly
    cycle: monthly 
  solar_house_consumption_yearly:
    source: sensor.solar_house_consumption_kwh
    name: Solar House Consumption Yearly
    cycle: yearly     

sensors.yaml

  - 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_production
    method: left
    unit_prefix: k
    name: solar_production_kwh
  - platform: integration
    source: sensor.solar_house_consumption
    method: left
    unit_prefix: k
    name: solar_house_consumption_kwh

  - platform: template
    sensors:
      solaredgemodbus_ac_total_current:
          friendly_name: "AC Total Current"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'ac_total_current') }}"
          unit_of_measurement: 'A'
      solaredgemodbus_ac_current_phase_a:
          friendly_name: "AC Current Phase A"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'ac_current_phase_a') }}"
          unit_of_measurement: 'A'
      solaredgemodbus_ac_current_phase_b:
          friendly_name: "AC Current Phase B"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'ac_current_phase_b') }}"
          unit_of_measurement: 'A'
      solaredgemodbus_ac_current_phase_c:
          friendly_name: "AC Current Phase C"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'ac_current_phase_c') }}"
          unit_of_measurement: 'A'
      solaredgemodbus_ac_voltage_phase_ab:
          friendly_name: "SolarEdge AC Output Voltage (A-B)"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'ac_voltage_phase_ab') }}"
          unit_of_measurement: 'V'
      solaredgemodbus_ac_current_voltage_a:
          friendly_name: "AC Voltage Phase A"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'ac_voltage_phase_a') }}"
          unit_of_measurement: 'V'
      solaredgemodbus_ac_current_voltage_b:
          friendly_name: "AC Voltage Phase B"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'ac_voltage_phase_b') }}"
          unit_of_measurement: 'V'
      solaredgemodbus_ac_current_voltage_c:
          friendly_name: "AC Voltage Phase C"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'ac_voltage_phase_c') }}"
          unit_of_measurement: 'V'
      solaredgemodbus_ac_power_output:
          friendly_name: "AC Power Output"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'ac_power_output') }}"
          unit_of_measurement: 'W'
      solaredgemodbus_dc_current:
          friendly_name: "DC Current"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'dc_current') }}"
          unit_of_measurement: 'A'
      solaredgemodbus_dc_voltage:
          friendly_name: "DC Voltage"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'dc_voltage') }}"
          unit_of_measurement: 'V'
      solaredgemodbus_dc_power_input:
          friendly_name: "DC Power Input"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'dc_power_input') }}"
          unit_of_measurement: 'W'
      solaredgemodbus_heatsink_temp:
          friendly_name: "Inverter Heat sink Temperature"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'heat_sink_temperature') }}"
          unit_of_measurement: '°C'
      solaredgemodbus_inverter_efficiency:
          friendly_name: "Inverter efficiency"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'computed_inverter_efficiency') }}"
          unit_of_measurement: '%'
      solaredgemodbus_ac_frequency:
          friendly_name: "AC Frequency"
          value_template: "{{ state_attr('sensor.solaredge_modbus', 'ac_frequency') }}"
          unit_of_measurement: 'Hz'
      solaredgemodbus_lifetime_production:
          friendly_name: "Lifetime production"
          value_template: "{{ (state_attr('sensor.solaredge_modbus', 'ac_lifetimeproduction') / 1000000) | round(2) }}"
          unit_of_measurement: 'kWh'
      solaredgemodbus_battery_power:
          friendly_name: "Battery Energy Flow"
          value_template: "{{ state_attr('sensor.solaredge_modbus_battery', 'battery_power') }}"
          unit_of_measurement: 'W'
      solaredgemodbus_battery_percentage:
          friendly_name: "Battery Percentage"
          value_template: "{{ state_attr('sensor.solaredge_modbus_battery', 'battery_state_of_charge') }}"
          unit_of_measurement: '%'
      solaredgemodbus_battery_status:
          friendly_name: "Battery Status"
          value_template: "{{ state_attr('sensor.solaredge_modbus_battery', 'battery_state') }}"
      solaredgemodbus_status:
          friendly_name: "SolarEdge Status"
          value_template: >-
            {% if state_attr('sensor.solaredge_modbus', 'status') == 1 %}
              Off
            {% elif state_attr('sensor.solaredge_modbus', 'status') == 2 %}
              Sleep
            {% elif state_attr('sensor.solaredge_modbus', 'status') == 3 %}
              Wake-Up
            {% elif state_attr('sensor.solaredge_modbus', 'status') == 4 %}
              Working
            {% elif state_attr('sensor.solaredge_modbus', 'status') == 5 %}
              Throttled
            {% elif state_attr('sensor.solaredge_modbus', 'status') == 6 %}
              Shut-Down
            {% elif state_attr('sensor.solaredge_modbus', 'status') == 7 %}
              Fault
            {% elif state_attr('sensor.solaredge_modbus', 'status') == 8 %}
              Maintenance
            {% else %}
              Unknown
            {% endif %}

template.yaml

- sensor:
 #==============================
 #=== Solar Custom Card
 #==============================
  - name: "Solar Selfconsumption Ratio"
    unique_id: solar_selfconsumption_ratio
    state: "{{((states('sensor.solar_house_consumption_daily') | float / states('sensor.solar_production_daily') | float) * 100 ) | round (0)}}"
  - name: "Solar Autarkie Ratio"
    unique_id: solar_autarkie_ratio
    state: "{{((1 - (states('sensor.solar_imported_power_daily') | float / states('sensor.solar_house_consumption_daily') | float)) * 100 ) | round (0)}}"        
  - name: "Solar Lifetime Energy kW"
    unique_id: solar_lifetime_energy_kw
    unit_of_measurement: 'MWh'
    icon: >-
      mdi:solar-power
    state_class: measurement
    device_class: energy    
    state: "{{ ((states('sensor.solaredge_lifetime_energy') | float) / 1000000) | round (2) }}"


  - name: "Solar Production"
    unique_id: solar_production
    state_class: measurement
    device_class: energy  
    unit_of_measurement: 'W'
    state: >
      {% if ((states('sensor.solaredgemodbus_ac_power_output') | float) + (states('sensor.solaredge_modbus_battery') | float) <= 0) %} 
        0
      {% else %}
        {{((states('sensor.solaredgemodbus_ac_power_output') | float + states('sensor.solaredge_modbus_battery') | float) )}}
      {% endif %}
  - name: "Solar House Consumption"
    unique_id: solar_house_consumption
    state_class: measurement
    device_class: energy  
    unit_of_measurement: 'W'
    state: "{{((states('sensor.solaredgemodbus_ac_power_output') | float) - (states('sensor.solaredge_modbus_meter_1') | float))}}"

  - name: "Solar Imported Power W"
    unique_id: solar_imported_power_w
    state_class: measurement
    device_class: energy  
    unit_of_measurement: 'W'
    state: >
      {% if ((states('sensor.solaredge_modbus_meter_1') | float) <= 0) %} 
        {{(-(states('sensor.solaredge_modbus_meter_1') | float))}}
      {% else %}
        0
      {% endif %}
  - name: "Solar Exported Power W"
    unique_id: solar_exported_power_w
    state_class: measurement
    device_class: energy  
    unit_of_measurement: 'W'
    state: >
      {% if ((states('sensor.solaredge_modbus_meter_1') | float) > 0) %} 
        {{(states('sensor.solaredge_modbus_meter_1') | float)}}
      {% else %}
        0
      {% endif %}

When that all worked, I was now able to use the import and export sensors in my Energy Dashboard configuration:

The only value I still need the SolarEdge Cloud integration for is the lifetime energy. Somehow the value coming from the Modbus integration is weird and not correct. Still need to dig in to this.

Next up is making some sensors which calculate my power usage from my battery on a daily basis and some more statistics which I just like to see.

4 Likes

Hi @Remko, thanks for the post. I have a new solaredge installation and have it all feeding into my home assistant fine via TCPModbus and the cloud. In fact i have a grafana dash to monitor it on a daily basis as below.

Now trying to make use of the new energy feature in HA but struggling a bit. I only see the solaredge lifetime sensor value available when setting up the energy feature and not sure what i am doing wrong.

Can’t say I am a HA expert and your post around senors and templates looks interesting but would really value a bit more explanation around them so that the more novice users like myself might be able to make use of the information that has kindly been shared already. Again, huge thanks for the post.

1 Like

Well, I am still quite the novice too. I have the system running since last december only. I do suggest you read some of the documentation on the template and sensor platforms. It is pretty good and there are quite a few examples. Secondly, start working with the built in “developer tools”. The template editor in there is pretty usefull in getting everything sorted.

Now to the Energy Dashboard and Solar Edge… The energy dashboard requires sensors to be present which have certain attributes. In the blog on the energy dashboard or in the configuration section of this community there are a few topics covering that, so I will not go into all the detail but basically following attributes are missing with some of the built in SolarEdge Sensors:

  • last_reset
  • device_class
  • state_class

To add these attributes to the existing sensors, it requires a bit of a workaround. Basically, add this section to your configuration.yaml and replace the sensor attribute to match the solaredge sensors. In my case I was interested in the ‘sensor.solaredge_exported_power’ and ‘sensor.solaredge_imported_power’, so following configuration worked for me. Adding this bit made me able to select the sensors in the energy dashboard configuration.

homeassistant:
  customize_glob:
    sensor.*_power:
      last_reset: '1970-01-01T00:00:00+00:00'
      device_class: energy
      state_class: measurement

However…I noticed that the values were not always correct and on top of that the cloud integration only updates every 15 minutes. That made me want to use the modbus integration for all of this, since it is almost instant and not depending on the cloud integration.

The big difference is, is that the modus integration mainly provides instant values, so energy in “W” and not “Wh” (consumption over time) which is what the energy dashboard needs. Therefore I basically needed to create the “integration platform”. This allows to use an integral Sum of the provided instant values and can therefore calculate consumption over time. This giving me the sensors I need for the energy dashboard.

I also used the utility meter platform to create counters for daily, weekly usage to have that data available for other dashboards. I used the template platform mainly to extract exported power and imported power out of the one modbus sensor. The modbus sensor switches between positive and negative values and I needed counters which give me those values seperate.
One other value (House Consumption) is also something which can only be extracted out of 2 of the modbus sensors (ac_power - grid power) so that is another bit in the template section.

So, yes, this did involve quite a bit of reading (documentation and threads) numerous restarts, trying, analyzing etc. I actually installed Grafana to create a dashboard which helped me visualise the problem. After that more tweaking etc to get it all to work.

Some of the things which are still missing (only because I can, no need)

  • Battery consumption, so calculate how much of my house consumption comes from the battery
  • The Tesla card…just like it and want to build it for my purposes
  • Lifetime energy production. That sensor in the modbus integration provides me a wrong value, so I am still depending on the cloud integration for that. If I solve that somehow, I will delete the cloud integration completely.

So hope this helps a bit…

1 Like

thanks for this @Remko, looking at this, if you are still quite a novice i need to reclassify myself as a noddy novice!!! Thanks for taking the time to explain further, cant say i understand it all just yet but will try and find some time over the weekend to read up on templates and sensors…all new ground to me in terms of defining in yaml files. Thanks again.

1 Like

Where does the value for sensor.solar_production come from? I’m not able to find what populates it. It’s always 0.

That sensor is defined in the template.yaml. I wanted to see the live production, so had to work with the battery charging or not. If you do not have a battery the modbus_acpower gives you that value too.

Nice post, could you tell me what kind of card you use (on the top) it does not seem to be a Grafana view.

It’s the “power-distribution-card”. Here:

Do you mind sharing the templates for calculating the values for the built in energy dashboard using the Modbus? That’s the only thing I have left to be in a happy state. I’ve got a Tesla style card running, but that runs on kW.

The templates are in the first post. The utility meters are the ones I use in the energy dashboard. There is also a screenshot of the energy dashboard configuration…

Thanks for this, I’m also working through trying to get this all running

I’m unable to see where this sensor is defined “sensor.solaredge_lifetime_energy”
As such the “Solar Lifetime Energy kW” value is 0

Which is used in this code block

I do have a “sensor.solaredgemodbus_lifetime_production” sensor which looks to have the needed value

Fixed my own issue
Needed the SolarEdge cloud integration as well :crazy_face:

Only remaining issue is the solar_exported_power_yearly sensor is not showing up for usage in the Energy page for some reason
It has data :confused:

Fixed, after switching to Mariadb for recorder :confused:

Remko, thanks so much for providing the config files! I am a rank newbie at HA, so I must be doing something wrong. I copied your yaml lines into sensors.yaml and template.yaml - both are in the config folder with configuration.yaml. Then I added the configuration.yaml text you provided and changed the config to my setup: the IP of my inverter and set read-battery to false - my installation does not have a battery.

I wasn’t sure how to “include” the sensors and template yaml’s, so added these lines to my configuration.yaml file:

sensor: !include sensors.yaml
template: !include template.yaml

“Check Configuration” gave me an error:

Component error: solaredge_modbus - Integration ‘solaredge_modbus’ not found.

Can you please point me to what I may be doing incorrectly?

Thanks again!

I have documented the entire setup and configuration here:

I did use another custom modbus component to get it all to work, so the above configuration is not valid anymore. Please follow the guide in the linked thread, then it should work. If you have any questions you can also send me a direct message.

But looking at your error message, you have not installed the custom modbus integration yet.

Thanks, Remko! Yes, you are correct - I realized that after posting this - installed last night. I’ll go through your full setup post and see if I can get it to work.

Thanks again!

Interestingly MWh is not a valid unit of measurement for device_class of energy.
It only allows Wh or kWh.

Doesn’t cause many problems except long term statistics won’t be stored, but they are probably not required.

Yeah, I did noticed that. But as you mentioned…does not have an effect and I only use this sensor to just display the current status. I don’t use it in any statistics.

Hi @scottda this looks great! Do you mind to share your Dashboard? Would give me some Idea whats possible in Grafana and I wouldn´t have to start from scratch. Thanks!

1 Like

Hi @marschall.philipp , sorry i tried to post the json code here for you but its too big, it wont let me attach a json file either. Any other way you can think of to share the json with you? thanks