Template light receiving invalid color temperature of 0

I’m trying to get rid of this error in my log:
[homeassistant.components.template.light] Received invalid color temperature : 0. Expected: 0-500

I think I narrowed the problem down to my template lights, particularly the setting for temperature_template. I’ve been trying to fix the error, but no luck so far. This is my latest attempt:

temperature_template: >-
  {% if state_attr('light.keukentafel','color_temp') == 'None' %}
  {{ states('sensor.colortemperature')|int if states('sensor.colortemperature') != 'None' else 330 }}
  {% else %}
  {{ state_attr('light.keukentafel','color_temp') | int }}
  {% endif %}

I think the errors occurs because both light.keukentafel and sensor.colortemperature are not available yet at startup. So I was trying to compensate for that, but I just keep adding if-statements without any success.

How can I get rid of that log error?

Can anyone help me to get rid of this error?

Thanks in advance!

My work around was to basically set the temperature_template to the light’s min_mireds if it was None.

"temperature_template:  {{ state_attr('light.office', 'color_temp') | int if state_attr('light.office', 'color_temp') | int > state_attr('light.office', 'min_mireds') | int else state_attr('light.office', 'min_mireds') | int }}"

The temperature_template has to be between min_mireds and max_mireds

def _update_temperature(self, render):
        """Update the temperature from the template."""

        try:
            if render in ("None", ""):
                self._temperature = None
                return
            temperature = int(render)
            if self.min_mireds <= temperature <= self.max_mireds:
                self._temperature = temperature
            else:
                _LOGGER.error(
                    "Received invalid color temperature : %s. Expected: 0-%s",
                    temperature,
                    self.max_mireds,
                )
                self._temperature = None
        except ValueError:
            _LOGGER.error(
                "Template must supply an integer temperature within the range for this light, or 'None'",
                exc_info=True,
            )
            self._temperature = None