I used wrong MQTT sensors for the battery. Now got it right i hope
- name: "MQ SEN Akku LadeEnergie"
unique_id: msa_battery_charge_energy
state_topic: "homeassistant/sensor/MSA-280425440006/device/state"
unit_of_measurement: "Wh"
device_class: energy
state_class: total_increasing
value_template: >
{{ (value_json.grid | selectattr('type','equalto','inv') | list | first).etin | round(0) }}
- name: "MQ SEN Akku EntladeEnergie"
unique_id: msa_battery_discharge_energy
state_topic: "homeassistant/sensor/MSA-280425440006/device/state"
unit_of_measurement: "Wh"
device_class: energy
state_class: total_increasing
value_template: >
{{ (value_json.grid | selectattr('type','equalto','inv') | list | first).etout | round(0)}}
had to fix the grid sensors, wrong unit
- sensor:
- name: "CALC SEN Netzbezug Energie"
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
state: >
{% set new = states('sensor.tasmota_emh_e_in') | float(999999) %}
{% set old = this.state | float(0) %}
{% if new == 999999 or new > 10000 %}
{{ old }}
{% else %}
{% if new < old %}
{{ old }}
{% else %}
{% if new > old + 2000 %}
{{ old }}
{% else %}
{{ new }}
{% endif %}
{% endif %}
{% endif %}