One Entity divided in two

Hello everyone,

I’m new to this forum and also to HomeAssistant, so I’m still trying to find my way around. I recently started using HomeAssistant and would now like to integrate the values I’m reading from my smart meter into the Energy Dashboard.

Currently, I’m feeding energy into the grid because I’m producing more than I consume. Here’s my challenge: I have an entity that shows positive values for consumption and negative values for energy fed into the grid. Now, I’d like to split this entity into two separate entities:

  • One entity should always display positive values and only be populated when the main entity has negative values (i.e., when feeding energy into the grid).
  • The other entity should also always display positive values and only be populated when the main entity has positive values (i.e., during consumption).

I hope my explanation is clear, and I’d appreciate any tips or guidance you can provide.

Thank you in advance!

My configuration.yaml looks at the moment like this:

template:
  - sensor:
    # Stromzähler aktuell
      - name: "Stromzaehler_Aktuell"
        unique_id: "Stromzaehler_Aktuell"
        unit_of_measurement: 'Wh'
        device_class: "energy"
        state_class: "total_increasing"
        state: >-
            {{states('sensor.tasmota_power_Cur')| float(0) }}
  - sensor:
    # Stromzähler Einspeisung
      - name: "Stromzähler Einspeisung"
        unique_id: "StromEinspeisung"
        unit_of_measurement: 'Wh'
        device_class: "energy"
        state_class: "total_increasing"
        state: >-
            {% if states('sensor.tasmota_power_Cur')|float(0) <= 0 %}
              {{ states('sensor.tasmota_power_Cur')|float | abs }}
            {% else %}
              0
            {% endif %}
  - sensor:
    # Stromzähler Verbrauch
      - name: "Stromzähler Verbrauch"
        unique_id: "StromVerbrauch"
        unit_of_measurement: 'Wh'
        device_class: "energy"
        state_class: "total_increasing"
        state: >-
          {% if states('sensor.tasmota_power_Cur')|float(0) >= 0 %}
            {{ states('sensor.tasmota_power_Cur')|float | abs }}
          {% else %}
            0
          {% endif %}

The status of the enteties looks like this:

You appear to be confusing power and energy. These are different things. Also entity ids do not have capital letters in them. You also need a test for the positive sensor.

template:
  - sensor:
    # Stromzähler aktuell
      - name: "Stromzaehler Aktuell"
        unique_id: "Stromzaehler_Aktuell"
        unit_of_measurement: "W"
        device_class: "power"
        state_class: "measurement"
        state: >
            {% set power = states('sensor.tasmota_power_cur')| float %}
            {{ power if power > 0 else 0 }}
        availability: "{{ has_value('sensor.tasmota_power_cur') }}"
  - sensor:
    # Stromzähler Einspeisung
      - name: "Stromzähler Einspeisung"
        unique_id: "Strom_Einspeisung"
        unit_of_measurement: "W"
        device_class: "power"
        state_class: "measurement"
        state: >
            {% set power = states('sensor.tasmota_power_cur')| float %}
            {{ power|abs if power < 0 else 0 }}
        availability: "{{ has_value('sensor.tasmota_power_cur') }}"

After confirming these sensors work as intended go to Developer Tools → States and fix any listed issues.

template:
  - sensor:
    # Stromzähler Verbrauch
      - name: "Stromzaehler Verbrauch"
        unique_id: "stromzaehler_verbrauch"
        unit_of_measurement: "W"
        device_class: "power"
        state_class: "measurement"
        state: >
            {% set power = states('sensor.tasmota_power_cur')| float %}
            {{ power if power > 0 else 0 }}
        availability: "{{ has_value('sensor.tasmota_power_cur') }}"
  - sensor:
    # Stromzähler Einspeisung
      - name: "Stromzähler Einspeisung"
        unique_id: "Strom_Einspeisung"
        unit_of_measurement: "W"
        device_class: "power"
        state_class: "measurement"
        state: >
            {% set power = states('sensor.tasmota_power_cur')| float %}
            {{ power|abs if power < 0 else 0 }}
        availability: "{{ has_value('sensor.tasmota_power_cur') }}"

This is now written in my configuration.yaml

The Developer Tolls tells me this:


But the State show me this: unavailable

And within the Entity Menu I can see this Information: Not avalable

Settings → System → Logs for related errors.

Also go to Developer Tools → Templates and copy what this returns:

{{ states('sensor.tasmota_power_cur') }}

Thanks. There was an error with the naming. Now the Numbers in the entities are right. but i can’t see them in the Energy Dashboard. I’m one step further but i think there a re still steps to do :wink:

Because they are power sensors. Not energy sensors. Which is what the energy dashboard uses.

If Tasmota does not supply energy sensors (I’m guessing it should) then you can use the integral helper to convert power into energy. Make sure to use method:left to minimise approximation errors.