Template Assistance - Exclude items from list

I’m using the afvalinfo integration which currently gives me 6x sensors:

  • 4x sensor.afvalinfo_home_xxxx which basically shows the date that these types of trash items will be collected, as well as some extra attributes including days_until_collection_date
  • 2x sensors (trash_type_today / trash_type_tomorrow) which give the trash type being collected either today or tomorrow.

Right, then I have this template below which creates a sensor to show the next trash type (in general) which will be collected.

However, what I’m actually looking for is the next item…. but excluding today and tomorrow.

{% set ns = namespace(minimum=365) %}
{% set list = ['gft', 'pbd', 'papier', 'restafval'] %}
{%- for l in list %}
{%- set days = state_attr('sensor.afvalinfo_home_' ~l, 'days_until_collection_date')%}
{%- if days != None and days < ns.minimum %}
{%- set ns.minimum = days %}
{%- endif %}
{%- endfor %}
{%- for l in list %}
{%- set days = state_attr('sensor.afvalinfo_home_' ~l, 'days_until_collection_date')%}        
{%- if days == ns.minimum %}
{{ list[loop.index0] }}
{%- endif %}
{%- endfor %}
{% set s_list = ['sensor.afvalinfo_home_gft', 'sensor.afvalinfo_home_pbd',
'sensor.afvalinfo_home_papier', 'sensor.afvalinfo_home_restafval'] %}
{{ (expand(s_list) | selectattr('attributes.days_until_collection_date', 'gt', 1) 
| sort(attribute = 'attributes.days_until_collection_date') | map(attribute='entity_id') | first).split('_')[-1] }}