Convert sensor value from negative to positive value

Hi,

Beginner here…

I have a energy meter thats reads the actual power of my solar panels. However this value is negative. How can I convert this to a positive value?

I have tried the following in configuration.yaml

template:
  - sensor:
      - name: Actual solar power - Dak
        unit_of_measurement: "kWh"
        state: "{{ states ('Solar meter dak (5c2faf0e37dc) Active power') | int *-1}}"

What am I doing wrong?

Thanks

Let’s assume your energy meter is:

sensor.solar_meter_5c2faf0e37dc

You can create a Template Sensor to convert the value of sensor.solar_meter_5c2faf0e37dc to a positive value using the abs filter:

template:
  - sensor:
      - name: Actual solar power - Dak
        unit_of_measurement: "kWh"
        state: "{{ states('sensor.solar_meter_5c2faf0e37dc') | int(0) | abs }}"
3 Likes

Thank you so much for helping me. It works now!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

1 Like