Help with energy sensor templates - Negative to positive

Now that you have formatted it (thanks) I can easily show you an example:

template:
  - sensor:  
      - name: Grid Power In
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: >
          {% if states('sensor.utility_meter_123_1d') | float(0) >= 0 %}
            {{ states('sensor.utility_meter_123_1d') | float(0) }}
          {% else %}
            0
          {% endif %}
        availability: "{{ has_value('sensor.utility_meter_123_1d') }}"

      - name: Grid Power Out
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: >
          {% if states('sensor.utility_meter_123_1d') | float(0) <= 0 %}
            {{ states('sensor.utility_meter_123_1d') |float | abs }}
          {% else %}
            0
          {% endif %}
        availability: "{{ has_value('sensor.utility_meter_123_1d') }}"
1 Like