well, sure, but isnt the fun of this project to create your own things to the exact detail of your needs?
my templates have grown on me, developing along with the changes in the integration, the data put forward by Saver, and possibilities of Lovelace/HA backend. As a matter of fact, I’ve even adapted them yesterday.
here’s my full package:
EDIT
updated the package below to follow the new CC version 5.X
##########################################################################################
## AfvalWijzer Custom Component
## created by @xirixiz, more info on https://github.com/xirixiz/home-assistant-config
## https://community.home-assistant.io/t/garbage-pickup-date-mijnafvalwijzer-nl-custom-component/34631
# place this package in /config/packages
# place the custom component sensor.py in /config/custom_components/afvalwijzer
# @mariusthvdb
# up to date for version 5.x of the CC
##########################################################################################
homeassistant:
customize:
sensor.afvalwijzer_restafval_next:
entity_picture: /local/afvalwijzer/restafval_saver.png
sensor.afvalwijzer_plastic_next:
entity_picture: /local/afvalwijzer/plastic_saver.png
sensor.afvalwijzer_gft_next:
entity_picture: /local/afvalwijzer/gft_saver.png
sensor.afvalwijzer_papier_next:
entity_picture: /local/afvalwijzer/papier_saver.png
sensor.afvalwijzer_restafval:
entity_picture: /local/afvalwijzer/restafval_saver.png
friendly_name: Restafval
sensor.afvalwijzer_plastic:
entity_picture: /local/afvalwijzer/plastic_saver.png
friendly_name: Plastic
sensor.afvalwijzer_gft:
entity_picture: /local/afvalwijzer/gft_saver.png
friendly_name: Gft
sensor.afvalwijzer_papier:
entity_picture: /local/afvalwijzer/papier_saver.png
friendly_name: Papier
sensor.afvalwijzer_first_next_in_days:
friendly_name: Days to next pickup
templates:
icon: >
if (state == 'Geen') return 'mdi:calendar-question';
var items = ['1','2','3','4','5','6','7','8','9'];
if (items.includes(state))
return 'mdi:numeric-' + state + '-box-multiple-outline';
return 'mdi:numeric-9-plus-box-multiple-outline';
sensor.afvalwijzer_today:
friendly_name: Afval vandaag
templates: &trash_picture
entity_picture: >
var items = ['papier','gft','plastic','restafval'];
if (items.includes(state))
return '/local/afvalwijzer/' + state + '.png';
return '/local/afvalwijzer/kliko_geen.png';
#previously
# if (state in ['papier','gft','plastic','restafval'])
# return '/local/afvalwijzer/' + state + '.png';
# return '/local/afvalwijzer/kliko_geen.png';
sensor.afvalwijzer_tomorrow:
friendly_name: Afval morgen
templates: *trash_picture
sensor.afvalwijzer_day_after_tomorrow:
friendly_name: Afval Dat
templates: *trash_picture
##########################################################################################
# Sensors
##########################################################################################
sensor:
- platform: afvalwijzer
provider: mijnafvalwijzer # (required, default = mijnafvalwijzer) either choose mijnafvalwijzer or afvalstoffendienstkalender
postal_code: !secret postcode # (required, default = 1111AA)
street_number: !secret huisnummer # (required, default = 11)
# suffix: None #(optional, default = None)
# include_date_today: false #(optional, default = false) to take or not to take Today into account in the next pickup.
default_label: Geen #(optional, default = Geen) label if no date found
- platform: template
sensors:
trash_alert:
value_template: >-
{% if states.sensor.afvalwijzer_today is not none and
states.sensor.afvalwijzer_tomorrow is not none %}
{%- if states('sensor.afvalwijzer_today') != 'Geen'%}
Afval: {{states('sensor.afvalwijzer_today')|title}} wordt vandaag opgehaald
{%- elif states('sensor.afvalwijzer_tomorrow') != 'Geen'%}
Afval: {{states('sensor.afvalwijzer_tomorrow')|title}} wordt morgen opgehaald
{%- else -%} No trash alert
{%- endif -%}
{% else %} No sensors in initiated
{% endif %}
trash_next_icon:
value_template: >
{% set days = states('sensor.afvalwijzer_first_next_in_days') %}
{% if days != 'Geen' %}
{% if days <= '9'%} mdi:numeric-{{days}}-box-multiple-outline
{% else %} mdi:numeric-9-plus-box-multiple-outline
{% endif%}
{% else %} mdi:checkbox-blank-outline
{% endif %}
trash_next_color:
value_template: >
{% set next = states('sensor.afvalwijzer_first_next_item') %}
{% set mapper = {'papier':'deepskyblue',
'gft':'green',
'plastic':'orange',
'restafval':'black'} %}
{% set color = mapper[next] if next in mapper else 'grey' %}
{{color}}
trash_color:
value_template: >
{% set vandaag = states('sensor.afvalwijzer_today') %}
{% set mapper = {'papier':'deepskyblue',
'gft':'green',
'plastic':'orange',
'restafval':'black'} %}
{% set color = mapper[vandaag] if vandaag in mapper else 'grey' %}
{{color}}
volgende_afval_ophaal_dag:
friendly_name: Volgende afval-ophaal dag
entity_id: sensor.afvalwijzer_first_next_date
value_template: >
{%- set tracker_timestamp = as_timestamp(strptime(states('sensor.afvalwijzer_first_next_date'),'%d-%m-%Y')) %}
{% set months = ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'] %}
{%- set wdays = ['Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag'] %}
{%- set wday = tracker_timestamp|timestamp_custom('%w')|int %}
{%- set month = tracker_timestamp |timestamp_custom('%m')|int %}
{{tracker_timestamp|timestamp_custom(wdays[wday] + ' ' '%d' ' ' + months[month-1])}}
#https://community.home-assistant.io/t/markdown-card-with-template-wont-format-correctly/137697/2
afvalwijzer_restafval_next:
friendly_name: Restafval
value_template: >
{{state_attr('sensor.afvalwijzer_restafval','days_until_collection_date')}}
attribute_templates:
date: >
{{as_timestamp(strptime(states('sensor.afvalwijzer_restafval'),'%d-%m-%Y'))
|timestamp_custom('%a %d %b')}}
timestamp: >
{{as_timestamp(strptime(states('sensor.afvalwijzer_restafval'),'%d-%m-%Y'))}}
afvalwijzer_plastic_next:
friendly_name: Plastic
value_template: >
{{state_attr('sensor.afvalwijzer_plastic','days_until_collection_date')}}
attribute_templates:
date: >
{{as_timestamp(strptime(states('sensor.afvalwijzer_plastic'),'%d-%m-%Y'))
|timestamp_custom('%a %d %b')}}
timestamp: >
{{as_timestamp(strptime(states('sensor.afvalwijzer_plastic'),'%d-%m-%Y'))}}
afvalwijzer_gft_next:
friendly_name: Gft
value_template: >
{{state_attr('sensor.afvalwijzer_gft','days_until_collection_date')}}
attribute_templates:
date: >
{{as_timestamp(strptime(states('sensor.afvalwijzer_gft'),'%d-%m-%Y'))
|timestamp_custom('%a %d %b')}}
timestamp: >
{{as_timestamp(strptime(states('sensor.afvalwijzer_gft'),'%d-%m-%Y'))}}
afvalwijzer_papier_next:
friendly_name: Papier
value_template: >
{{state_attr('sensor.afvalwijzer_papier','days_until_collection_date')}}
attribute_templates:
date: >
{{as_timestamp(strptime(states('sensor.afvalwijzer_papier'),'%d-%m-%Y'))
|timestamp_custom('%a %d %b')}}
timestamp: >
{{as_timestamp(strptime(states('sensor.afvalwijzer_papier'),'%d-%m-%Y'))}}
binary_sensor:
- platform: template
sensors:
trash_notification:
friendly_name: Trash is notifying
value_template: >
{{is_state('persistent_notification.trash_notification','notifying')}}
saver_offline:
friendly_name: Saver offline
value_template: >
{{states.sensor.afvalwijzer_today is none}}
device_class: problem
##############################################################################################################
# Automations
##############################################################################################################
automation:
- alias: Saver offline
id: Saver offline
trigger:
platform: state
entity_id: binary_sensor.saver_offline
to: 'on'
action:
- service: persistent_notification.create
data:
notification_id: >
saver-notification
title: >
{{now().strftime('%d %B')}}: Saver melding
message: >
Saver is Offline of heeft andere problemen, geen data voor HA
- service: script.intercom_message
data:
message_nl: >
Het is {{now().strftime('%A %-d %B')}}: Saver is Offline of heeft andere problemen, geen data voor Home Assistant
message_en: >
It is {{now().strftime('%A %-d %B')}}: Saver is Offline and experiencing issues, no data provided to Home Assistant
##############################################################################################################
# Vandaag moet het afval worden voorgezet
##############################################################################################################
#datetime.date.today().strftime('%Y-%m-%d')
- alias: Afval vandaag
id: Afval vandaag
trigger:
platform: time
at: '07:00:00'
condition:
- >
{{states.sensor.afvalwijzer_today is not none}}
- >
{{states('sensor.afvalwijzer_today') != 'Geen'}}
action:
- service: script.intercom_message
data:
message_nl: >
Het is {{now().strftime('%A %-d %B')}}: vandaag wordt {{states('sensor.afvalwijzer_today')}} opgehaald!
message_en: >
It is {{now().strftime('%A %-d %B')}}: today {{states('sensor.afvalwijzer_today')}} will be collected!
- service: script.notify_trash_today
- service: script.persistent_trash_today
- service: script.trash_outside_today
##############################################################################################################
# Morgen moet het afval worden voorgezet
##############################################################################################################
- alias: Afval morgen
id: Afval morgen
trigger:
platform: time
at: '21:00:00'
condition:
- >
{{states.sensor.afvalwijzer_tomorrow is not none}}
- >
{{states('sensor.afvalwijzer_tomorrow') != 'Geen'}}
action:
- service: script.intercom_message
data:
message_nl: >
Het is {{now().strftime('%d %B')}}: Morgen wordt
{{states('sensor.afvalwijzer_tomorrow')|title}} opgehaald!
message_en: >
It is {{now().strftime('%d %B')}}: Tomorrow
{{states('sensor.afvalwijzer_tomorrow')|title}} will be picked up!
- service: script.notify_trash_tomorrow
- service: script.persistent_trash_tomorrow
- service: script.trash_outside_tomorrow
- alias: Reset trash notification
trigger:
platform: state
entity_id: input_boolean.trash_outside
to: 'on'
for:
hours: 5
action:
service: input_boolean.turn_off
entity_id: input_boolean.trash_outside
- alias: Mark trash as moved outside from notification
trigger:
platform: event
event_type: ios.notification_action_fired
event_data:
actionName: MARK_TRASH_MOVED
condition:
>
{{(trigger.event.data.actionName == 'MARK_TRASH_MOVED')}}
action:
- service: input_boolean.turn_on
entity_id: input_boolean.trash_outside
- service: persistent_notification.dismiss
data:
notification_id: trash-notification
- service: notify.mobile_app_calltheboss
data:
title: iOS notification
message: >
Afval staat aan de straat
data:
push:
badge: 0
sound: US-EN-Morgan-Freeman-Garage-Door-Closed.wav
##############################################################################################################
# Scripts
##############################################################################################################
script:
notify_trash_today:
alias: Notify trash today
mode: restart
sequence:
- condition: state
entity_id: input_boolean.notify_utility
state: 'on'
- service: notify.notify
data:
title: >
{{now().strftime('%d %B')}}: Afvalmelding vandaag
message: >
{{states('sensor.afvalwijzer_today')|title}} wordt vandaag opgehaald!
persistent_trash_today:
alias: Persistent trash today
mode: restart
sequence:
- condition: state
entity_id: input_boolean.persistent_notification_create
state: 'on'
- service: persistent_notification.create
data:
notification_id: >
trash-notification
title: >
{{now().strftime('%d %B')}}: Afvalmelding vandaag
message: >
{{states('sensor.afvalwijzer_today')|title}} wordt vandaag opgehaald!
notify_trash_tomorrow:
alias: Notify trash tomorrow
mode: restart
sequence:
- condition: state
entity_id: input_boolean.notify_utility
state: 'on'
- service: notify.notify
data:
title: >
{{now().strftime('%d %B')}}: Afvalmelding morgen
message: >
{{states('sensor.afvalwijzer_tomorrow')|title}} wordt morgen opgehaald!
persistent_trash_tomorrow:
alias: Persistent trash tomorrow
mode: restart
sequence:
- condition: state
entity_id: input_boolean.persistent_notification_create
state: 'on'
- service: persistent_notification.create
data:
notification_id: >
trash-notification
title: >
{{now().strftime('%d %B')}}: Afvalmelding morgen
message: >
{{states('sensor.afvalwijzer_tomorrow')|title}} wordt morgen opgehaald!
trash_outside_tomorrow:
alias: Trash outside tomorrow
mode: restart
sequence:
- condition: state
entity_id: input_boolean.trash_outside
state: 'off'
- condition: state
entity_id: input_boolean.trash_reminder
state: 'on'
- service: notify.mobile_app_calltheboss
data:
title: iOS notification
message: >
{{states('sensor.afvalwijzer_tomorrow')|title}} wordt morgen opgehaald, zet het afval aan de straat
data:
push:
badge: 5
category: 'afval'
sound: US-EN-Alexa-Garage-Door-Opened.wav
trash_outside_today:
alias: Trash outside today
mode: restart
sequence:
- condition: state
entity_id: input_boolean.trash_outside
state: 'off'
- condition: state
entity_id: input_boolean.trash_reminder
state: 'on'
- service: notify.mobile_app_calltheboss
data:
title: iOS notification
message: >
{{states('sensor.afvalwijzer_today')|title}} wordt vandaag opgehaald, zet het afval aan de straat
data:
push:
badge: 5
category: 'afval'
sound: US-EN-Alexa-Garage-Door-Opened.wav
action_data:
entity_id: input_boolean.trash_outside
###############################################################################################################
## Ios
###############################################################################################################
#
ios:
push:
categories:
- name: Afval
identifier: 'afval'
actions:
- identifier: 'MARK_TRASH_MOVED'
title: Afval verwerkt
activationMode: 'background'
authenticationRequired: no
destructive: yes
# behavior: 'default'
###############################################################################################################
## Inputs
###############################################################################################################
input_boolean:
trash_outside:
name: Trash is outside
initial: 'off'
icon: mdi:delete-empty
trash_reminder:
name: Trash reminder enabled
icon: mdi:cellphone-message
and the trash alert button showing on a pickup day:
type: custom:button-card
template: button_body
entity: automation.mark_trash_as_moved_outside_from_notification
name: Mark trash outside
label: >
[[[ var trash = states['sensor.saver_trash_today'].state != 'Geen'
? states['sensor.saver_trash_today'].state : states['sensor.saver_trash_tomorrow'].state;
return trash.charAt(0).toUpperCase() + trash.slice(1); ]]]
icon: mdi:delete-alert
show_state: false
variables:
view: >
[[[ return window.location.pathname.split('lovelace/')[1] == 'home'; ]]]
styles:
card:
- animation: blink 2s ease infinite
label:
- color: >
[[[ var trash = states['sensor.saver_trash_today'].state != 'Geen'
? states['sensor.saver_trash_today'].state : states['sensor.saver_trash_tomorrow'].state;
var mapper = {papier:'deepskyblue',
gft:'green',
plastic:'orange',
restafval: 'black'}
return mapper[trash] ? mapper[trash] :'grey';
]]]
icon:
- color: >
[[[ var trash = states['sensor.saver_trash_today'].state != 'Geen'
? states['sensor.saver_trash_today'].state : states['sensor.saver_trash_tomorrow'].state;
if (trash == 'papier') return 'deepskyblue';
if (trash == 'gft') return 'green';
if (trash == 'plastic') return 'orange';
if (trash == 'restafval') return 'black';
return 'grey';
]]]
tap_action:
action: navigate
navigation_path: /lovelace/tijd_agenda
hold_action:
action: >
[[[ return variables.view ? 'navigate' : 'call-service'; ]]]
navigation_path: >
[[[ return variables.view ? 'tijd_agenda' : null; ]]]
service: >
[[[ return variables.view ? null : 'automation.trigger'; ]]]
service_data:
entity_id: >
[[[ return variables.view ? null : entity.entity_id ]]]