Template Sensor Error No Default Was Specified

I’m a little out of practice with HA so pardon me if this is super obvious… I have had templates in the past where I have had to add (0) or default and such… and some pertaining to time which I know I have fixed with now() etc… but this template is how Alexa Routines are and have been connected to my HA since way back when… it monitors the brightness of the “Light” which is controlled by the Alexa Routines… Since updating to 2023.11.0 last night I am getting the following error in my log:

2023-11-03 19:09:58.633 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('ValueError: Template error: int got invalid input 'None' when rendering template '{% if states.light.alexa_virtual.attributes.brightness is defined %}
   {{(states.light.alexa_virtual.attributes.brightness|int/255*100)|round}}
{% else %}
   0
{%- endif -%}' but no default was specified') while processing template 'Template<template=({% if states.light.alexa_virtual.attributes.brightness is defined %}
   {{(states.light.alexa_virtual.attributes.brightness|int/255*100)|round}}
{% else %}
   0
{%- endif -%}) renders=36>' for attribute '_attr_native_value' in entity 'sensor.alexa_virtual'

I have tried adding default, float (0) etc, what I could remember and find from previous similar issues. Also this is how it now looks in history since updating:


Here is the template, and suggestions on how to get rid of the error and get it to report 0 when unavailable (or “not defined” rather) again would be appreciated.

####################################################
###   ALEXA DUMMY LIGHT
####################################################
    alexa_virtual:
      friendly_name: Alexa Dummy Sensor
      value_template: >-
         {% if states.light.alexa_virtual.attributes.brightness is defined %}
            {{(states.light.alexa_virtual.attributes.brightness|int/255*100)|round}}
         {% else %}
            0
         {%- endif -%}

The brightness attribute is always defined now. It has the value None when the light is off. So you can simplify your template to this:

    alexa_virtual:
      friendly_name: Alexa Dummy Sensor
      value_template: "{{ (states.light.alexa_virtual.attributes.brightness|int(0)/255*100)|round }}"

Though it would be better like this:

    alexa_virtual:
      friendly_name: Alexa Dummy Sensor
      value_template: "{{ (state_attr('light.alexa_virtual','brightness')|int(0)/255*100)|round }}"

https://www.home-assistant.io/docs/configuration/templating/#states