Convert value ‘unavailable’ to 0

template:
  # Solar production - Prevent showing unavailable instead of 0
  - sensor:
      - name: "Solar Current Power"
        unit_of_measurement: "W"
        state: "{{ 0 if states('sensor.on_grid_l1_power') == 'unavailable' else states('sensor.on_grid_l1_power' ) }}"