Sensor template - use value from one sensor if associated device is running, use another value if a different device is running

Hi
Trying to create a new temperature sensor that will give the temperature of pool water
I have two pumps associated with the pool - one for the filter and one for the solar heater - these can be running at different times
Have temperature probes installed in the intake on both pumps
Want the combined temperature sensor to work like this:
If the solar pump is running, use the sensor linked to that
Else if the filter pump is running, use the sensor linked to that
Else unavailable or 0 as the water temperature isn’t correct if it isn’t currently flowing from the pool

Tried this so far:

template:
  - sensor:
      - name: "Pool Temperature"
        unit_of_measurement: "°C"
        device_class: temperature
        value_template: >
          {% if states('switch.pool_solar_heating_shelly_1pm', 'on') %}
            sensor.pool_solar_heating_shelly_1pm_temperature
          {% elif states('switch.pool_filter_shelly_1pm', 'on') %}
            sensor.pool_filter_shelly_1pm_temperature
          {% else %}
            0       
          {% endif %}

Get this error in Developer Tools > Template:
TypeError: AllStates.call() takes 2 positional arguments but 3 were given
Any ideas please?

template:
  - sensor:
      - name: "Pool Temperature"
        unit_of_measurement: "°C"
        device_class: temperature
        state: >
          {% if is_state('switch.pool_solar_heating_shelly_1pm', 'on') %}
            {{ states('sensor.pool_solar_heating_shelly_1pm_temperature') }}
          {% elif is_state('switch.pool_filter_shelly_1pm', 'on') %}
            {{ states('sensor.pool_filter_shelly_1pm_temperature') }}
          {% else %}
            0       
          {% endif %}

Thanks for the fast reply! Now working, much appreciated!