Sensor if state problem

Hello, I have the following problem.

I have a Shelly 4PM that controls 3 relays (heating rod).
Since the Shelly only controls the relays, I don’t see the power consumption and can’t work with it.

I know the watts per channel, so I would like to build 3 template sensors that have exactly the watts (500W, 1000W, 2000W) as the state when the respective Shelly switch is “on”

like this: can anybody help? thx

- sensor:
      - name: "shellypro 500W power consumption"
        unique_id: "shellypro_500W_power_consumption"
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement
        state: >
          {% set switch0 = states('switch.shellypro4pm_500') | float %}
          {% if switch0 'on' } 500
          {% else %} 0
          {% endif %}