Integrating a Selectronic Solar Inverter with Home Assistant

As we all know, solar systems are all the rage these days (and for good reason, we’ve got to fix the climate somehow). We got a Selectronic-branded inverter and battery system installed at my family’s property a few years ago, and whilst the web portal provided by the manufacturer is fine, I’ve always wanted to integrate it with Home Assistant. Integration would allow me to use the Home Assistant Energy dashboard to view history, as well as automate a few things (primarily the hot water system and heat pump) based on battery levels.

My first attempt at this integration involved scraping the web portal using a .NET application and publishing the data via MQTT to the Mosquito broker inside Home Assistant. Whilst this was excellent experience in writing web scrapers and using MQTT, it turns out there is a much better way!

Home Assistant has in-built functionality to poll REST endpoints and parse the JSON it finds. And it also turns out Selectronic inverters have REST endpoints in their local controllers.

A screenshot of the 'RESTful' integration within Home Assistant.

Thanks to this post on the Home Assistant forums, I was able to put together some configuration to read my local controller and present the data as a bunch of sensors:

sensor:
  - platform: rest
    name: "selectronic"
    json_attributes_path: "$.items"
    json_attributes:
      - 'battery_in_wh_today'
      - 'battery_in_wh_total'   #
      - 'battery_out_wh_today'
      - 'battery_out_wh_total'  #
      - 'battery_soc'           #
      - 'battery_w'             #
      - 'fault_code'
      - 'fault_ts'
      - 'gen_status'
      - 'grid_in_wh_today'
      - 'grid_in_wh_total'      #
      - 'grid_out_wh_today'
      - 'grid_out_wh_total'     #
      - 'grid_w'                #
      - 'load_w'
      - 'load_wh_today'
      - 'load_wh_total'         #
      - 'shunt_w'
      - 'solar_wh_today'
      - 'solar_wh_total'        #
      - 'solarinverter_w'
      - 'timestamp'
    resource: "http://192.168.1.105/cgi-bin/solarmonweb/devices/BB9FDF8BB64FE24C7CD183FC75E64423/point"
    value_template: '{{ value_json.device.name }}'
    force_update: true
    
template:
  sensor:
    # Data from selectronic for long term statistics
    - name: "Selectronic - Battery State of Charge"
      device_class: battery
      state_class: measurement
      state: "{{(state_attr('sensor.selectronic', 'battery_soc')|float) | round(3)}}"
      unit_of_measurement: "%"
      unique_id: sensor.selectronic.battery_soc
      
    - name: "Selectronic - Battery Watts"
      device_class: power
      state_class: measurement
      state: "{{(state_attr('sensor.selectronic', 'battery_w')|float) | round(3)}}"
      unit_of_measurement: "w"
      unique_id: sensor.selectronic.battery_w
      
    - name: "Selectronic - Grid Watts"
      device_class: power
      state_class: measurement
      state: "{{(state_attr('sensor.selectronic', 'grid_w')|float) | round(3)}}"
      unit_of_measurement: "w"
      unique_id: sensor.selectronic.grid_w
      
    - name: "Selectronic - Load Watts"
      device_class: power
      state_class: measurement
      state: "{{(state_attr('sensor.selectronic', 'load_w')|float) | round(3)}}"
      unit_of_measurement: "w"
      unique_id: sensor.selectronic.load_w
      
    - name: "Selectronic - Solar Watts"
      device_class: power
      state_class: measurement
      state: "{{(state_attr('sensor.selectronic', 'solarinverter_w')|float) | round(3)}}"
      unit_of_measurement: "w"
      unique_id: sensor.selectronic.solarinverter_w
      
    - name: "Selectronic - Battery Out Total"
      device_class: energy
      state_class: total
      state: "{{(state_attr('sensor.selectronic', 'battery_out_wh_total')|float) | round(3)}}"
      unit_of_measurement: "kWh"
      unique_id: sensor.selectronic.battery_out_wh_total
        
    - name: "Selectronic - Battery In Total"
      device_class: energy
      state_class: total
      state: "{{(state_attr('sensor.selectronic', 'battery_in_wh_total')|float) | round(3)}}"
      unit_of_measurement: "kWh"
      unique_id: sensor.selectronic.battery_in_wh_total
        
    - name: "Selectronic - Load Usage Total"
      device_class: energy
      state_class: total
      state: "{{(state_attr('sensor.selectronic', 'load_wh_total')|float) | round(3)}}"
      unit_of_measurement: "kWh"
      unique_id: sensor.selectronic.load_wh_total
        
    - name: "Selectronic - Solar Production"
      device_class: energy
      state_class: total
      state: "{{(state_attr('sensor.selectronic', 'solar_wh_total')|float) | round(3)}}"
      unit_of_measurement: "kWh"
      unique_id: sensor.selectronic.solar_wh_total
      
    - name: "Selectronic - Grid In Total"
      device_class: energy
      state_class: total
      state: "{{(state_attr('sensor.selectronic', 'grid_in_wh_total')|float) | round(3)}}"
      unit_of_measurement: "kWh"
      unique_id: sensor.selectronic.grid_in_wh_total
      
    - name: "Selectronic - Grid Out Total"
      device_class: energy
      state_class: total
      state: "{{(state_attr('sensor.selectronic', 'grid_out_wh_total')|float) | round(3)}}"
      unit_of_measurement: "kWh"
      unique_id: sensor.selectronic.grid_out_wh_total

If you choose to use this configuration yourself, the only change that should be required is the URL endpoint. Change the IP address to that of your controller on your network, and the device ID will also need to be changed. You can find the correct device ID by viewing IPADDRESS/cgi-bin/solarmonweb/devices/ in your browser.

And voila, solar generation and power usage statistics!

Liked this? Here's some more:

  • No Related Posts! How sad!

Leave a Reply

Your email address will not be published. Required fields are marked *