Zigbee offline devices Automation

Hi guys.
I have an automation that detects which Zigbee devices have not been transmitting for x minutes.
For some time now, the message no longer works, or rather it no longer shows me the offline devices (only the simple text part arrives “OFFLINE Zigbee Devices:”).
This is the Action of automation:

  action:
    - service: notify.notification_service
      data:
        title: Z2M DEVICE ALERT
        message: >
          OFFLINE Zigbee Devices:
          {% macro GetDroppedZigbee() -%}
          {% for state in states.sensor -%}
          {%- if ("linkquality" in state.name and state_attr(state.entity_id, "last_seen") != None and (as_timestamp(now()) - as_timestamp(state_attr(state.entity_id, "last_seen")) > (5 * 60 * 60))) -%}
          {{ state.name | regex_replace(find=' linkquality', replace='', ignorecase=False) }} -- Da {{ ((as_timestamp(now()) - as_timestamp(state.attributes.last_seen)) / (3600)) | round(0) }} ore {{- '\n' -}}
          {%- endif -%}
          {%- endfor %}
          {%- endmacro -%}
          {{ GetDroppedZigbee() }}


I don’t understand why it doesn’t work anymore, it always worked very well.
I use Zigbee2mqtt, and the last_seen option is enabled.
Thanks

Why not enable availability? Then the device will become unavailable, and that will simplify things.

I don’t remember why I used this method, maybe it didn’t work well with some devices.
It has always worked with my template, now the template in the message no longer works. In your opinion, is there anything that has changed in the new versions?
Thanks

Availability works with all devices.

Unsure, but you should check whether the linkquality entities are enabled.

I enabled Availability from Zigbee2mqtt and it works, but among the entities of the individual devices I don’t have any entity that indicates this parameter.
How do I put this in the notification automation?

The entities become unavailable - there’s no additional entity.

You can use that with a template sensor or automation as you want.