Garbage pickup date (mijnafvalwijzer.nl) custom_component

Have it served from homeassistant itself
https://my-ip:8123/local/file.json

json file in local folder

Now we just need a switch :slight_smile:
:wink:

Could someone help with how to use this component?

  1. Iā€™ve placed the script in: /config/custom_components/sensor/
  2. But the sensor is not displayed in the states.

What steps am I missing?

You have to add the sensor under your sensor attribute:

- platform: mijnafvalwijzer
  postcode: !secret afvalwijzer_postcode
  huisnummer: !secret afvalwijzer_huisnummer
  toevoeging: !secret afvalwijzer_toevoeging
1 Like

Thanks! That did the trick.

1 Like

@xirixiz fantastic component and very usefull. Maybe you can update the script so it use httpS (https://github.com/xirixiz/home-assistant/blob/master/custom_components/sensor/mijnafvalwijzer.py#L58), currently youā€™re using http :(. AfvalWijzer works secure, they badly donā€™t force itā€¦

HI @xirixiz

you probably noticed followingthe tag I created , but please update the custom component with the correct version format, so the custom component card can track your component:

Hahaha, great job Marius! Iā€™ve been quiet busy, so I didnā€™t found the time yet to investigate this matter.
I just adjusted the custom_component with ā€œversion = ā€˜1.1.4ā€™ā€. Can you verify if itā€™s working?

The custom_component now uses https

If someone could make this work for IVIO, thatā€™d be brilliant!

Iā€™ve got a bad feeling that ivio doesnā€™t have a public rest api though

I will, but have to see if this update doesnā€™t brake any of the sensors and automations I use, while still on 1.0.2ā€¦

I am trying to get this to work, but when I add the sensor information in my configuration file all my sensors disappear in my dashboard.
Also checking the configuration file through the settings page (I am using Hassio) does not seem to work. It does not say it is not valid, but it keeps showing like it is checking.
Any ideas what I can check?

Just to confirm, I have the following in my configuration file:

  • platform: mijnafvalwijzer
    postcode: 1111AA
    huisnummer: 11

Postcode is not real.

I have /config/custom_components/sensor/mijnafvalwijzer.py for the custom component

please format your code correctly (using the </>) so we can see if the code is alright.

you should have this in your yaml:

sensor:
  - platform: mijnafvalwijzer
    postcode: !secret postcode
    huisnummer: !secret huisnummer

the path of the file is correct.

youā€™re sure the py file itself is copied correctly? You should download the raw file, (and check if it isnā€™t 0 bytes also, have seen that fly by here)

It was the py file itself, thanks for the tip on the raw file download. That was the problem.
Not sure how it happened, but the file was 102KB. After doing a raw download it is 7KB and working!

Great! Thans Marius for providing support, Iā€™ve been quiet busy lately :roll_eyes:

It was working fine (0.82.x) and then I updated to (0.83.3)

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 70, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 301, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 168, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f2500041518>: Failed to establish a new connection: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='json.mijnafvalwijzer.nl', port=443): Max retries exceeded with url: /?method=postcodecheck&%20%20%20%20%20%20%20%20%20%20%20%20%20postcode=1234AB&street=&huisnummer=1&toevoeging=&%20%20%20%20%20%20%20%20%20%20%20%20%20platform=phone&langs=nl& (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f2500041518>: Failed to establish a new connection: [Errno 101] Network is unreachable',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/app/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/sensor/mijnafvalwijzer.py", line 114, in update
    self.data.update()
  File "/usr/src/app/homeassistant/util/__init__.py", line 324, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/sensor/mijnafvalwijzer.py", line 133, in update
    response = requests.get(self._url)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='json.mijnafvalwijzer.nl', port=443): Max retries exceeded with url: /?method=postcodecheck&%20%20%20%20%20%20%20%20%20%20%20%20%20postcode=1234AB&street=&huisnummer=1&toevoeging=&%20%20%20%20%20%20%20%20%20%20%20%20%20platform=phone&langs=nl& (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f2500041518>: Failed to establish a new connection: [Errno 101] Network is unreachable',))

Anyone else got this issue?

Hi, Iā€™m using currently the 'mijnafvalwijzer.nl component. There are a few things that are strange.

  • The ā€˜custom updaterā€™ in configuration.yaml is giving errors. Iā€™ve deactivated at the moment and the dates are still correct.

  • Also itā€™s showing the ā€˜empty binā€™ icon, and Iā€™am some how not able to change that to the nice png shown in this topic (in customization.yaml).

my customization.yaml code:

sensor.trash_gft:
  friendly_name: 'GFT'
  templates:
entity_picture: >
 if (state === 'gft') return '/icons/Afvalwijzer/gft.png';
  _stateDisplay: >
 if (state === 'gft') return 'GFT';

Iā€™m doing something wrong, but what? who can point me in the right direction.

Thanks!

because the template looks for a state ā€˜gftā€™ while in fact it is a time sensor:

also,your spacing is rather offā€¦and you should also take care for the ā€˜elseā€™, and if no option is needed, state null.
not sure if it solves your issue but at least code like this:

sensor.trash_gft:
  friendly_name: 'GFT'
  templates:
    entity_picture: >
      if (state === 'gft') return '/icons/Afvalwijzer/gft.png';
      return null;
    _stateDisplay: >
      if (state === 'gft') return 'GFT';
      return null;

that being said, fwiw, I have hidden these sensors and created a few template sensors based on:

  afval_vandaag:
    friendly_name: 'Afval vandaag'
    value_template: >-
       {% if is_state('sensor.afval_datum', 'vandaag') %}
        {{states('sensor.afval_soort')}}
        {% 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_vandaag') %}
      {{ mapper[state] if state in mapper else '/local/mijnafvalwijzer/kliko.png' }}

and

  - platform: scrape
    resource: !secret scrape_resource_date
    name: Afval Datum
    select: ".firstDate"
    scan_interval: 60

  - platform: scrape
    resource: !secret scrape_resource_type
    name: Afval Soort
    select: ".firstWasteType"
    scan_interval: 60

1 Like

Hi Sjorsjes, dit you notice this error

Failed to establish a new connection: [Errno 101] Network is unreachable',

Is it resolved now? It seems you couldnā€™t establish a connection to mijnafvalwijzer.nl, or mijnafvalwijzer.nl had some issues.

I also released a new version recently (1.1.5). Now, if there are multiple pickups Today or Tomorrow, the sensor provides a comma seperated list of all garbage types.

https://github.com/xirixiz/home-assistant-config/blob/master/custom_components/sensor/mijnafvalwijzer.py

Yeah I think that me or afvalwijzer just had a connection hiccup and canā€™t reproduce the error. I updated to 1.1.5 and, with some lovelace love and template magic, it works like a charm :slight_smile: Just need to spend some time to find better resolution icons :wink:

afvalwijzer