Energy dashboard and Solax grid and battery integration

I’ve gone through a lot of configurations on energy meter and solax but struggled to get a comprehensive view so I’m listing how I have configured to help others. Part of the code is borrowed from different posts as every post adds some knowledge to the configuration that I’ve used and thanks for all who have shared their configurations :slight_smile: :hugs:
I’ve two standard solax inverters and 1 hybrid inverter connected to battery. So even if no solar output is produced the ac output of the Solax hybrid will still have output getting the value from battery.

I thought that Energy dashboard gives real time info just like solax


But it DOESN’T, it shows real time moving dots but these are the load, consumption and generation of the observation window (day, week…)
so you need to provide that info.
I don’t get total grid or battery info and the only total is for solar so I have to create integration sensors to get the total values. I used the total solar but can’t recall an issue with that and decided to create a total solar as well.

You have to add customisation to these sensors otherwsie they won’t appear in the dashboard.
This how it looks like

The following code needs to go in configuration file under

sensor:
## X1a ##
  - platform: rest
    scan_interval: 60
    resource: https://www.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=202109xxxx&sn=yyy
    name: "Solax X1a"
    json_attributes_path: "$.result"
    json_attributes:
      - yieldtoday
      - yieldtotal
      - acpower
      - uploadTime
      - inverterStatus
    value_template: '1'  # dummy value, not used; avoids the "State max length is 255 characters" error
  - platform: template
    sensors:
      solax_x1a_today:
        friendly_name: "Solax X1a today"
        value_template: "{{ state_attr('sensor.solax_x1a', 'yieldtoday') }}"
        unit_of_measurement: "kWh"
      solax_x1a_total:
        friendly_name: "Solax X1a total"
        value_template: "{{ state_attr('sensor.solax_x1a', 'yieldtotal') }}"
        unit_of_measurement: "kWh"
      solax_x1a_now:
        friendly_name: "Solax X1a now"
        value_template: "{{ state_attr('sensor.solax_x1a', 'acpower') }}"
        unit_of_measurement: "W"
      solax_x1a_upload_time:
        friendly_name: "Solax X1a upload time"
        value_template: "{{ state_attr('sensor.solax_x1a', 'uploadTime') }}"
      solax_x1a_status:
        friendly_name: "Solax X1 status"
        value_template: >
          {% if state_attr('sensor.solax_x1a', 'inverterStatus') == '100' %}Wait
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '101' %}Check
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '102' %}Normal
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '103' %}Fault
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '104' %}Permanent Fault
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '105' %}Update
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '106' %}EPS Check
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '107' %}EPS
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '108' %}Self-test
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '109' %}Idle
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '110' %}Standby
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '111' %}Pv Wake Up Bat
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '112' %}Gen Check
          {% elif state_attr('sensor.solax_x1a', 'inverterStatus') == '113' %}Gen Run
          {% else %}I dont know{% endif %}

## X1b ##
  - platform: rest
    scan_interval: 60
    resource: https://www.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=202109xxxx&sn=yyy 
    name: "Solax X1b"
    json_attributes_path: "$.result"
    json_attributes:
      - yieldtoday
      - yieldtotal
      - acpower
      - uploadTime
      - inverterStatus
    value_template: '1'  # dummy value, not used; avoids the "State max length is 255 characters" error
  - platform: template
    sensors:
      solax_x1b_today:
        friendly_name: "Solax X1b today"
        value_template: "{{ state_attr('sensor.solax_x1b', 'yieldtoday') }}"
        unit_of_measurement: "kWh"
      solax_x1b_total:
        friendly_name: "Solax X1b total"
        value_template: "{{ state_attr('sensor.solax_x1b', 'yieldtotal') }}"
        unit_of_measurement: "kWh"
      solax_x1b_now:
        friendly_name: "Solax X1b now"
        value_template: "{{ state_attr('sensor.solax_x1b', 'acpower') }}"
        unit_of_measurement: "W"
      solax_x1b_upload_time:
        friendly_name: "Solax X1b upload time"
        value_template: "{{ state_attr('sensor.solax_x1b', 'uploadTime') }}"
      solax_x1b_status:
        friendly_name: "Solax X1b status"
        value_template: >
          {% if state_attr('sensor.solax_x1b', 'inverterStatus') == '100' %}Wait
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '101' %}Check
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '102' %}Normal
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '103' %}Fault
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '104' %}Permanent Fault
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '105' %}Update
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '106' %}EPS Check
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '107' %}EPS
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '108' %}Self-test
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '109' %}Idle
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '110' %}Standby
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '111' %}Pv Wake Up Bat
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '112' %}Gen Check
          {% elif state_attr('sensor.solax_x1b', 'inverterStatus') == '113' %}Gen Run
          {% else %}I dont know{% endif %}

## X1h ##
  - platform: rest
    scan_interval: 60
    resource: https://www.solaxcloud.com:9443/proxy/api/getRealtimeInfo.do?tokenId=202109xxxx&sn=yyy 
    name: "Solax X1h"
    json_attributes_path: "$.result"
    json_attributes:
      - yieldtoday
      - yieldtotal
      - acpower
      - feedinpower
      - powerdc1
      - powerdc2
      - batPower
      - soc
      - uploadTime
      - inverterStatus
    value_template: '1'  # dummy value, not used; avoids the "State max length is 255 characters" error
  - platform: template
    sensors:
      solax_x1h_today:
        friendly_name: "Solax X1h today"
        value_template: "{{ state_attr('sensor.solax_x1h', 'yieldtoday') }}"
        unit_of_measurement: "kWh"
      solax_x1h_total:
        friendly_name: "Solax X1h total"
        value_template: "{{ state_attr('sensor.solax_x1h', 'yieldtotal') }}"
        unit_of_measurement: "kWh"
      solax_x1h_ac:
        friendly_name: "Solax X1h ac"
        unit_of_measurement: "W"
        value_template: "{{ state_attr('sensor.solax_x1h', 'acpower') }}"
      solax_x1h_feedin:
        friendly_name: "Solax X1h feedin"
        unit_of_measurement: "W"
        value_template: "{{ state_attr('sensor.solax_x1h', 'feedinpower') }}"
      solax_x1h_dc1:
        friendly_name: "Solax X1 dc1"
        value_template: "{{ state_attr('sensor.solax_x1h', 'powerdc1') }}"
        unit_of_measurement: "W"
      solax_x1h_dc2:
        friendly_name: "Solax X1h dc2"
        value_template: "{{ state_attr('sensor.solax_x1h', 'powerdc2') }}"
        unit_of_measurement: "W"
      solax_x1h_soc:
        friendly_name: "Solax X1h soc"
        value_template: "{{ state_attr('sensor.solax_x1h', 'soc') }}"
        unit_of_measurement: "%"
      #Solar output of Hybrid inverter
      solax_x1h_solar:
        friendly_name: "Solax X1h solar"
        value_template:  >
          {% if (state_attr('sensor.solax_x1h', 'powerdc1') | float) > 0 and 
                (state_attr('sensor.solax_x1h', 'powerdc2') | float ) > 0 %}
            {{ (((states('sensor.solax_x1h_ac') | float ) - (states('sensor.battery_out') | float) 
            + (states('sensor.battery_in') | float)) | float | abs) }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: "W"
      #A/C output of Hybrid inverter
      solax_x1h_now:
        friendly_name: "Solax X1h now"
        value_template: "{{ (states('sensor.solax_x1h_ac') | float ) }}"
        unit_of_measurement: "W"
      solax_x1h_batpower:
        friendly_name: "Solax X1h batPower"
        value_template: "{{ state_attr('sensor.solax_x1h', 'batPower') }}"
        unit_of_measurement: "W"
      solax_x1h_upload_time:
        friendly_name: "Solax X1h upload time"
        value_template: "{{ state_attr('sensor.solax_x1h', 'uploadTime') }}"
      solax_x1h_status:
        friendly_name: "Solax X1h status"
        value_template: >
          {% if state_attr('sensor.solax_x1h', 'inverterStatus') == '100' %}Wait
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '101' %}Check
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '102' %}Normal
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '103' %}Fault
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '104' %}Permanent Fault
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '105' %}Update
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '106' %}EPS Check
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '107' %}EPS
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '108' %}Self-test
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '109' %}Idle
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '110' %}Standby
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '111' %}Pv Wake Up Bat
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '112' %}Gen Check
          {% elif state_attr('sensor.solax_x1h', 'inverterStatus') == '113' %}Gen Run
          {% else %}I dont know{% endif %}
#Sum of all invertors          
  - platform: template
    sensors:
      solar_total:
        friendly_name: Solar total
        unit_of_measurement: "kWh"
        value_template: "{{ (states('sensor.solax_x1a_total') | float) + (states('sensor.solax_x1b_total') | float)  + (states('sensor.solax_x1h_total') | float) }}"
      solar_today:
        friendly_name: Solar today
        unit_of_measurement: "kWh"
        value_template: "{{ (states('sensor.solax_x1a_today') | float) + (states('sensor.solax_x1b_today') | float) + (states('sensor.solax_x1h_today') | float)}}"
      solar_now:
        friendly_name: Solar now
        unit_of_measurement: W
        value_template: "{{ (states('sensor.solax_x1a_now') | float) + (states('sensor.solax_x1b_now') | float) + (states('sensor.solax_x1h_solar') | float) }}"
      total_ac_now:
        friendly_name: Total AC now
        unit_of_measurement: W
        value_template: "{{ (states('sensor.solax_x1a_now') | float) + (states('sensor.solax_x1b_now') | float) + (states('sensor.solax_x1h_now') | float) }}"

# Calculate power in and out 
      battery_in:
        friendly_name: Battery in
        unit_of_measurement: W
        value_template: >
          {% if (states('sensor.solax_x1h_batpower') | float ) > 0  %}
            {{ (states('sensor.solax_x1h_batpower') | float | abs) }}
          {% else %}
            0
          {% endif %} 
      battery_out:
        friendly_name: Battery out
        unit_of_measurement: W
        value_template: >
          {% if (states('sensor.solax_x1h_batpower') | float ) < 0  %}
            {{ (states('sensor.solax_x1h_batpower') | float | abs) }}
          {% else %}
            0
          {% endif %}    
      house_load:
        friendly_name: House Load
        value_template:  >
          {% if (states('sensor.solar_now') | float ) == 0  %}
            {{ (states('sensor.solax_x1h_now') | float) 
          + (states('sensor.grid_in') | float) - (states('sensor.grid_out') | float) }}
          {% else %}
            {{ (states('sensor.total_ac_now') | float) 
          + (states('sensor.grid_in') | float) - (states('sensor.grid_out') | float) }}
          {% endif %}
        unit_of_measurement: W
# Grid power in and out      
      grid_out:
        friendly_name: Grid out
        unit_of_measurement: W
        value_template: >
          {% if (states('sensor.solax_x1h_feedin') | float ) > 0  %}
            {{ (states('sensor.solax_x1h_feedin') | float | abs)}}
          {% else %}
            0
          {% endif %}
      grid_in:
        friendly_name: Grid in
        value_template: >
          {% if (states('sensor.solax_x1h_feedin') | float ) < 0  %}
            {{ (states('sensor.solax_x1h_feedin') | float | abs) }}
          {% else %}
             0
          {% endif %}
        unit_of_measurement: W
# Integrating Export and Import Grid        
  - platform: integration
    source: sensor.grid_in
    name: total_grid_in
    unit_prefix: k
    round: 2
    method: left
  - platform: integration
    source: sensor.grid_out
    name: total_grid_out
    unit_prefix: k
    round: 2
    method: left
  - platform: integration
    source: sensor.battery_in
    name: total_battery_in
    unit_prefix: k
    round: 2
    method: left
  - platform: integration
    source: sensor.battery_out
    name: total_battery_out
    unit_prefix: k
    round: 2
    method: left
  - platform: integration
    source: sensor.house_load
    name: total_house_load
    unit_prefix: k
    round: 2
    method: left
  - platform: integration
    source: sensor.solar_now
    name: total_solar
    unit_prefix: k
    round: 2
    method: left

This has to go in the customize.yaml

sensor.total_grid_out:
  last_reset: '2021-10-10T00:00:00+00:00'
  state_class: total
  device_class: energy
  value_template: '{{value|round(2)}}'
sensor.total_grid_in:
  last_reset: '2021-10-10T00:00:00+00:00'
  state_class: total
  device_class: energy
  value_template: '{{value|round(2)}}'
sensor.total_battery_out:
  last_reset: '2021-10-10T00:00:00+00:00'
  state_class: total
  device_class: energy
  value_template: '{{value|round(2)}}'
sensor.total_battery_in:
  last_reset: '2021-10-10T00:00:00+00:00'
  state_class: total
  device_class: energy
  value_template: '{{value|round(2)}}'
sensor.total_house_load:
  last_reset: '2021-10-10T00:00:00+00:00'
  state_class: total
  device_class: energy
  value_template: '{{value|round(2)}}'
sensor.total_solar:
  last_reset: '2021-10-10T00:00:00+00:00'
  state_class: total
  device_class: energy
  value_template: '{{value|round(2)}}'

provided you have defined customize.yaml in configuration.yaml file

homeassistant:
  customize: !include customize.yaml

Hope this helps others

5 Likes

Hi,
Thanks for the thread, I’ve been sat trying to modify and recreate it as I’ve got 2 inverters, one Solax which appears to be the same as your ‘X1H’ to control my battery and the other a Sofar branded one that takes the solar. I think I’ve replaced the Solax X1a info with the correct Sofar data to pull it all together but I’m having some issues configuring it all in the energy dashboard. I appreciate this is a 9 month old thread but if you’re still about, any chance I can ask a few questions?

Thanks

Yes, saw your message today :pensive:

In the energy section when i try to add Solar Panel’s using the above code/config why does it not show up the sensors for me to select?

image

ok so i got the sensor showing total_solar as i had duplicate entries.

But now im showing

image

Check in the development tool, what is the value being returned. To me it looks like the unit is not correct

If it’s any help for anyone, below is the code that I’ve got running on my system at the moment based on the original code from @ausfas. It’s working ok for the Energy Dashboard but I’ve also ended up setting up a second dashboard using the 'tesla-style card" as I’ve found that the energy dashboard only tends to be able to show a daily cumulative position whereas the tesla-style card is better at showing the “live” position.
The code below is also what I’m using based on two different inverter brands. It’s definitely not optimised and there are a couple of parts that probably do the same thing but it;s working well enough at present.

sensor:
  ### Sofar Inverter ###
  - platform: rest
    resource: https://api.solarmanpv.com/device/v1.0/currentData?appId=<XXXX>&language=en&=
    method: POST
    name: "Sofar Cumulative Production"
    scan_interval: 3600
    headers:
      Authorization: bearer XXXX
      Content-Type: application/json
    payload: '{  "deviceSn": "XXXXX"}'
    value_template: "{{ value_json.dataList[22].value }}"
    unit_of_measurement: kWh
  - platform: rest
    resource: https://api.solarmanpv.com/device/v1.0/currentData?appId=<XXXXX>&language=en&=
    method: POST
    name: "Sofar Current AC Production"
    scan_interval: 15
    unit_of_measurement: W
    device_class: power
    state_class: total
    headers:
      Authorization: bearer XXXXX
      Content-Type: application/json
    payload: '{  "deviceSn": "XXXXX"}'
    value_template: "{{ value_json.dataList[21].value }}"
  - platform: rest
    resource: https://api.solarmanpv.com/device/v1.0/currentData?appId=<XXXX>&language=en&=
    method: POST
    name: "Sofar Daily Production"
    scan_interval: 3600
    headers:
      Authorization: bearer XXXXXXX
      Content-Type: application/json
    payload: '{  "deviceSn": "XXXXX"}'
    value_template: "{{ value_json.dataList[23].value }}"
    unit_of_measurement: kWh
    device_class: energy
    state_class: total_increasing

  ## Solax Inverter ##
  - platform: rest
    scan_interval: 60
    resource: https://www.solaxcloud.com/proxyApp/proxy/api/getRealtimeInfo.do?tokenId=XXXXX&sn=XXXXX
    name: "Solax"
    json_attributes_path: "$.result"
    json_attributes:
      - yieldtoday
      - yieldtotal
      - acpower
      - feedinpower
      - feedinpowerM2
      - powerdc1
      - powerdc2
      - batPower
      - soc
      - uploadTime
      - inverterStatus
    value_template: "1" # dummy value, not used; avoids the "State max length is 255 characters" error
  - platform: template
    sensors:
      solax_today:
        friendly_name: "Solax today"
        value_template: "{{ state_attr('sensor.solax', 'yieldtoday') }}"
        unit_of_measurement: kWh
        device_class: energy
      solax_total:
        friendly_name: "Solax total"
        value_template: "{{ state_attr('sensor.solax', 'yieldtotal') }}"
        unit_of_measurement: kWh
      solax_ac:
        friendly_name: "Solax ac"
        unit_of_measurement: W
        value_template: "{{ state_attr('sensor.solax', 'acpower') }}"
      solax_feedin:
        friendly_name: "Solax feedin"
        unit_of_measurement: W
        value_template: "{{ state_attr('sensor.solax', 'feedinpower') }}"
      solax_feedinpowerm2:
        friendly_name: "Solax feedinpowerm2"
        unit_of_measurement: W
        value_template: "{{ state_attr('sensor.solax', 'feedinpowerM2') }}"
      solax_dc1:
        friendly_name: "Solax dc1"
        value_template: "{{ state_attr('sensor.solax', 'powerdc1') }}"
        unit_of_measurement: W
      solax_dc2:
        friendly_name: "Solax dc2"
        value_template: "{{ state_attr('sensor.solax', 'powerdc2') }}"
        unit_of_measurement: W
      solax_soc:
        friendly_name: "Solax soc"
        value_template: "{{ state_attr('sensor.solax', 'soc') }}"
        unit_of_measurement: "%"

      #Solar output of Inverter based on battery out flow only
      solax_solar:
        friendly_name: "Solax solar"
        value_template: "{{ (states('sensor.battery_out') | float) }}"
        unit_of_measurement: W
        device_class: power

      #A/C output of Inverter
      solax_now:
        friendly_name: "Solax now"
        value_template: "{{ (states('sensor.solax_ac') | float ) }}"
        unit_of_measurement: W
      solax_batpower:
        friendly_name: "Solax batPower"
        value_template: "{{ state_attr('sensor.solax', 'batPower') }}"
        unit_of_measurement: W
      solax_upload_time:
        friendly_name: "Solax upload time"
        value_template: "{{ state_attr('sensor.solax', 'uploadTime') }}"
      solax_status:
        friendly_name: "Solax status"
        value_template: >
          {% if state_attr('sensor.solax', 'inverterStatus') == '100' %}Wait
          {% elif state_attr('sensor.solax', 'inverterStatus') == '101' %}Check
          {% elif state_attr('sensor.solax', 'inverterStatus') == '102' %}Normal
          {% elif state_attr('sensor.solax', 'inverterStatus') == '103' %}Fault
          {% elif state_attr('sensor.solax', 'inverterStatus') == '104' %}Permanent Fault
          {% elif state_attr('sensor.solax', 'inverterStatus') == '105' %}Update
          {% elif state_attr('sensor.solax', 'inverterStatus') == '106' %}EPS Check
          {% elif state_attr('sensor.solax', 'inverterStatus') == '107' %}EPS
          {% elif state_attr('sensor.solax', 'inverterStatus') == '108' %}Self-test
          {% elif state_attr('sensor.solax', 'inverterStatus') == '109' %}Idle
          {% elif state_attr('sensor.solax', 'inverterStatus') == '110' %}Standby
          {% elif state_attr('sensor.solax', 'inverterStatus') == '111' %}Pv Wake Up Bat
          {% elif state_attr('sensor.solax', 'inverterStatus') == '112' %}Gen Check
          {% elif state_attr('sensor.solax', 'inverterStatus') == '113' %}Gen Run
          {% else %}I dont know{% endif %}

  #Sum of all invertors now just based on Sofar
  - platform: template
    sensors:
      solar_total:
        friendly_name: Solar total
        unit_of_measurement: kWh
        value_template: "{{ (states('sensor.sofar_cumulative_production') | float) }}"
        device_class: energy
      solar_today:
        friendly_name: Solar today
        unit_of_measurement: kWh
        value_template: "{{ (states('sensor.sofar_daily_production') | float) }}"
        device_class: energy
      solar_now:
        friendly_name: Solar now
        unit_of_measurement: W
        value_template: "{{ (states('sensor.sofar_current_ac_production') | float) }}"
        device_class: power
      total_ac_now:
        friendly_name: Total AC now
        unit_of_measurement: W
        value_template: "{{ (states('sensor.sofar_current_ac_production') | float) }}"
        device_class: power

      # Calculate power in and out
      battery_in:
        friendly_name: Battery in
        unit_of_measurement: W
        value_template: >
          {% if (states('sensor.solax_batpower') | float ) > 0  %}
            {{ (states('sensor.solax_batpower') | float | abs) }}
          {% else %}
            0
          {% endif %}
      battery_out:
        friendly_name: Battery out
        unit_of_measurement: W
        value_template: >
          {% if (states('sensor.solax_batpower') | float ) < 0  %}
            {{ (states('sensor.solax_batpower') | float | abs) }}
          {% else %}
            0
          {% endif %}
      house_load:
        friendly_name: House Load
        value_template: "{{ (states('sensor.solax_feedinpowerm2') | float) + (states('sensor.solax_ac') | float) - (states('sensor.solax_feedin') | float) }}"
        unit_of_measurement: W
        device_class: power
      solar_utilisation:
        friendly_name: Solar Utilisation
        value_template: "{{ (states('sensor.generation_to_house') | float) + (states('sensor.battery_out') | float) }} "
        unit_of_measurement: W
        device_class: power
      generation_to_house:
        friendly_name: Generation to House
        value_template: >
          {% if (states('sensor.sofar_current_ac_production') | float ) > 0  %}
            {{ ((states('sensor.sofar_current_ac_production') | float )) - (states('sensor.battery_in') | float ) - (states('sensor.grid_out') | float ) }}
          {% else %}
            0
          {% endif %}
        device_class: power
        unit_of_measurement: W

      # Grid power in and out
      grid_out:
        friendly_name: Grid out
        unit_of_measurement: W
        value_template: >
          {% if (states('sensor.solax_feedin') | float ) > 0  %}
            {{ (states('sensor.solax_feedin') | float | abs)}}
          {% else %}
            0
          {% endif %}
      grid_in:
        friendly_name: Grid in
        value_template: >
          {% if (states('sensor.solax_feedin') | float ) < 0  %}
            {{ (states('sensor.solax_feedin') | float | abs) }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: W

  # Integrating Export and Import Grid
  - platform: integration
    source: sensor.grid_in
    name: total_grid_in
    unit_prefix: k
    unit_time: h
    round: 2
    method: left
  - platform: integration
    source: sensor.grid_out
    name: total_grid_out
    unit_prefix: k
    unit_time: h
    round: 2
    method: left
  - platform: integration
    source: sensor.battery_in
    name: total_battery_in
    unit_prefix: k
    unit_time: h
    round: 2
    method: left
  - platform: integration
    source: sensor.battery_out
    name: total_battery_out
    unit_prefix: k
    unit_time: h
    round: 2
    method: left
  - platform: integration
    source: sensor.house_load
    name: total_house_load
    unit_prefix: k
    unit_time: h
    round: 2
    method: left
  - platform: integration
    source: sensor.solar_now
    name: total_solar
    unit_prefix: k
    unit_time: h
    round: 2
    method: left
  - platform: integration
    source: sensor.solar_utilisation
    name: total_solar_utilisation
    unit_prefix: k
    unit_time: h
    round: 2
    method:
      left

utility_meter:
  daily_grid_in:
    source: sensor.grid_in
    cycle: daily
  daily_grid_out:
    source: sensor.grid_out
    cycle: daily
  daily_battery_in:
    source: sensor.battery_in
    cycle: daily
  daily_battery_out:
    source: sensor.battery_out
    cycle: daily
  daily_house_load:
    source: sensor.house_load
    cycle: daily
  daily_solar_generation:
    source: sensor.solar_now
    cycle: daily
  daily_solar_utilisation:
    source: sensor.solar_utilisation
    cycle: daily