Order sensors by value

Hello,
I created a garbage calender:


This is the code:

title: Müllabfuhr
type: vertical-stack
in_card: true
cards:
  - type: custom:button-card
    entity: sensor.abfall_bio
    layout: icon_name_state2nd
    show_label: true
    label: |
      [[[
        var days_to = entity.state.split("|")[1]
        if (days_to == 0)
        { return "Heute" }
        else if (days_to == 1)
        { return "Morgen" }
        else
        { return "in " + days_to + " Tagen" }
      ]]]
    show_name: true
    name: Abholung des Bioabfalls
    state:
      - color: red
        operator: template
        value: '[[[ return entity.state.split("|")[1] == 0 ]]]'
      - color: orange
        operator: template
        value: '[[[ return entity.state.split("|")[1] == 1 ]]]'
      - value: default
  - type: custom:button-card
    entity: sensor.abfall_restmuell
    layout: icon_name_state2nd
    show_label: true
    label: |
      [[[
        var days_to = entity.state.split("|")[1]
        if (days_to == 0)
        { return "Heute" }
        else if (days_to == 1)
        { return "Morgen" }
        else
        { return "in " + days_to + " Tagen" }
      ]]]
    show_name: true
    name: Abholung des Restabfalls
    state:
      - color: red
        operator: template
        value: '[[[ return entity.state.split("|")[1] == 0 ]]]'
      - color: orange
        operator: template
        value: '[[[ return entity.state.split("|")[1] == 1 ]]]'
      - value: default
  - type: custom:button-card
    entity: sensor.abfall_gelbersack
    layout: icon_name_state2nd
    show_label: true
    label: |
      [[[
        var days_to = entity.state.split("|")[1]
        if (days_to == 0)
        { return "Heute" }
        else if (days_to == 1)
        { return "Morgen" }
        else
        { return "in " + days_to + " Tagen" }
      ]]]
    show_name: true
    name: Abholung des Plastikabfalls
    state:
      - color: red
        operator: template
        value: '[[[ return entity.state.split("|")[1] == 0 ]]]'
      - color: orange
        operator: template
        value: '[[[ return entity.state.split("|")[1] == 1 ]]]'
      - value: default
  - type: custom:button-card
    entity: sensor.abfall_papier
    layout: icon_name_state2nd
    show_label: true
    label: |
      [[[
        var days_to = entity.state.split("|")[1]
        if (days_to == 0)
        { return "Heute" }
        else if (days_to == 1)
        { return "Morgen" }
        else
        { return "in " + days_to + " Tagen" }
      ]]]
    show_name: true
    name: Abholung des Papierabfalls
    state:
      - color: red
        operator: template
        value: '[[[ return entity.state.split("|")[1] == 0 ]]]'
      - color: orange
        operator: template
        value: '[[[ return entity.state.split("|")[1] == 1 ]]]'
      - value: default

Now I want it to be sorted by days, so that the nearest is always a the top.
Is there a way to do this? In didn’t find anything usefull until now.

I do not think it is possible to sort with the individual button cards you defined.
(There is a missing connection between the states of the entities and which button card they belong to and which “group” of button cards you would like to sort).

I have it solved myself by using the custom:auto-entities card.
(Colors of the icons are set within the customize domain/yaml)

type: custom:auto-entities
card:
  type: entities
  title: Müllleerung
filter:
  include:
    - entity_id: "sensor.abfall_*"
  exclude:
    - entity_id: "sensor.abfall_next"
sort:
  method: state

image