Create new sensor for energy board with condition

Hello all,
I am still quite new to HA and wanted to add my Victron system to the energy dashboard.
I am failing due to the following condition.
I would like to add my battery and have two entities from Victron for this.

(without the sensor.victron_system_battery_soc)

What I can’t do is to create a new sensor in the dashboard that will take the value from “Energy flowing into the battery” when the value from my second sensor is “CHARGING”.

As a second sensor in the energy dashboard I wanted to create one “Energy coming out of the battery” when the value is “DISCHARGING”.

I fail when creating a template sensor because I can’t get the if state condition right :frowning:

Thank you for the help.
Greetings
Thorsten

Hi again,
i try now this code in template.yaml

But after check configs, i get this error :
Logger: homeassistant.config
Source: config.py:868
First occurred: 12:50:15 (4 occurrences)
Last logged: 13:09:51

  • Invalid config for [template]: [Batterie_Laden] is an invalid option for [template]. Check: template->sensor->0->Batterie_Laden. (See /config/template.yaml, line 13).
  • Invalid config for [template]: [entity_id] is an invalid option for [template]. Check: template->sensor->0->entity_id. (See /config/template.yaml, line 12).
  • Invalid config for [template]: [entity_id] is an invalid option for [template]. Check: template->sensor->0->entity_id. (See /config/template.yaml, line 0).
  • Invalid config for [template]: [platform] is an invalid option for [template]. Check: template->sensor->0->platform. (See /config/configuration.yaml, line 16).

Any idea whats wrong ? Maybe it is because the unit_of_measurement for the battery state is not defined ?

Thanks for help :slight_smile:

Cheers
Thorsten

Batterie_Laden: should be batterie_laden:

Do not use capital letters in slugs.

Also please do not post pictures of text. Paste the text and format it correctly for the forum (see the FAQ).

Edit: actually looking at the file that config is in you may have much bigger issues. Show the !include for that file.

Thank you for the answer.
I have now changed capital letters.
I had copied the image because I noticed when I copied the text from the yaml, wrong characters crept in.
In future I will copy the text according to the FAQ :slight_smile:

What do you mean by the !include ?
it is in my configuration.yaml , this is a part of it

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml
template: !include template.yaml

Yeah. That’s what I suspected.

You are using the new template sensor format (good) but you have configured it using the old format (won’t work).

Look at the example here and compare it to yours:

https://www.home-assistant.io/integrations/template/#state-based-template-binary-sensors-buttons-numbers-selects-and-sensors

Hello,

i am german, excuse my bad english. I have a power Sensor, kWh.
And i copy this sensor into two virtual sensors. Depend on a switch = boolean.

If the switch is True store enengy in virtual sensor 01, if the switch is False store energy in virtual sensor 2.

> - name: "Strom vom Netz"
>        unique_id: strom_vom_netz
>        icon: mdi:pulse  
>        unit_of_measurement: 'kWh'
>        device_class: energy
>        state_class: total
>        state: >
>          {% if is_state('switch.stromzkeller_laufrichtung', 'on') %}    
>          {{ states('stromzähler_gesamt') | float }}
>          {% else %}
>          0
>          {% endif %}
> 
>      - name: "Strom ins Netz"
>        unique_id: strom_ins_netz
>        icon: mdi:pulse  
>        unit_of_measurement: 'kWh'
>        device_class: energy
>        state_class: total
>        state: >
>          {% if is_state('switch.stromzkeller_laufrichtung', 'off') %}    
>          {{ states('stromzahler_gesamt') | float }}
>          {% else %}
>          0
>          {% endif %}

i also have a file template.yaml an in configuration yaml → template: !include template.yaml

it works if i take a real sensor = stromzahler_gesamt must be a real sensor.

.