Hi there!
I added my own functionality to this component. With this, it’s possible to see the following:
Instead of images for only; today, tomorrow, day after tomorrow. So, with this change, i’ll never see a ‘none’ anymore.
On bug, sometimes the name sensor returns ‘unknown’ After some time or restart it is fixed. Probably because the sensors are created before the afvalwijzer has grabbed the info? Don’t know…
Here’s the ‘sensor’ code:
- platform: template
sensors:
first_trash_date:
value_template: >-
{% set selected_item = 0 %}
{% set gftInDays = state_attr('sensor.afvalwijzer_gft', 'days_until_collection_date') | default(99) %}
{% set papierInDays = state_attr('sensor.afvalwijzer_papier', 'days_until_collection_date') | default(99) %}
{% set pmdInDays = state_attr('sensor.afvalwijzer_pmd', 'days_until_collection_date') | default(99) %}
{% set restAfvalInDays = state_attr('sensor.afvalwijzer_restafval', 'days_until_collection_date') | default(99) %}
{% set daysDutch = ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'] %}
{% set todayDateTime = as_timestamp(now())|int %}
{% set nextInDays = [gftInDays, papierInDays, pmdInDays, restAfvalInDays] %}
{% set sortedNextInDays = nextInDays|sort %}
{% if sortedNextInDays[ selected_item ] == gftInDays %}
{% if (gftInDays <= 2) %}
{{ 'Vandaag' if (gftInDays == 0) else ('Morgen' if (gftInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (gftInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (gftInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (gftInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
{% if sortedNextInDays[ selected_item ] == papierInDays %}
{% if (papierInDays <= 2) %}
{{ 'Vandaag' if (papierInDays == 0) else ('Morgen' if (papierInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (papierInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (papierInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (papierInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
{% if sortedNextInDays[ selected_item ] == pmdInDays %}
{% if (pmdInDays <= 2) %}
{{ 'Vandaag' if (pmdInDays == 0) else ('Morgen' if (pmdInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (pmdInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (pmdInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (pmdInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
{% if sortedNextInDays[ selected_item ] == restAfvalInDays %}
{% if (restAfvalInDays <= 2) %}
{{ 'Vandaag' if (restAfvalInDays == 0) else ('Morgen' if (restAfvalInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (restAfvalInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (restAfvalInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (restAfvalInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
first_trash_name:
value_template: >-
{% set selected_item = 0 %}
{% set trash_gft_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_gft.state, "%d-%m-%Y"))|int %}
{% set trash_papier_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_papier.state, "%d-%m-%Y"))|int %}
{% set trash_pmd_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_pmd.state, "%d-%m-%Y"))|int %}
{% set trash_restafval_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_restafval.state, "%d-%m-%Y"))|int %}
{% set trash_ts_array = [trash_gft_date_ts, trash_pmd_date_ts, trash_papier_date_ts, trash_restafval_date_ts] %}
{% set sorted_trash_ts_array = trash_ts_array|sort %}
{% set selected_timestamp = sorted_trash_ts_array[ selected_item ] %}
{% if (selected_timestamp == trash_papier_date_ts) %}
papier
{% elif (selected_timestamp == trash_pmd_date_ts) %}
pmd
{% elif (selected_timestamp == trash_gft_date_ts) %}
gft
{% elif (selected_timestamp == trash_restafval_date_ts) %}
restafval
{% else %}
geen
{% endif %}
second_trash_date:
value_template: >-
{% set selected_item = 1 %}
{% set gftInDays = state_attr('sensor.afvalwijzer_gft', 'days_until_collection_date') | default(99) %}
{% set papierInDays = state_attr('sensor.afvalwijzer_papier', 'days_until_collection_date') | default(99) %}
{% set pmdInDays = state_attr('sensor.afvalwijzer_pmd', 'days_until_collection_date') | default(99) %}
{% set restAfvalInDays = state_attr('sensor.afvalwijzer_restafval', 'days_until_collection_date') | default(99) %}
{% set daysDutch = ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'] %}
{% set todayDateTime = as_timestamp(now())|int %}
{% set nextInDays = [gftInDays, papierInDays, pmdInDays, restAfvalInDays] %}
{% set sortedNextInDays = nextInDays|sort %}
{% if sortedNextInDays[ selected_item ] == gftInDays %}
{% if (gftInDays <= 2) %}
{{ 'Vandaag' if (gftInDays == 0) else ('Morgen' if (gftInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (gftInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (gftInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (gftInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
{% if sortedNextInDays[ selected_item ] == papierInDays %}
{% if (papierInDays <= 2) %}
{{ 'Vandaag' if (papierInDays == 0) else ('Morgen' if (papierInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (papierInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (papierInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (papierInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
{% if sortedNextInDays[ selected_item ] == pmdInDays %}
{% if (pmdInDays <= 2) %}
{{ 'Vandaag' if (pmdInDays == 0) else ('Morgen' if (pmdInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (pmdInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (pmdInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (pmdInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
{% if sortedNextInDays[ selected_item ] == restAfvalInDays %}
{% if (restAfvalInDays <= 2) %}
{{ 'Vandaag' if (restAfvalInDays == 0) else ('Morgen' if (restAfvalInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (restAfvalInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (restAfvalInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (restAfvalInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
second_trash_name:
value_template: >-
{% set selected_item = 1 %}
{% set trash_gft_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_gft.state, "%d-%m-%Y"))|int %}
{% set trash_papier_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_papier.state, "%d-%m-%Y"))|int %}
{% set trash_pmd_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_pmd.state, "%d-%m-%Y"))|int %}
{% set trash_restafval_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_restafval.state, "%d-%m-%Y"))|int %}
{% set trash_ts_array = [trash_gft_date_ts, trash_pmd_date_ts, trash_papier_date_ts, trash_restafval_date_ts] %}
{% set sorted_trash_ts_array = trash_ts_array|sort %}
{% set selected_timestamp = sorted_trash_ts_array[ selected_item ] %}
{% if (selected_timestamp == trash_papier_date_ts) %}
papier
{% elif (selected_timestamp == trash_pmd_date_ts) %}
pmd
{% elif (selected_timestamp == trash_gft_date_ts) %}
gft
{% elif (selected_timestamp == trash_restafval_date_ts) %}
restafval
{% else %}
geen
{% endif %}
third_trash_date:
value_template: >-
{% set selected_item = 2 %}
{% set gftInDays = state_attr('sensor.afvalwijzer_gft', 'days_until_collection_date') | default(99) %}
{% set papierInDays = state_attr('sensor.afvalwijzer_papier', 'days_until_collection_date') | default(99) %}
{% set pmdInDays = state_attr('sensor.afvalwijzer_pmd', 'days_until_collection_date') | default(99) %}
{% set restAfvalInDays = state_attr('sensor.afvalwijzer_restafval', 'days_until_collection_date') | default(99) %}
{% set daysDutch = ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'] %}
{% set todayDateTime = as_timestamp(now())|int %}
{% set nextInDays = [gftInDays, papierInDays, pmdInDays, restAfvalInDays] %}
{% set sortedNextInDays = nextInDays|sort %}
{% if sortedNextInDays[ selected_item ] == gftInDays %}
{% if (gftInDays <= 2) %}
{{ 'Vandaag' if (gftInDays == 0) else ('Morgen' if (gftInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (gftInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (gftInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (gftInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
{% if sortedNextInDays[ selected_item ] == papierInDays %}
{% if (papierInDays <= 2) %}
{{ 'Vandaag' if (papierInDays == 0) else ('Morgen' if (papierInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (papierInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (papierInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (papierInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
{% if sortedNextInDays[ selected_item ] == pmdInDays %}
{% if (pmdInDays <= 2) %}
{{ 'Vandaag' if (pmdInDays == 0) else ('Morgen' if (pmdInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (pmdInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (pmdInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (pmdInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
{% if sortedNextInDays[ selected_item ] == restAfvalInDays %}
{% if (restAfvalInDays <= 2) %}
{{ 'Vandaag' if (restAfvalInDays == 0) else ('Morgen' if (restAfvalInDays == 1) else 'Overmorgen') }}
{% else %}
{% set dayNumber = ((todayDateTime + (restAfvalInDays * 86400))|timestamp_custom('%w'))|int %}
{% if (restAfvalInDays <= 7) %}
{{ daysDutch[dayNumber] }}
{% elif (restAfvalInDays > 14) %}
{{ daysDutch[dayNumber] }} over twee week
{% else %}
Volgende week {{ daysDutch[dayNumber]|lower }}
{% endif %}
{% endif %}
{% endif %}
third_trash_name:
value_template: >-
{% set selected_item = 2 %}
{% set trash_gft_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_gft.state, "%d-%m-%Y"))|int %}
{% set trash_papier_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_papier.state, "%d-%m-%Y"))|int %}
{% set trash_pmd_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_pmd.state, "%d-%m-%Y"))|int %}
{% set trash_restafval_date_ts = as_timestamp(strptime(states.sensor.afvalwijzer_restafval.state, "%d-%m-%Y"))|int %}
{% set trash_ts_array = [trash_gft_date_ts, trash_pmd_date_ts, trash_papier_date_ts, trash_restafval_date_ts] %}
{% set sorted_trash_ts_array = trash_ts_array|sort %}
{% set selected_timestamp = sorted_trash_ts_array[ selected_item ] %}
{% if (selected_timestamp == trash_papier_date_ts) %}
papier
{% elif (selected_timestamp == trash_pmd_date_ts) %}
pmd
{% elif (selected_timestamp == trash_gft_date_ts) %}
gft
{% elif (selected_timestamp == trash_restafval_date_ts) %}
restafval
{% else %}
geen
{% endif %}
And the lovelace yaml:
- cards:
- entity: sensor.first_trash_name
show_name: false
show_state: false
state_image:
Geen: /local/mijnafvalwijzer/kliko_geen.png
gft: /local/mijnafvalwijzer/gft3.png
papier: /local/mijnafvalwijzer/papier3.png
pmd: /local/mijnafvalwijzer/plastic3.png
restafval: /local/mijnafvalwijzer/restafval3.png
type: picture-entity
- entity: sensor.second_trash_name
show_name: false
show_state: false
state_image:
Geen: /local/mijnafvalwijzer/kliko_geen.png
gft: /local/mijnafvalwijzer/gft3.png
papier: /local/mijnafvalwijzer/papier3.png
pmd: /local/mijnafvalwijzer/plastic3.png
restafval: /local/mijnafvalwijzer/restafval3.png
type: picture-entity
- entity: sensor.third_trash_name
show_name: false
show_state: false
state_image:
Geen: /local/mijnafvalwijzer/kliko_geen.png
gft: /local/mijnafvalwijzer/gft3.png
papier: /local/mijnafvalwijzer/papier3.png
pmd: /local/mijnafvalwijzer/plastic3.png
restafval: /local/mijnafvalwijzer/restafval3.png
type: picture-entity
type: horizontal-stack
- cards:
- content: >
<center>{{
states('sensor.first_trash_date')}}</center>
type: markdown
- content: >
<center>{{
states('sensor.second_trash_date')}}</center>
style:
text-align: center
type: markdown
- content: >
<center>{{
states('sensor.third_trash_date')}}</center>
style:
text-align: center
type: markdown
type: horizontal-stack```