type: custom:auto-entities
card:
  type: entities
  title: Afvalwijzer
filter:
  exclude:
    - options: {}
      entity_id: sensor.afvalwijzer_notifications
    - options: {}
      entity_id: sensor.afvalwijzer_next_type
    - options: {}
      entity_id: sensor.afvalwijzer_tomorrow
    - options: {}
      entity_id: sensor.afvalwijzer_next_in_days
    - options: {}
      entity_id: sensor.afvalwijzer_today
    - options: {}
      entity_id: sensor.afvalwijzer_day_after_tomorrow
    - options: {}
      entity_id: sensor.afvalwijzer_next_date
    - options: {}
      entity_id: sensor.afvalwijzer_pbd_pmd
  include:
    - options:
        type: custom:template-entity-row
        state: >
          {% set day_month = as_timestamp(strptime(states(config.entity),'%Y-%m-%d',states(config.entity))) | timestamp_custom('%-d') %} 
          {% set month = as_timestamp(strptime(states(config.entity),'%Y-%m-%d',states(config.entity))) | timestamp_custom('%B') %} 
          {% set maanden =
              {'January': 'Januari',
              'February': 'Februari',
              'March': 'Maart',
              'April': 'April',
              'May': 'Mei',
              'June': 'Juni',
              'July': 'Juli',
              'August': 'Augustus',
              'September': 'September',
              'October': 'Oktober',
              'November': 'November',
              'December': 'December'} %} 
          {% set maand = maanden[month] if month in maanden else month %}  
          {% set phrase = day_month + ' ' + maand %}  
          {{phrase}}
        secondary: >
          {% set count = state_attr(config.entity,'days_until_collection_date') | int %}  
          {% set day = as_timestamp(strptime(states(config.entity),'%Y-%m-%d',states(config.entity))) | timestamp_custom('%A') %} 
          {% set dagen =
            {'Monday': 'Maandag',
            'Tuesday': 'Dinsdag',
            'Wednesday': 'Woensdag',
            'Thursday': 'Donderdag',
            'Friday': 'Vrijdag',
            'Saturday': 'Zaterdag',
            'Sunday': 'Zondag'} %}
          {% set dag = dagen[day] if day in dagen else day %}  
          {% set unit = 'Dag' if count == 1 else 'dagen' %}
          {% if count >= 27 %} 
             {% set phrase = dag + ' over 4 weken' %}  
             {% elif count >= 20 %} {% set phrase = dag + ' over 3 weken' %}  
             {% elif count >= 13 %} {% set phrase = dag + ' over 2 weken' %}  
             {% elif count >=  7 %}  {% set phrase = 'Volgende week ' + dag %}  
             {% elif count >=  3 %}  {% set phrase = 'Komende ' + dag %}  
             {% elif count ==  2 %}  {% set phrase = dag + ', overmorgen' %}  
             {% elif count ==  1 %}  {% set phrase = 'morgen, ' + dag %}  
             {% else %} {% set phrase = 'Vandaag, ' + dag %} 
          {% endif %} 
          {{phrase}}
      entity_id: sensor.afvalwijzer_*
sort:
  attribute: days_until_collection_date
  method: attribute
  numeric: true
