Alternative for legacy "availability_template" sensor option in modern configuration format?

When creating sensors it happens that a value is unavailable and the calculated sensor value is crap. I read that there is the availability_template but I looks like that this is only available in the legacy configuration format. What is the alternative for it in the recommended modern configuration format?

Right now I solve it the following way but I hope there is a smarter solution.

template:
  - sensor:
      - name: "COP heating last 24h"
        unit_of_measurement: 
        state: >
          {% if states('sensor.delta_heating_supplied_24h') in ['unavailable', 'unknown', 'none'] %}
            {{ states('sensor.COP_heating_last_24h') }}
          {% elif states('sensor.delta_heating_consumed_compressor_24h') in ['unavailable', 'unknown', 'none'] %}
            {{ states('sensor.COP_heating_last_24h') }}
          {% elif states('sensor.delta_heating_consumed_electrical_24h') in ['unavailable', 'unknown', 'none'] %}
            {{ states('sensor.COP_heating_last_24h') }}
          {% else %}
            {% set delta_heating_supplied_24h = states('sensor.delta_heating_supplied_24h') | float %}
            {% set delta_heating_consumed_compressor_24h = states('sensor.delta_heating_consumed_compressor_24h') | float %}
            {% set delta_heating_consumed_electrical_24h = states('sensor.delta_heating_consumed_electrical_24h') | float %}          

            {{ (delta_heating_supplied_24h / (delta_heating_consumed_compressor_24h + delta_heating_consumed_electrical_24h)) | round(2, default=0) }}
          {% endif %}

It is available in the new format. It is called

availability: "{{ your template here }}"

https://www.home-assistant.io/integrations/template/#availability

Here’s an example I wrote not long ago: Mah support on energy dashboard - #2 by tom_l

Great! Exactly what I was looking for.