Garbage pickup date (mijnafvalwijzer.nl) custom_component


#147

As I replied in a PM I noticed that the following example URL isn’t working for your postal code and house number. It seems like an issue at mijnafvalwijzer.nl, perhaps you can contact them that you can’t get json data from their website.

http://json.mijnafvalwijzer.nl/?method=postcodecheck&postcode=3582ES&street=&huisnummer=1&toevoeging=

Also in version 2.0.0 (major rewrite), I added a lot of exception handling, so the component will give a nice message in the log that no data was received instead of the error posted by robertjanb.


#148

Hey there,

Yeah I got the same issue unfortunately (NOK). I think my city changed something because the login screen says my address is not known (I am pretty sure it exists…). I’ll send them an email, but thanks anyway for developing the component!


#149

…in the meantime mijnafvalwijzer.nl stated that the usage of json.mijnafvalwijzer.nl is only allowed for paying customers, great security :joy:.

Anyhow, I modified the sensor to make sure it’s futureproof in case mijnafvalwijzer is closing up the json url. I now created a scraper which can be tested. Be aware the date format has changed form %Y-%m-%d to %d-%m-%Y.


#150

Hi guys,

thanks for the nice custom component, was thinking of using ical inputs for the trash pickup dates. But this works so much better.

However, i can’t seem to get the custimization working…

  • i have all the correct icons with the correct trash type
  • i have the dates in the (almost) correct way (it’s stil in english… can’t seem to get it in dutch*)
    • Home assistant is set to dutch
  • tried a lot of templates for the sensors, but none of them are working. Do i need to have custom_ui installed for the templates to work? can’t seem to get it right…


#151

i use this for customizations (and yes, have custom-ui installed):

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

sensor.trash_today:
  friendly_name: 'Trash today'
  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';
    _stateDisplay: >
     if (state === 'papier') return 'Papier';
     if (state === 'gft' ) return 'Gft';
     if (state === 'plastic verpakkingsafval') return 'Plastic';
     if (state === 'restafval') return 'Restafval';
     return 'Geen';

sensor.trash_tomorrow:
  friendly_name: 'Trash tomorrow'
  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';
    _stateDisplay: >
     if (state === 'papier') return 'Papier';
     if (state === 'gft' ) return 'Gft';
     if (state === 'plastic verpakkingsafval') return 'Plastic';
     if (state === 'restafval') return 'Restafval';
     return 'Geen';

#152

do we set this up as usual or have to add _scraper in the sensor platform? I get a config error now…

EDIT_
nevermind, think I got it working, renamed the component to mijnafvalwijzer.py…

please let me ask this:

will the state for the plastic sensor be sensor.trash_plastic, or as it used to be plastic_verpakkingsmateriaal. And, related, will the trash_today and _tomorrow use plastic, or plastic_verpakkingsmateriaal.
I can’t find it in the inspector just yet, but your component seems to have changed that?

secondly, something is amiss with the dates, have a look. It seems to skip 2 dates and jumps to 14 februari for Papier:

29

while this is in the app:


#153

Thanks!

seems the custom_ui thing did the trick!!
Sorry for the weird question :confused:

I’m gonna try my hand on making a telegram notification with inline keyboard… will post if it works :wink:


#154

Have notifications for you if you want … just let me know.

Btw it is sensor.trash_next with the new CC version


#155

Hi Marius, is the new cc version running fine now, or do you still have some issues? From now on I`ll make release notes with changes and breaking changes so there’s more info about what has actually changed.

Sensors are created based on the name of mijnafvalwijzer with the prefix “trash_”. For my region f.e. I have only “Papier, GFT, Restafval and Plastic”, so the sensors “trash_papier, trash_gft, trash_restafval and trash_plastic” are generated. trash_today, trash_tomorrow, trash_next will remain the same in upcoming releases.

I was thinking of creating one sensor with multiple attributes, but I`m not sure if that would be a better approach. Perhaps someone else at this topic knows :face_with_raised_eyebrow:?


#156

running fine! except for the strange thing about missing out on 2 pickup dates in februari, as I showed you.

about the plastic sensor, I’ll be sure when it happens.

did you ever see my automation based on the trash sensors today and tomorrow. They’re much smaller than the big conditional templates:

  - 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')}}

and:

  - alias: 'Afval vandaag alt'
    id: 'Afval vandaag alt'
    initial_state: on
    trigger:
      platform: time
      hours: 7 
      minutes: 0
      seconds: 0
    condition:
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_utility', 'on')}}
      - condition: template
        value_template: >
          {{states('sensor.trash_today') != 'Geen'}}
    action:
      - service: notify.notify
        data_template:
          message: >
            Het is vandaag {{ now().strftime("%d %B") }}.
              {{states('sensor.trash_today')|title}} wordt vandaag 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.trash_today')|title}} wordt vandaag opgehaald!'
          title: >
            'Trash today: '

#157

Thanks for sharing, I agree the automation I use is a bit outdated :slight_smile:.

I don’t see what’s wrong actually. GFT is correct, plastic is correct, and restafval is correct, but I don’t see the next pickup date for papier in the app, is it really before 14 feb? The naming for plastic depends what you gemeente has provided to mijnafvalwijzer. It could be plastic_verpakkingsmateriaal in 2018, while in 2019 they changed it to just plastic.


#158

well, the app says so, and this is what’s on the webpage:


#159

I think I don’t understand what the problem is. The next pickup dates are matching on the website, app and mijnafvalwijzer component as far as I can see.

…or do you mean the list order on the lovelace card?


#160

not the order, but the dates:
25

shouldn’t this show the next few pickups? it goes from jan 22 to 29 , which is correct, then jumps to feb 14, and misses out on feb 5 and 7…


#161

No, this is correct. For every trash type the first next upcoming pickup date, nothing in between :smiley:.


#162

a ok, if this is per design, all is well then :wink:

would you accept a feature request for an extra: to have the dates listed in order of next appearance? as on the website, maybe for the next month? If at all possible scraping the site of course.


#163

I’m afraid that’s not possible with hass as a sensor has a single state, perhaps as an attribute…