Custom sensor won't get recognized

Hi community,
I’m trying to create a custom sensor for my solar rectifier so that it shows “0” Watts during the night when the rectifier is in a not available state.

sensor:
  - platform: template
    sensors:
      pv_leistung_korrigiert:
        friendly_name: "PV Leistung (Korrigiert)"
        unique_id: "pv_leistung_korrigiert"
        unit_of_measurement: "W"
        device_class: power
        value_template: >-
          {% if states('sensor.solar_gesamtleistung') in ['unknown', 'unavailable', 'none'] %}
            0
          {% else %}
            {{ states('sensor.solar_gesamtleistung') | float }}
          {% endif %}

Config check is fine. Nevertheless, the sensor “pv_leistung_korrigiert” is not available when I try to add it to my dashboard as an entity.
What am I missing here?

Thanks for any help

Checked the logs for errors?

You should not use the legacy sensor configuration format.
Rewrite the sensor to use the modern format.

logs are good.
I rewrote it like this:

template:
  - sensor:
      - name: "PV Leistung (Korrigiert)"
        unique_id: "pv_leistung_korrigiert"
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement
        state: >
          {% set value = states('sensor.solar_gesamtleistung') %}
          {% if value in ['unknown', 'unavailable', 'none'] %}
            0
          {% else %}
            {{ value | float(0) | int }}
          {% endif %}

which works fine.
Thanks for getting back!