Solar net balance / Current solar balance / Running energy balance

lenemeth had a similar post a while back but did not share the actual calculation, so I would do so now.

This is useful for those who want to keep an eye on their current solar/grid balance. It’s a very simple calculation from two sensors. I took the values from my electricity meter (P1 port, slimmelezer) that count the current import and export for all tariffs cumulated, and then went and created a new sensor.

# Calculate Remaining Power
- platform: template
  sensors:
      remainingpower:
        value_template: "{{ (( states('sensor.hatasos_export_energia_a') | float) - ( states('sensor.hatasos_import_energia_a') | float) + XXXXXXX) |  round(3) }}"
        unit_of_measurement: 'kWh'
        device_class: energy
        friendly_name: Net Electricity

XXXX is the balance value that must be calculated beforehand if you start running the script later than the measurement cycle starts. Addition for me, because we ended the last cycle in energy “debt” but modify however necessary.

Put this in your config.yaml file, or if you have a separate one for sensors, there. Once you have the new sensor up and running, it’s easy to make a Lovelace card out of it.

Unfortunately it’s not recognized by the energy dashboard, or at least I did not find a way yet.