Home Assistant: Convert a negative value to a positive value

My PV system delivers a negative watt value as production at the Shelly. As I didn’t want to change it in the Shelly, I converted this value in the Home Assistant as follows:

Bash
template:
  - sensor:
      - name: "bkw1.watt"
        unique_id: bkw1.watt
        unit_of_measurement: "W"
        state: >
          {% set wert = states('sensor.sensor_shelly_bkw1_power') | float %}
          {{ -wert if wert < 0 else wert }}