Garbage pickup date (mijnafvalwijzer.nl) custom_component

Thanks a bunch, this fixed it for me to

Tagging @xirixiz, maybe you could add this to the readme?

Hi @xirixiz

have you ever given the idea (we talked about some time ago) of the sensor.trash_next some thought, showing the next trash, on the day of pickup?

that would enable this:

      afval_overmorgen:
        friendly_name: Afval overmorgen
        value_template: >
          {% set afval = states('sensor.trash_firstwastetype') %}
          {% set overmorgen = states('sensor.trash_next') == '2' %}
          {% if overmorgen %} {{afval[:-1]}}
          {% else %} Geen
          {% endif %}

as it stands we can’t use the above, because on a pickup day, the trash_next shows the current days pickup, and not the next…

I ask because the following sensor throws a lot of errors in the startup sequence, while the above sensor doesn’t. (Doesn’t work correctly yet of course, but the sensor itself initializes fine without errors)

      afval_overmorgen:
        friendly_name: Afval overmorgen
        value_template: >
            {% set papier = (as_timestamp(strptime(states('sensor.trash_papier'), '%d-%m-%Y')) - 
                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
            {% set gft = (as_timestamp(strptime(states('sensor.trash_gft'), '%d-%m-%Y')) - 
                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
            {% set plastic = (as_timestamp(strptime(states('sensor.trash_plastic'), '%d-%m-%Y')) - 
                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
            {% set rest = (as_timestamp(strptime(states('sensor.trash_restafval'), '%d-%m-%Y')) - 
                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
            {% set date = now().strftime('%d-%m-%Y') %}
            {% if date == papier %} Papier
            {% elif date == gft %} Gft
            {% elif date == plastic %} Plastic
            {% elif date == rest %} Restafval
            {% else %} Geen
            {% endif %}

please have a look? thanks!

update

following @pnbruckner 's advise, this is a sensor not causing startup issues.

      afval_overmorgen:
        friendly_name: Afval overmorgen
        value_template: >
          {% set date = (as_timestamp(now())+2*86400)|timestamp_custom('%d-%m-%Y') %}
          {% if date == states('sensor.trash_papier') %} Papier
          {% elif date == states('sensor.trash_gft') %} Gft
          {% elif date == states('sensor.trash_plastic') %} Plastic
          {% elif date == states('sensor.trash_restafval') %} Restafval
          {% else %} Geen
          {% endif %}
#            {% set papier = (as_timestamp(strptime(states('sensor.trash_papier'), '%d-%m-%Y')) - 
#                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#            {% set gft = (as_timestamp(strptime(states('sensor.trash_gft'), '%d-%m-%Y')) - 
#                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#            {% set plastic = (as_timestamp(strptime(states('sensor.trash_plastic'), '%d-%m-%Y')) - 
#                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#            {% set rest = (as_timestamp(strptime(states('sensor.trash_restafval'), '%d-%m-%Y')) - 
#                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#            {% set date = now().strftime('%d-%m-%Y') %}
#            {% if date == papier %} Papier
#            {% elif date == gft %} Gft
#            {% elif date == plastic %} Plastic
#            {% elif date == rest %} Restafval
#            {% else %} Geen
#            {% endif %}
        entity_picture_template: >
          {% set mapper = {'Papier': '/local/mijnafvalwijzer/papier.png',
                           'Gft': '/local/mijnafvalwijzer/gft.png',
                           'Plastic': '/local/mijnafvalwijzer/plastic.png',
                           'Restafval': '/local/mijnafvalwijzer/restafval.png'} %}
          {% set state = states('sensor.afval_overmorgen') %}
          {{ mapper[state] if state in mapper else '/local/mijnafvalwijzer/kliko_geen.png' }}

Thanks!

I am new to HA/this and i wonder if this can be simplified to allow install from within HA? Assuming here that currently adding the github repo wont work.

Also, perhaps update first post with link to the repo? It took me a while to find the GitHub link to your sensor, its a long thread and not searchable on mobile due to the loading + scrolling.

Hi hi,

With the new 0.96 verdien I get this error in the config checker addon:

Failed config
  General Errors: 
    - Platform not found: sensor.afvalwijzer

Below is my configuration.

sensor:
  - platform: afvalwijzer
    url: 'mijnafvalwijzer.nl'
    postcode: !secret postcode
    huisnummer: !secret housenumber
    toevoeging: ''
    label_geen: 'Geen'

Someone else get this error?

I had this previously; just a reboot, maybe twice fixed it for me.

You can use Custom Component: HACS
If the component is not in HACS, you can add the repository yourself, provided that the repository can be read by HACS.

1 Like

Thanks @bouwew i got HACS installed and used it to install the component by Xirixiz for use with afvalstoffendienstkalender.nl

This community components store looks nice. Already discovered great components made by others.

1 Like

HI @xirixiz, anyone ,

testing the push notification in your GitHub, I can’t seem to get it to work. The automation sending the notification works fine but my phone won’t show a button to press, only the notification message itself. Even 3d pushing the message won’t popup the otherwise showing buttons to press.

I’ve tested the event identifier ‘MARK_TRASH_MOVED’ it self (in the services page), and that works, and turns on the input_boolean.

Please have a look what could be amiss here? thanks!

I am having the same problem like some mentioned before. I installed afvalwijzer with HACS and added this to my configuration (under sensor:) :

- platform: afvalwijzer
    url: 'mijnafvalwijzer.nl'
    postcode: '1111AA'
    huisnummer: '1'

No sensor are popping up, even after several restart in home assistant.
I installed the missing dependancy with pip install bs4

The Error I got is this:

Platform not found: sensor.afvalwijzer
15:25 components/homeassistant/init.py (ERROR) - message first occured at 15:09 and shows up 6 times

Other components no problem, but this one just does not work for me

is there a link or place where i can download the pictures/icon’s you’re using for this custom component ?

Check the readme on the github repo. Just added a link to my config.

I use hassbian and I get “Platform error sensor.afvalwijzer - No module named ‘bs4’”.
How do I install bs4?

Afvalwijzer is not working here. Running hassio on a Odroid C2

2019-09-01 21:33:10 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.trash_pmd_formatted fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 261, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 439, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/template/sensor.py", line 220, in async_update
    self._state = self._template.async_render()
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 215, in async_render
    return compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.7/site-packages/jinja2/sandbox.py", line 438, in call
    return __context.call(__obj, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 805, in strptime
    return datetime.strptime(string, fmt)
TypeError: strptime() argument 1 must be str, not Undefined

I copied @xirixiz config (including the packages-config… first timer for me) but no luck. I have no clue what is wrong. Any help is much appreciated!

Just try to build it step by step. First the sensor and platform. After that next part. I have tried whole day and finaly got it worked.

This card looks great and since Home Assistant is pretty new for me i thought lets start with this to recreate what you have created here but I failed big time i think.

This is what i had after copy-paste

Those images arent the biggest obstacle but a few sensors are, for example:
sensor.vandaag.state
sensor.gft_formatted
sensor.papier_formatted
sensor.plastic_verpakkingsafval_formatted
sensor.restafval_formatted

I don’t have thos and can’t seem to find them also.
Any suggesitons/help?

sure, here you go:

  - platform: template
    sensors:
      restafval:
        friendly_name: 'Restafval'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_restafval'), '%d-%m-%Y')) | timestamp_custom('%d %B') }}

      plastic_verpakkingsafval:
        friendly_name: 'Plastic'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_plastic'), '%d-%m-%Y')) | timestamp_custom('%d %B') }}

      gft:
        friendly_name: 'Gft'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_gft'), '%d-%m-%Y')) | timestamp_custom('%d %B') }}

      papier:
        friendly_name: 'Papier'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_papier'), '%d-%m-%Y')) | timestamp_custom('%d %B') }}

      gft_formatted:
        friendly_name: 'Gft'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_gft'), '%d-%m-%Y')) | timestamp_custom('%a %d %b') }}

      papier_formatted:
        friendly_name: 'Papier'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_papier'), '%d-%m-%Y')) | timestamp_custom('%a %d %b') }}

      plastic_verpakkingsafval_formatted:
        friendly_name: 'Plastic'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_plastic'), '%d-%m-%Y')) | timestamp_custom('%a %d %b') }}

      restafval_formatted:
        friendly_name: 'Restafval'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_restafval'), '%d-%m-%Y')) | timestamp_custom('%a %d %b') }}

note that those formatted sensors are purely made for displaying nicely in the Lovelace card.
sensor.vandaag.state isnt a sensor, its the silly way of templating for the useful-markdown card, which is no longer needed.
You can now simply use jinja templates in the native Hassio markdown card

      - type: markdown
        content: >
          Vandaag is het **<font color=green> {{states('sensor.vandaag')}}</font>**.

          Volgende afval-ophaal over **<font color=var(--secondary-text-color)>{{states('sensor.trash_next')}}</font>** dagen:

          **<font color=var(--secondary-text-color)>{{states('sensor.trash_firstdate')}}</font>** : **{{states('sensor.trash_firstwastetype')}}**

images:
asbest
elec gft
gft3
glas
goedbeter
kca
kliko_geen
kliko
kringloop
milieustraat
papier
papier3
plastic
plastic3
restafval
restafval3
textiel asbest.png
elec.png
gft.png
gft3.png
glas.png
goedbeter.png
kca.png
kliko_geen.png
kliko.png
kringloop.png
milieustraat.png
papier.png
papier3.png
plastic.png
plastic3.png
restafval.png
restafval3.png
textiel.png

You might want to use the full package. Note that this also holds info for legacy HA (eg the groups), and useful customization, using custom-u which is needed separately:

##########################################################################################
## MijnAfvalWijzer 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 mijnafvalwijzer.py in /config/custom_components/sensor
# @marijnthvdb
##########################################################################################
# manual edit in CC:
# 226 trashFirstDate['value'] = scraper_data.find('p', attrs={'class':'firstDate'}).text.capitalize()
# 232 firstWasteType['value'] = scraper_data.find('p', attrs={'class':'firstWasteType'}).text.replace('.','')

homeassistant:
  customize:
    group.trash_calendar:
      templates:
        icon: >
          if (entities['sensor.trash_today'].state === 'Geen') return 'mdi:delete-empty';
          return 'mdi:delete-restore';

    sensor.restafval:
      entity_picture: /local/mijnafvalwijzer/restafval.png
    sensor.plastic_verpakkingsafval:
      entity_picture: /local/mijnafvalwijzer/plastic.png
    sensor.gft:
      entity_picture: /local/mijnafvalwijzer/gft.png
    sensor.papier:
      entity_picture: /local/mijnafvalwijzer/papier.png

    sensor.restafval_formatted:
      entity_picture: /local/mijnafvalwijzer/restafval.png
    sensor.plastic_verpakkingsafval_formatted:
      entity_picture: /local/mijnafvalwijzer/plastic.png
    sensor.gft_formatted:
      entity_picture: /local/mijnafvalwijzer/gft.png
    sensor.papier_formatted:
      entity_picture: /local/mijnafvalwijzer/papier.png

    sensor.trash_gft:
      hidden: true
    sensor.trash_papier:
      hidden: true
    sensor.trash_plastic:
      hidden: true
    sensor.trash_restafval:
      hidden: true

    sensor.afval_vandaag:
      templates:
        theme: >
          if (state === 'Papier') return 'papier';
          if (state === 'Gft' ) return 'green';
          if (state === 'Plastic') return 'orange';
          if (state === 'Restafval') return 'black';
          return 'grey';

    sensor.afval_overmorgen:
      templates:
        theme: >
          if (state === 'Papier') return 'papier';
          if (state === 'Gft' ) return 'green';
          if (state === 'Plastic') return 'orange';
          if (state === 'Restafval') return 'black';
          return 'grey';

    sensor.trash_next:
      friendly_name: Days to next pickup
      templates:
        icon: >
          if (state === 'Geen') return 'mdi:calendar-question';
          if (state === '0' || state === '1' || state === '2' || state === '3' || state === '4' 
              || state === '5' || state === '6' || state === '7' || state === '8' || state === '9')
          return 'mdi:numeric-' + state + '-box-multiple-outline';
          return 'mdi:numeric-9-plus-box-multiple-outline';

#    sensor.trash_today:
#      friendly_name: 'Afval vandaag'
#      templates:
#        entity_picture: >
#          if (state === 'papier') return '/local/mijnafvalwijzer/papier.png';
#          if (state === 'gft') return '/local/mijnafvalwijzer/gft.png';
#          if (state === 'plastic') return '/local/mijnafvalwijzer/plastic.png';
#          if (state === 'restafval') return '/local/mijnafvalwijzer/restafval.png';
#          return '/local/mijnafvalwijzer/kliko_geen.png';
#        theme: >
#          if (state === 'papier') return 'papier';
#          if (state === 'gft') return 'green';
#          if (state === 'plastic') return 'orange';
#          if (state === 'restafval') return 'black';
#          return 'grey';

    sensor.trash_tomorrow:
      friendly_name: 'Afval morgen'
      templates:
        entity_picture: >
          if (state === 'papier') return '/local/mijnafvalwijzer/papier.png';
          if (state === 'gft') return '/local/mijnafvalwijzer/gft.png';
          if (state === 'plastic verpakkingsafval') return '/local/mijnafvalwijzer/plastic.png';
          if (state === 'restafval') return '/local/mijnafvalwijzer/restafval.png';
          return '/local/mijnafvalwijzer/kliko_geen.png';
        theme: >
          if (state === 'papier') return 'papier';
          if (state === 'gft') return 'green';
          if (state === 'plastic verpakkingsafval') return 'orange';
          if (state === 'restafval') return 'black';
          return 'grey';

    sensor.trash_firstdate:
      friendly_name: First date
      icon: mdi:calendar-check
      templates:
        theme: >
          if (entities['sensor.trash_firstwastetype'].state === 'Papier en karton') return 'papier';
          if (entities['sensor.trash_firstwastetype'].state === 'Groente, Fruit en Tuinafval' ) return 'green';
          if (entities['sensor.trash_firstwastetype'].state === 'Plastic verpakkingsafval') return 'orange';
          if (entities['sensor.trash_firstwastetype'].state === 'Restafval') return 'black';
          return 'grey';

#    sensor.afval_soort:
    sensor.trash_firstwastetype:
      friendly_name: First waste type
      templates:
        entity_picture: >
          if (state === 'Papier en karton') return '/local/mijnafvalwijzer/papier.png';
          if (state === 'Groente, Fruit en Tuinafval') return '/local/mijnafvalwijzer/gft.png';
          if (state === 'Plastic verpakkingsafval') return '/local/mijnafvalwijzer/plastic.png';
          if (state === 'Restafval') return '/local/mijnafvalwijzer/restafval.png';
          return '/local/mijnafvalwijzer/kliko_geen.png';
        theme: >
          if (state === 'Papier en karton') return 'papier';
          if (state === 'Groente, Fruit en Tuinafval') return 'green';
          if (state === 'Plastic verpakkingsafval') return 'orange';
          if (state === 'Restafval') return 'black';
          return 'grey';

##########################################################################################
# Sensors
##########################################################################################

sensor:
  - platform: mijnafvalwijzer
    postcode: !secret postcode
    huisnummer: !secret huisnummer
    label_geen: 'Geen'
#    scan_interval: 3600 #1 keer per uur

  - platform: template
    sensors:
      restafval:
        friendly_name: 'Restafval'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_restafval'), '%d-%m-%Y')) | timestamp_custom('%d %B') }}

      plastic_verpakkingsafval:
        friendly_name: 'Plastic'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_plastic'), '%d-%m-%Y')) | timestamp_custom('%d %B') }}

      gft:
        friendly_name: 'Gft'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_gft'), '%d-%m-%Y')) | timestamp_custom('%d %B') }}

      papier:
        friendly_name: 'Papier'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_papier'), '%d-%m-%Y')) | timestamp_custom('%d %B') }}

      gft_formatted:
        friendly_name: 'Gft'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_gft'), '%d-%m-%Y')) | timestamp_custom('%a %d %b') }}

      papier_formatted:
        friendly_name: 'Papier'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_papier'), '%d-%m-%Y')) | timestamp_custom('%a %d %b') }}

      plastic_verpakkingsafval_formatted:
        friendly_name: 'Plastic'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_plastic'), '%d-%m-%Y')) | timestamp_custom('%a %d %b') }}

      restafval_formatted:
        friendly_name: 'Restafval'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.trash_restafval'), '%d-%m-%Y')) | timestamp_custom('%a %d %b') }}

      afval_vandaag:
        friendly_name_template: >
          Vandaag: {{states('sensor.afval_vandaag')}}
        value_template: >
          {{states('sensor.trash_today')|title}}
        entity_picture_template: >
          {% set mapper = {'papier': '/local/mijnafvalwijzer/papier.png',
                           'gft': '/local/mijnafvalwijzer/gft.png',
                           'plastic': '/local/mijnafvalwijzer/plastic.png',
                           'restafval': '/local/mijnafvalwijzer/restafval.png'} %}
          {% set state = states('sensor.afval_vandaag')|lower %}
          {{ mapper[state] if state in mapper else '/local/mijnafvalwijzer/kliko_geen.png' }}
        unit_of_measurement: Afval
# werkt niet zolang trash_next op de dag zelf niet de volgende trash soort toont
#      afval_overmorgen_2:
#        friendly_name: Afval overmorgen
#        value_template: >
#          {% if states('sensor.trash_next') == '2' %}
#            {{states('sensor.trash_firstwastetype')}}
#          {% else %} Geen
#          {% endif %}
#        entity_picture_template: >
#          {% set mapper = {'Papier': '/local/mijnafvalwijzer/papier.png',
#                           'Groente, Fruit en Tuinafval': '/local/mijnafvalwijzer/gft.png',
#                           'Plastic verpakkingsafval': '/local/mijnafvalwijzer/plastic.png',
#                           'Restafval': '/local/mijnafvalwijzer/restafval.png'} %}
#          {% set state = states('sensor.afval_overmorgen') %}
#          {{ mapper[state] if state in mapper else '/local/mijnafvalwijzer/kliko_geen.png' }}

#      afval_overmorgen:
#        friendly_name: Afval overmorgen
#        value_template: >
#          {% set afval = states('sensor.trash_firstwastetype') %}
#          {% set overmorgen = states('sensor.trash_next') == '2' %}
#          {% if overmorgen %} {{afval[:-1]}}
#          {% else %} Geen
#          {% endif %}
#        entity_picture_template: >
#          {% set mapper = {'Papier': '/local/mijnafvalwijzer/papier.png',
#                           'Gft': '/local/mijnafvalwijzer/gft.png',
#                           'Plastic': '/local/mijnafvalwijzer/plastic.png',
#                           'Restafval': '/local/mijnafvalwijzer/restafval.png'} %}
#          {% set state = states('sensor.afval_overmorgen') %}
#          {{ mapper[state] if state in mapper else '/local/mijnafvalwijzer/kliko_geen.png' }}

      afval_overmorgen:
        friendly_name: Afval overmorgen
        value_template: >
          {% set date = (as_timestamp(now())+2*86400)|timestamp_custom('%d-%m-%Y') %}
          {% if date == states('sensor.trash_papier') %} Papier
          {% elif date == states('sensor.trash_gft') %} Gft
          {% elif date == states('sensor.trash_plastic') %} Plastic
          {% elif date == states('sensor.trash_restafval') %} Restafval
          {% else %} Geen
          {% endif %}
#            {% set papier = (as_timestamp(strptime(states('sensor.trash_papier'), '%d-%m-%Y')) - 
#                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#            {% set gft = (as_timestamp(strptime(states('sensor.trash_gft'), '%d-%m-%Y')) - 
#                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#            {% set plastic = (as_timestamp(strptime(states('sensor.trash_plastic'), '%d-%m-%Y')) - 
#                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#            {% set rest = (as_timestamp(strptime(states('sensor.trash_restafval'), '%d-%m-%Y')) - 
#                  (2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#            {% set date = now().strftime('%d-%m-%Y') %}
#            {% if date == papier %} Papier
#            {% elif date == gft %} Gft
#            {% elif date == plastic %} Plastic
#            {% elif date == rest %} Restafval
#            {% else %} Geen
#            {% endif %}
        entity_picture_template: >
          {% set mapper = {'Papier': '/local/mijnafvalwijzer/papier.png',
                           'Gft': '/local/mijnafvalwijzer/gft.png',
                           'Plastic': '/local/mijnafvalwijzer/plastic.png',
                           'Restafval': '/local/mijnafvalwijzer/restafval.png'} %}
          {% set state = states('sensor.afval_overmorgen') %}
          {{ mapper[state] if state in mapper else '/local/mijnafvalwijzer/kliko_geen.png' }}


# now in CC, so no need for manual sensor anymore:
#  - platform: scrape
#    resource: !secret scrape_resource_date
#    name: Afval Datum
#    select: '.firstDate'
#    scan_interval: 3600

#  - platform: scrape
#    resource: !secret scrape_resource_type
#    name: Afval Soort
#    select: '.firstWasteType'
#    scan_interval: 3600

##############################################################################################################
# Groups
##############################################################################################################

group:
  trash_pickup:
    name: 'Afvalwijzer ophaaldata'
    icon: mdi:delete-restore
    control: hidden
    entities:
      - sensor.trash_firstdate
      - sensor.trash_firstwastetype
      - sensor.trash_next
#      - sensor.trash_today
      - sensor.afval_vandaag
      - sensor.trash_tomorrow
      - sensor.afval_overmorgen
      - sensor.restafval
      - sensor.gft
      - sensor.plastic_verpakkingsafval
      - sensor.papier
      - automation.afval_vandaag
      - automation.afval_morgen
#      - input_boolean.trash_moved
#      - input_boolean.trash_reminder

  afval_data_formatted:
    name: Afval data
    icon: mdi:calendar
    entities:
      - sensor.plastic_verpakkingsafval_formatted
      - sensor.papier_formatted
      - sensor.restafval_formatted
      - sensor.gft_formatted


##############################################################################################################
# Automations
##############################################################################################################

automation:

##############################################################################################################
# Vandaag moet het afval worden voorgezet
##############################################################################################################
#datetime.date.today().strftime('%Y-%m-%d')

  - alias: 'Afval vandaag'
    id: 'Afval vandaag'
#    initial_state: 'on'
    trigger:
      platform: time
      at: '07:00:00'
    condition:
      condition: template
      value_template: >
        {{states('sensor.trash_today') != 'Geen'}}
    action:
      - service: script.intercom_message
        data_template:
          message_nl: >
            Het is {{now().strftime('%A %-d %B')}}: vandaag wordt {{states('sensor.trash_today')}} opgehaald!
          message_en: >
            It is {{now().strftime('%A %-d %B')}}: today {{states('sensor.trash_today')}} will be collected!
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_utility', 'on')}}
      - service: notify.notify
        data_template:
          message: >
            {{ now().strftime('%d %B') }}: Afvalmelding vandaag wordt
              {{states('sensor.trash_today')|title}} opgehaald!
      - condition: template
        value_template: >
          {{ is_state('input_boolean.persistent_notification_create', 'on')}}
      - service: persistent_notification.create
        data_template:
          notification_id: >
            {{states('sensor.trash_today')}}-trash-notification
          title: >
            {{ now().strftime('%d %B') }}: Afvalmelding vandaag
          message: >
            {{states('sensor.trash_today')|title}} wordt opgehaald!

#werkt ook maar niet nodig als trash_today werkt
#  - alias: 'Afval vandaag 2'
#    initial_state: 'on'
#    trigger:
#      platform: time
#      hours: 7 
#      minutes: 0
#      seconds: 0
#    condition:
#      - condition: template
#        value_template: >
#           {{ states('sensor.trash_firstdate') == 'Vandaag' }}
#      - condition: template
#        value_template: >
#          {{ is_state('input_boolean.notify_utility', 'on')}}
#    action:
#      - service: notify.notify
#        data_template:
#          title: >
#            {{ now().strftime('%d %B') }}: Afvalmelding vandaag
#          message: >
#            Zet het {{states('sensor.trash_firstwastetype')|capitalize}} aan de straat!
#      - condition: template
#        value_template: >
#          {{ is_state('input_boolean.persistent_notification_create', 'on')}}
#      - service: persistent_notification.create
#        data_template:
#          title: >
#            {{ now().strftime('%d %B') }}: Afvalmelding vandaag
#          message: >
#            Zet het {{states('sensor.trash_firstwastetype')|capitalize}} aan de straat!
##############################################################################################################
# Morgen moet het afval worden voorgezet
##############################################################################################################

  - alias: 'Afval morgen'
    id: 'Afval morgen'
#    initial_state: 'on'
    trigger:
      platform: time
      at: '20:00:00'
    condition:
      - condition: template
        value_template: >
          {{states('sensor.trash_tomorrow') != 'Geen'}}
    action:
      - service: script.intercom_message
        data_template:
          message: >
              Het is {{ now().strftime('%d %B') }}: Morgen wordt
              {{states('sensor.trash_tomorrow')|title}} opgehaald!
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_utility', 'on')}}
      - service: notify.notify
        data_template:
          title: >
            {{ now().strftime('%d %B') }}: Afvalmelding morgen
          message: >
            {{states('sensor.trash_tomorrow')|title}} wordt morgen opgehaald!
      - condition: template
        value_template: >
          {{ is_state('input_boolean.persistent_notification_create', 'on')}}
      - service: persistent_notification.create
        data_template:
          notification_id: >
            {{states('sensor.trash_tomorrow')}}-trash-notification
          title: >
            {{ now().strftime('%d %B') }}: Afvalmelding morgen
          message: >
            {{states('sensor.trash_tomorrow')|title}} wordt morgen opgehaald!


#
#
#
#  - alias: Reset trash notification
#    trigger:
#      platform: state
#      entity_id: input_boolean.trash_moved
#      to: 'on'
#      for:
#        hours: 12
#    action:
#      - service: input_boolean.turn_off
#        entity_id: input_boolean.trash_moved
#      - service: input_boolean.turn_on
#        entity_id: input_boolean.trash_reminder
#
#  - alias: Mark trash as moved from notification
#    trigger:
#      platform: event
#      event_type: ios.notification_action_fired
##      event_data:
##        actionName: MARK_TRASH_MOVED
#    condition:
#      condition: template
#      value_template: >
#        {{(trigger.event.data.actionName == 'MARK_TRASH_MOVED')}}
#    action:
#      service: input_boolean.turn_on
#      entity_id: input_boolean.trash_moved
#
#  - alias: Trash has not been moved
#    trigger:
#      platform: time_pattern
#      minutes: '/30'
#      seconds: 00
#    condition:
#      condition: and
#      conditions:
#        - condition: template
#          value_template: >
#            {{is_state('input_boolean.trash_moved','off')}}
#        - condition: template
#          value_template: >
#            {{is_state('input_boolean.trash_reminder','on')}}
#        - condition: time
#          after: '18:00:00'
#          before: '23:00:00'
#        - condition: template
#          value_template: >
#            {{ states('sensor.trash_tomorrow') != 'Geen' }}
#    action:
#      service: notify.ios_telefoonmhb
#      data_template:
#        title: 'Afval'
#        message: >
#          {{ states('sensor.trash_tomorrow') }} wordt morgen opgehaald, zet het afval aan de straat
#        data:
#          push:
#            badge: 0
#            sound: https://hvb.duckdns.org:8124/local/sounds/sound_bites/siren.mp3
#            category: 'afval'
##            action_data:
##              entity_id: input_boolean.trash_moved
###############################################################################################################
## Ios
###############################################################################################################
#
#ios:
#  push:
#    categories:
#      - name: Afval
#        identifier: 'afval'
#        actions:
#          - identifier: 'MARK_TRASH_MOVED'
#            title: 'Afval verwerkt'
#            activationMode: 'background'
#            authenticationRequired: yes
#            destructive: yes
#            behavior: 'default'
#
###############################################################################################################
## Inputs
###############################################################################################################
#
#input_boolean:
#  trash_moved:
#    name: Trash has been moved
#    initial: 'off'
#    icon: mdi:delete-empty
#  trash_reminder:
#    name: Trash reminder enabled
#    initial: 'on'
#    icon: mdi:cellphone-message

#  - alias: 'Afval morgen'
#    id: 'Afval morgen'
#    initial_state: 'on'
#    trigger:
#      platform: time
#      hours: 20 
#      minutes: 0
#      seconds: 0
#    condition:
#      - condition: template
#        value_template: >
#          {{ is_state('input_boolean.notify_utility', 'on')}}
#      - condition: template
#        value_template: >
#          {{states('sensor.trash_tomorrow') != 'Geen'}}
#    action:
#      - service: notify.notify
#        data_template:
#          message: >
#            Het is vandaag {{ now().strftime('%d %B') }}, 
#              {{states('sensor.afval_soort')|replace('.','')}} wordt morgen opgehaald!
#      - condition: template
#        value_template: >
#          {{ is_state('input_boolean.persistent_notification_create', 'on')}}
#      - service: persistent_notification.create
#        data_template:
#          message : >
#            Het is vandaag {{ now().strftime('%d %B') }},
#                    {{states('sensor.afval_soort')|replace('.','')}} wordt morgen opgehaald!, 
#                    Trash tomorrow: {{states('sensor.trash_tomorrow')}}'
#          title: >
#            Afvalmelding Morgen: {{states('sensor.afval_soort')|replace('.','')}} : {{states('sensor.trash_tomorrow')}}

#  - alias: 'Trash tomorrow'
#    id: 'Trash tomorrow'
#    initial_state: 'on'
#    trigger:
#      platform: time
#      hours: 20
#      minutes: 0
#      seconds: 0
#    condition:
#      - condition: template
#        value_template: >
#          {{ is_state('input_boolean.notify_utility', 'on')}}
#      - condition: or
#        conditions:
#          - condition: template
#            value_template: >
#              {{ (now().strftime('%d-%m-%Y')) == 
#              (as_timestamp(strptime(states('sensor.trash_gft'), '%d-%m-%Y')) - 
#              (1 * 86400 )) | timestamp_custom('%d-%m-%Y') }}
#          - condition: template
#            value_template: >
#              {{ (now().strftime('%d-%m-%Y')) == 
#              (as_timestamp(strptime(states('sensor.trash_restafval'), '%d-%m-%Y')) - 
#              (1 * 86400 )) | timestamp_custom('%d-%m-%Y') }}
#          - condition: template
#            value_template: >
#              {{ (now().strftime('%d-%m-%Y')) == 
#              (as_timestamp(strptime(states('sensor.trash_papier'), '%d-%m-%Y')) - 
#              (1 * 86400 )) | timestamp_custom('%d-%m-%Y') }}
#          - condition: template
#            value_template: >
#              {{ (now().strftime('%d-%m-%Y')) == 
#              (as_timestamp(strptime(states('sensor.trash_plastic'), '%d-%m-%Y')) - 
#              (1 * 86400 )) | timestamp_custom('%d-%m-%Y') }}
#    action:
#      service: notify.notify
#      data_template:
#        title: >
#          {{ now().strftime('%d %B') }}: Morgen afval voor zetten!
#        message: >-
#          {% if (now().strftime('%d-%m-%Y')) == 
#          (as_timestamp(strptime(states('sensor.trash_gft'), '%d-%m-%Y')) - 
#          (1 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#             De groene bak wordt geleegd op: {{ states('sensor.trash_gft')}}!
#          {% endif %}
#          {% if (now().strftime('%d-%m-%Y')) == 
#          (as_timestamp(strptime(states('sensor.trash_restafval'), '%d-%m-%Y')) - 
#          (1 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#             De grijze bak wordt geleegd op: {{ states('sensor.restafval')}}!
#          {% endif %}
#          {% if (now().strftime('%d-%m-%Y')) == 
#          (as_timestamp(strptime(states('sensor.trash_papier'), '%d-%m-%Y')) - 
#          (1 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#             Papier wordt opgehaald op: {{ states('sensor.trash_papier')}}!
#          {% endif %}
#          {% if (now().strftime('%d-%m-%Y')) == 
#          (as_timestamp(strptime(states('sensor.trash_plastic'), '%d-%m-%Y')) - 
#          (1 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
#             Plastic wordt opgehaald op: {{ states('sensor.trash_plastic')}}!
#          {% endif %}
1 Like

I tried but still no Module bs4. What do I miss? :unamused:

pi@piname:~ $ sudo su
root@piname:/home/pi# sudo -u homeassistant -H -s
homeassistant@piname:/home/pi $ cd /srv/homeassistant/
homeassistant@piname:/srv/homeassistant $ python3 -m venv .
homeassistant@piname:/srv/homeassistant $ source bin/activate
(homeassistant) homeassistant@piname:/srv/homeassistant $ python3 -m pip install bs4
Looking in indexes: Simple index, piwheels - Simple index
Collecting bs4
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x75412d70>: Failed to establish a new connection: [Errno 101] Network is unreachable’)': /simple/bs4/

^CERROR: Operation cancelled by user
(homeassistant) homeassistant@piname:/srv/homeassistant $ python3 -m pip install beautifulsoup4
Looking in indexes: Simple index, piwheels - Simple index
Collecting beautifulsoup4
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x753aa2f0>: Failed to establish a new connection: [Errno 101] Network is unreachable’)': /simple/beautifulsoup4/

Updated my Lovelace card a bit:

  - type: custom:vertical-stack-in-card
    cards:
      - type: markdown
        content: >
          # <font color={{'green' if states('sensor.trash_firstdate') == 'vandaag' else 'grey'}}>Afvalwijzer</font>

          **<font color=green> {{states('sensor.vandaag')}}</font>**.


          **<font color=var(--secondary-text-color)>{{states('sensor.trash_firstdate')}}</font>** : **{{states('sensor.trash_firstwastetype')}}**

          Volgende afval-ophaal over **<font color=var(--secondary-text-color)>{{states('sensor.trash_next')}}</font>** dagen
      - type: horizontal-stack
        cards:
          - type: picture-entity
            entity: sensor.trash_today
            name: Vandaag
            show_state: false
            state_image:
              'gft': /local/mijnafvalwijzer/gft3.png
              'papier': /local/mijnafvalwijzer/papier3.png
              'restafval': /local/mijnafvalwijzer/restafval3.png
              'plastic': /local/mijnafvalwijzer/plastic.png
              'Geen': /local/mijnafvalwijzer/kliko_geen.png
          - type: picture-entity
            entity: sensor.trash_tomorrow
            name: Morgen
            show_state: false
            state_image:
              'gft': /local/mijnafvalwijzer/gft3.png
              'papier': /local/mijnafvalwijzer/papier3.png
              'restafval': /local/mijnafvalwijzer/restafval3.png
              'plastic': /local/mijnafvalwijzer/plastic3.png
              'Geen': /local/mijnafvalwijzer/kliko_geen.png
          - type: picture-entity
            entity: sensor.afval_overmorgen
            name: Overmorgen
            show_state: false
            state_image:
              'Gft': /local/mijnafvalwijzer/gft3.png
              'Papier': /local/mijnafvalwijzer/papier3.png
              'Restafval': /local/mijnafvalwijzer/restafval3.png
              'Plastic': /local/mijnafvalwijzer/plastic3.png
              'Geen': /local/mijnafvalwijzer/kliko_geen.png

      - type: glance
        entities:
         - entity: sensor.gft_formatted
           name: GFT
         - entity: sensor.papier_formatted
           name: Papier
         - entity: sensor.plastic_verpakkingsafval_formatted
           name: Plastic
         - entity: sensor.restafval_formatted
           name: Restafval

      - type: divider

      - type: entities
        entities:
         - entity: automation.afval_vandaag
           name: Notify vandaag
         - entity: automation.afval_morgen
           name: Notify morgen
5 Likes

Thanks for explaining and the needed files, works as expected now :wink:

1 Like

sure, you’re welcome.

If you’d like the text in the Lovelace card to follow the type of trash to be picked up, have a look here: