Garbage pickup date (mijnafvalwijzer.nl) custom_component

well thats nice, and maybe an automation can be built on the other notification:
if tomorrow is a pickup day, show this scrape tomorrow…? something like that?

Seems a bit wird these scrape sensors, not as ‘programmable’ as the regular api sensors. But maybe there’s no other way…

btw, i think there’s also a Nextday? maybe thats scalable too? That way we would have both. Current and next.

thats very nice! How can we use that in Hassio? Don’t think i’ve ran a bash script before in the setup.

btw, might i ask if you have any experience with the techniques used in this Epson cartridge level program. I have it working up to the actual ink-levels, but down think i use the correct ‘scraping’ technique.
Maybe you can guide meow to proceed, thx!

Would you mind to share youre complete (working) code for this garbage collection . I’m fighting for several days
now but i’m not able to get this working. What I want is to trigger at let say 8:00PM and if there is a garbage pickup scheduled in the google calendar within the next 24 hours and then select , based on the message parameter (GFT, PLASTIC, RESTAFVAL), a correct message and picture to send a notify with telegram.

Thanks in advance.

@proton999
In order to keep this thread clean, I’ve created a new thread, See my solution here: https://community.home-assistant.io/t/another-way-of-garbage-pickup-notifications

hi,
its a bit off, have a look:

07

today is Restafval, not Papier…
maybe theres a typo in your sensor value, it’s showing the . after restafval?

made a customization for this:

sensor.afval_soort:
  templates:
    entity_picture: >
     if (entity.state = 'Papier') return '/local/mijnafvalwijzer/papier.png';
     else if (entity.state = 'Gft' ) return '/local/mijnafvalwijzer/gft.png';
     else if (entity.state = 'Plastic verpakkingsafval') return '/local/mijnafvalwijzer/plastic.png';
     else if (entity.state = 'Restafval') return '/local/mijnafvalwijzer/restafval.png';
     else return '/local/mijnafvalwijzer/kliko.png';

13

cool.
Cheers,
Marius

1 Like

Nice work!

As Marius stated, to keep this post clean, I’ve uploaded all code to Github:

I also made some modifications/improvements to the custom component.

  • Now less sensors are needed
  • The loop for parsing json from mijnafvalwijzer has been improved, no more nasty break!
  • Dynamicaly built the Python TRASH_TYPES dictionary. No more static content.

Next steps:

  • Add fault handling

nice, will install after reading this :wink:

as you can see in the screenshot above, the sensor Afval soort (showing papier) doesnt correspond with the AfvalDatum sensor (3 april in his case, where Gft will be picked up)…

might have to add some logic to the sensor, cause as i can see the full page, it is quite difficult to parse and scrape like this without getting the incorrect results…

Anyways, Cheers!
Marius

You could add this, that should help you resolve the issue you have:

  • platform: template
    sensors:
    afval_vandaag:
    friendly_name: “Afval vandaag”
    value_template: >-
    {% if is_state(‘sensor.afval_datum’, ‘vandaag’) %}
    {{states.sensor.afval_soort.state}}
    {% else %}
    Geen
    {% endif %}
1 Like

will do, thanks!
unfortunately this is not working as hoped for:

36

the state is correct: Geen. still the value_template results in Papier, which is indeed the next pickup…sensor afval_datum is 3 april, not Vandaag so the template should point to the ‘else’ bit, resulting in Geen :wink: Don’t know why this doesnt happen (yet)

I noticed mijnafvalwijzer swtiches between the trash pickup today and the next pickup date using the same classname. Therefor the sensor probably isn’t reliable using the scrape platform.

ive found my customizing to be incorrect, this seems to be more to the point:

sensor.afval_soort:
  templates:
    entity_picture: >
     if (state === 'Papier') return '/local/mijnafvalwijzer/papier.png';
     else if (state === 'Groente, Fruit en Tuinafval' ) return '/local/mijnafvalwijzer/gft.png';
     else if (state === 'Plastic verpakkingsafval') return '/local/mijnafvalwijzer/plastic.png';
     else if (state === 'Restafval') return '/local/mijnafvalwijzer/restafval.png';
     else return '/local/mijnafvalwijzer/kliko.png';

sensor.afval_vandaag:
  templates:
    entity_picture: >
     if (state === 'Papier') return '/local/mijnafvalwijzer/papier.png';
     else if (state === 'Groente, Fruit en Tuinafval' ) return '/local/mijnafvalwijzer/gft.png';
     else if (state === 'Plastic verpakkingsafval') return '/local/mijnafvalwijzer/plastic.png';
     else if (state === 'Restafval') return '/local/mijnafvalwijzer/restafval.png';
     else return '/local/mijnafvalwijzer/kliko.png';

works for today :wink:

41

installed the latest version, which took some adjusting in the templating… :wink:

still, works out beautifully.

took out the double Afval Soort and Afval Vandaag, since they both pointed to the same, and Vandaag uses Soort as a value_template anyhow.

07

maybe you’re interested in the extra automation for an extra notification on the pick-up-day itself:

   - alias: 'Afval vandaag'
    trigger:
      - platform: time
        hours: 7 
        minutes: 0
        seconds: 0
    condition:
      - condition: template
        value_template: '{{ states.sensor.afval_datum.state == "vandaag" }}'
    action:
      - service: notify.notify
        data_template:
          message: 'Het is vandaag {{ now().strftime("%Y-%m-%d") }}.
                    Zet het {{states.sensor.afval_soort.state}} aan de straat!'
      - service: persistent_notification.create
        data_template:
          title: 'Afvalmelding: {{states.sensor.afval_soort.state}}'
          message: 'Het is vandaag {{ now().strftime("%Y-%m-%d") }}.
                    Zet het {{states.sensor.afval_soort.state}} aan de straat!'

shows:

55

hope this works too…

  - alias: 'Afval morgen'
    trigger:
      - platform: time
        hours: 20 
        minutes: 0
        seconds: 0
    condition:
      - condition: template
        value_template: '{{ now().strftime("%Y-%m-%d") == 
                         (as_timestamp(states.sensor.afval_soort.state) - 
                         (24*3600)) | timestamp_custom("%Y-%m-%d") }}'
    action:
      - service: notify.notify
        data_template:
          message: 'Het is vandaag {{ now().strftime("%Y-%m-%d") }}.
                    {{states.sensor.afval_soort.state}} wordt morgen opgehaald!'
      - service: persistent_notification.create
        data:
          message : 
            'Het is vandaag {{ now().strftime("%Y-%m-%d") }}.
                    {{states.sensor.afval_soort.state}} wordt morgen opgehaald!'
          title: 'Morgen {{states.sensor.afval_soort.state}}'

if desired, one could further change the date of course, leaving out the year, as i’ve done in the group.

Anyways, lots of things to play with, maybe combine into one templated automation. Thanks to your efforts!

Cheers,
Marius

Great work, using a lot of your package! The only thing I’m missing are good entity_pics. Any change of you uploading them?

thanks!

sure:

asbestelecgftkringloopglasmilieustraatpapierplastictextielrestafvalkcakliko

cheers,
Marius

1 Like

Holy pictogram Batman, you’re fast :smiley:

Quick question: any idea why

trash_gft_date:
    friendly_name: 'Gft'
    value_template: '{{ as_timestamp(states.sensor.trash_gft.state) | timestamp_custom("%Y-%m-%d") }}' 

Is returning None? sensor.trash_gft exists, with date, and …gft_date has friendly name Gft and the correct picure. Already trying a few hours, but untill now no luck…

you should check your own situation but over here it is called ‘Groente, Fruit en Tuinafval’
hence:

sensor.afval_vandaag:
  templates:
    entity_picture: >
     if (state === 'Papier') return '/local/mijnafvalwijzer/papier.png';
     else if (state === 'Groente, Fruit en Tuinafval' ) return '/local/mijnafvalwijzer/gft.png';
     else if (state === 'Plastic verpakkingsafval') return '/local/mijnafvalwijzer/plastic.png';
     else if (state === 'Restafval') return '/local/mijnafvalwijzer/restafval.png';
     else return '/local/mijnafvalwijzer/kliko.png';

are you using the latest version of the CC? It changed the creation of the sensors, and lost the trailing _date…

i have this now (and changed the representation of the date too, i know which year it is most of the time) :

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

  - platform: template
    sensors:
      restafval:
        friendly_name: 'Restafval'
        value_template: 
           '{{ as_timestamp(strptime(states.sensor.trash_restafval.state, "%Y-%m-%d")) | timestamp_custom("%d %B") }}'
      plastic_verpakkingsafval:
        friendly_name: 'Plastic'
        value_template: 
           '{{ as_timestamp(strptime(states.sensor.trash_plastic_verpakkingsafval.state, "%Y-%m-%d")) | timestamp_custom("%d %B") }}' 
      gft:
        friendly_name: 'Gft'
        value_template: 
           '{{ as_timestamp(strptime(states.sensor.trash_gft.state, "%Y-%m-%d")) | timestamp_custom("%d %B") }}'
      papier:
        friendly_name: 'Papier'
        value_template: 
           '{{ as_timestamp(strptime(states.sensor.trash_papier.state, "%Y-%m-%d")) | timestamp_custom("%d %B") }}'
      afval_vandaag:
        friendly_name: "Afval vandaag"
        value_template: >-
           {% if is_state('sensor.afval_datum', 'vandaag') %}
            {{states.sensor.afval_soort.state}}
            {% else %}
            Geen
            {% endif %}
1 Like

Yes, thats it: strptime was the missing part, learned something again. Thanks a million!

1 Like

well, it doesn’t… the value_template returns none… which is logical, since it compares 2 different entities…
wonder if we could compact the trash tomorrow automation using a better value_template, (the action part works fine) and prevent the need for the conditions for all trash types … Any thoughts on this @xirixiz @robertjanb ?

HI,
An effort to try this with “day_after_tomorrow” which shows on the native App and the website, won’t work. There must be a setting hidden in the html page for day after tomorrow, or next-pickup, but i cant seem to locate it. Would you know how to create a sensor for that, using either scrape or other platform sensor?