Define sensor and change its values

Can someone help me? I have a sensor defined via template. By default, it shows “ON” or “OFF”. but I would like to change ON → DHW, and OFF → Space. I am unable to figure out how to define it all in one template sensor. Here is my template now:

- platform: template
  sensors:
    espaltherma_3wv:
      friendly_name: "Altherma 3Way Valve"
      value_template: "{{ state_attr('sensor.althermasensors','3way valve(On:DHW_Off:Space)') }}"
value_template: "{{ 'DHW' if is_state_attr('sensor.althermasensors','3way valve', 'ON') else 'Space' }}"
1 Like

Thanks a lot!