Garbage pickup date (mijnafvalwijzer.nl) custom_component

The skalava is nice, i think i’ll give that a shot. Since it also has the ios notification reminders.

So after leaving HA for a few days I saw that the sensors are not upadting their value at all and that was half the problem. As of a breaking change in HA 0.81 your code needs to be edited to inlcude “entity_id” to update automatically.

However the problem of the value being one day short still remains. If garbage collection is 8 days away the sensor value is 7 days. Does anyone have an idea what yould be wrong and why this happens? I have all day events in my google calendar and this is the sensor code:

  - platform: template
    sensors:
       plastik_abholung:
          friendly_name: Plastik
          entity_id: sensor.date
          unit_of_measurement: "Tage"
          value_template: >
            {% set pickupday = strptime(states.calendar['wertstofftonne'].attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%A") %}
            {% set pickupday2 = strptime(states.calendar['wertstofftonne'].attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%b %d, %Y") %}
            {% if as_timestamp(states.calendar.wertstofftonne.attributes.start_time) / 86400 - as_timestamp(now()) / 86400 == 0.0 %}
              - TODAY -
            {% elif as_timestamp(states.calendar.wertstofftonne.attributes.start_time) / 86400 - as_timestamp(now()) / 86400 == 1.0 %}
              TOMORROW
            {% elif as_timestamp(states.calendar.wertstofftonne.attributes.start_time) / 86400 - as_timestamp(now()) / 86400 >= 7.0 %}
               {{ (as_timestamp(states.calendar.wertstofftonne.attributes.start_time) / 86400 - as_timestamp(now()) / 86400) | int  }} Tg.
            {% elif as_timestamp(states.calendar.wertstofftonne.attributes.start_time) / 86400 - as_timestamp(now()) / 86400 >= 2.0 %}
              {{ pickupday }}
            {% else %}
              TODAY
            {% endif %}

I’m breaking my head around this. Can’t get the component to work anymore.

This happens when I check my config:
Platform not found: sensor.afvalwijzer

And when I reboot the system my log says:
You are using a custom integration for afvalwijzer which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.

Hi Patrick,

What does your directory structure look like? It has to look like this:
custom_components/afvalwijzer/

With the following files:

__init__.py
manifest.json (optional)
sensor.py

Hi Xirixiz,

Yes it does.

Tried a fresh download of your github page this morning. My homeassistant is on version 0.92.2

I’ve even updated my python version to 3.7.3 (as suggested in https://github.com/xirixiz/Home-Assistant-Sensor-Afvalwijzer/issues/10)

I’ve also doublechecked the permissions. I’m able to acces and edit the files as the homeassistant user. ls -al seems right to.

So, my Gemeente finally uses the json as well via Afvalwijzer. But now it’s again not working here, here’s my log:

2019-05-09 14:57:15 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform afvalwijzer
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 126, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/lib/python3.6/asyncio/tasks.py”, line 358, in wait_for
return fut.result()
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/afvalwijzer/sensor.py”, line 84, in setup_platform
json_obj = response.json()
File “/srv/homeassistant/lib/python3.6/site-packages/requests/models.py”, line 897, in json
return complexjson.loads(self.text, **kwargs)
File “/usr/lib/python3.6/json/init.py”, line 354, in loads
return _default_decoder.decode(s)
File “/usr/lib/python3.6/json/decoder.py”, line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python3.6/json/decoder.py”, line 357, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Any idea what I did wrong?

EDIT: My bad, i was using

postcode: ‘!secret postcode’
huisnummer: ‘!secret huisnummer’

But this threw errors.
Should be:

postcode: !secret postcode
huisnummer: !secret huisnummer

It’s working now!

A missing dependency on bs4 failed to make it run for me. pip install bs4 solved it.

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!