Split a sensor in two template sensors

Hey everyone!

I’ve been searching the community for a few days and can’t really find and help or a push in the right direction.

I have a sensor (sensor.batterij_input_output) that shows the input (= positive value) and output (= negative value) of my battery. I want to have this split in two sensors. So I have a battery_input and battery_output sensor.

I know that I have to use a template sensor for this, but as said before I can’t find any more information…

Thanks in advance!

Post the sensor entity id and its actual state from Developer Tools / States.

When you have output, what should the input sensor read? Presumably zero?

The state always updates every 5 seconds. It doesn’t have a entity id, because I get this sensor through modbus tcp from my victron.

unit_of_measurement: W
friendly_name: Batterij input/output

@nickrout Yes, the value should then read zero.

I just realised the entity_id is in your original post ( sensor.batterij_input_output ).

template:
  - sensor:
      - name: "Battery Input"
        unit_of_measurement: "A"
        state: >
          {% if states('sensor.batterij_input_output')|float >= 0 %}
            {{ states('sensor.batterij_input_output') }}
          {% else %}
            0
          {% endif %}
      - name: "Battery Output"
        unit_of_measurement: "A"
        state: >
          {% if states('sensor.batterij_input_output')|float < 0 %}
            {{ -1 * states('sensor.batterij_input_output')|float }}
          {% else %}
            0
          {% endif %}

This shows both sensors (input and output) as positive numbers. If you want the output sensor to be negative just remove -1 * from the battery output template.

3 Likes

Works great! Thanks for the help!