TemplateError('UndefinedError: None has no element 0') while processing template

After rebooting HA I get the error message because the sensor doesn’t exist yet.

TemplateError('UndefinedError: None has no element 0') while processing template 'Template<template=({{ state_attr('weather.accuweather', 'forecast')[0].temperature }}) renders=4>' for attribute '_attr_available' in entity 'sensor.accuweather_temperatur_vorhersage_morgen'
TemplateError('UndefinedError: None has no element 0') while processing template 'Template<template=({{ state_attr('weather.accuweather', 'forecast')[0].temperature | default(0) }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.accuweather_temperatur_vorhersage_morgen'

Now I wanted to improve this with the availabilty entry. Unfortunately this did not work. What’s wrong with the code?

template:
    sensor:
    - name: "AccuWeather Temperatur Vorhersage Morgen"
      state: "{{ state_attr('weather.accuweather', 'forecast')[0].temperature | default(0) }}"
      availability: "{{ state_attr('weather.accuweather', 'forecast')[0].temperature }}"
      icon: "mdi:thermometer"
      unit_of_measurement: "°C"

Does somebody has any idea?

availability: "{{ state_attr('weather.accuweather', 'forecast')[0].temperature }}"

is assuming that there is at least one entry, which might not be true.
even state can be unknown or undefined

states('weather.accuweather')

Not tested, try something like

availability: >
  {% set forecast = state_attr('weather.accuweather', 'forecast') %}
  {% if forecast is defined and forecast is not none and forecast | length > 0 %}
    true
  {% else %}
    false
  {% endif %}

Bonne journée Olivier et merci pour la solution.

I have tested it. After rebooting HA I no longer have any error messages. In this respect I can confirm that the above code is the solution to the problem.