Halving an energy sensor and using in the Energy dashboard

Hi All,

I’m a relative newbie to HomeAssistant, abolsutely blown away by it’s capability.

The reason I set it up is to help monitor my new solar array and batteries, and if I’m feeling confident enough use HA to control the mode of my inverter (for the time being I’m focussing on a read only set up)

I have 2x Growatt MIN-3600 inverters connected to Solar Assistant pumping data into HA via MQTT, so far things on the HA side going great, I even managed to set up a realtime energy dashboard.

My issue is that the GRID values coming from Solar Assistant across the two inverters needs to be the average of the two inverters, not the sum. I’ve asked Solar Assistant if they can do anything about this, but in the meantime I thought I’d try and see what I could do to mitigate in HA.

I managed to create the grid (avg) sensor shown in the above image, works fine!

However, I want to be able to do the same for the day total figure that gets used on the energy dashboard.As all of my totals are ~double what they should be…

I’ve tried creating a new sensor with a simple division in please but this isn’t selectable on the energy dashboard as an input.

- platform: template
  sensors:
    correctedgridimport:
      friendly_name: Grid Import
      value_template: "{{ states('sensor.grid_energy_in') | float(0) / 2 }}"
      unit_of_measurement: "kW"

Question

What is the best way of me taking the exsiting grid_energy_in & grid_energy_out figures, dividing them by two, and having them still work as inputs within the energy dashboard.

Any help would be greatly appreciated.

Thank you!

You need to add the correct state and device class to your template sensor. You should also be using the new sensor format and add an availability template to prevent strange spikes in energy if your sensor becomes unavailable. Like this:
(configuration.yaml)

template:
  - sensor:
      - name: Corrected Grid Import
        state: "{{ states('sensor.grid_energy_in') | float(0) / 2 }}"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        availability: "{{ states('sensor.grid_energy_in') | is_number }}"

Edit: just noticed you had the wrong unit too. kWh for energy, not kW which is a measure of power.

This is awsome, thankyou so much!

1 Like