Energy Management in Home Assistant

I still need to test mine more, after some searching though I found this;

This is mine;

template:
#Split power in and out of battery
  - sensor:
      - name: "Battery input power"
        unit_of_measurement: "W"
        state: >
          {% if states('sensor.battery_power')|float >= 0 %}
            {{ states('sensor.battery_power') }}
          {% else %}
            0
          {% endif %}
      - name: "Battery output power"
        unit_of_measurement: "W"
        state: >
          {% if states('sensor.battery_power')|float < 0 %}
            {{ -1 * states('sensor.battery_power')|float }}
          {% else %}
            0
          {% endif %}

Then I do the normal utility meter

Edit: Seems to be working well.
image