How to create statistic for charged and discharged energy

My Homebattery gives me SoC and Power values. Via integral I have generated the Energy value.

Goal is to use this in the enery dashboard but the dashbord editor requests statistics for “Energy charged into the battery” and “Energy discharged from the battery” See the red markings in the hardcopy.

Means: I have to separate the positive and negative power into two Energy integrals. How can I do this?

Environment: Home Assistant Green with OS v16.3 (and absolute HA beginner).
Of cause the solution is here in the community but I have been searching for several days with no success.

Note that you need to do that for the power sensors, and then you can do two integrals sensors each based on one of those two resulting sensors.

I have inserted the YAML part with 3 modifications into the file /homeassistant/customize.yaml

  • unit of measurement : W
  • change the name “Grid” to “Battery”
  • replace sensor.grid_power with sensor.evcc_battery_power

In the file editor it looks like this

When I make the YAML check there is an error message for line 11. Here the whole error message

Configuration errors

Invalid config for ‘homeassistant’ at customize.yaml, line 11: Entity ID template is an invalid entity ID ‘customize->template’, got [{‘sensor’: [{‘name’: ‘Battery Power In’, ‘unit_of_measurement’: ‘W’, ‘device_class’: ‘power’, ‘state_class’: ‘measurement’, ‘state’: “{% if states(‘sensor.evcc_battery_power’) | float(0) >= 0 %}\n {{ states(‘sensor.evcc_battery_power’) | float(0) }}\n{% else %}\n 0\n{% endif %}\n”, ‘availability’: “{{ has_value(‘sensor.evcc_battery_power’) }}”}, {‘name’: ‘Battery Power Out’, ‘unit_of_measurement’: ‘W’, ‘device_class’: ‘power’, ‘state_class’: ‘measurement’, ‘state’: "{% if states('sensor.ev…

Do you have any idea for the reason of this error message?

I have deleted line 11 and the “-” in line 12 → no error message for the YAML check.
But I cannot find the new sensors. Where can I find them?

None of that goes into customize.yaml.

It either goes into configuration.yaml, or into a separate file depending on how you split your configuration.

But since writing template sensors in YAML appears to be new to you, I would recommend not messing with the YAML files and instead just create the sensors using the UI. The second post in that link shows that method.

All is new for me. Therefore I keep on the first / YAML path.
Moving the code to the file you told me works - thank you.

1 Like