Garbage pickup date (mijnafvalwijzer.nl) custom_component

Replying to myself, this is what eventually worked:

  - platform: template
    sensors:
      afvalwijzer_gft_friendly:
        value_template: > 
                           {{ as_timestamp(strptime(state_attr("sensor.afvalwijzer_gft", "year_month_day_date"), "")) | timestamp_custom('%a %d/%m') }}
        icon_template: mdi:apple
1 Like

And as sharing is caring, this is the full code I use, as the solution above broke ordering by days until pickup. This way this attribute is also added (and of course you can choose to add other attributes in a similar way:

#Transform to day dd/mm
  - platform: template
    sensors:
      afvalwijzer_gft_friendly:
        value_template: > 
          {{ as_timestamp(strptime(state_attr("sensor.afvalwijzer_gft", "year_month_day_date"), "")) | timestamp_custom('%a %d/%m') }}
        attribute_templates:
          days_until_collection_date: >
            {{state_attr("sensor.afvalwijzer_gft","days_until_collection_date")}}
        icon_template: mdi:apple
        friendly_name: 'Afvalwijzer GFT'

Have it installed. First through HACS, but didn`t work. Then removed it, restarted the PI and did it by hand. But no sensors. I have the latest updates and get the next error in the logfile:

Logger: homeassistant.components.sensor
Source: custom_components/afvalwijzer/provider/afvalwijzer.py:69
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 15:39:40 (1 occurrences)
Last logged: 15:39:40

Error while setting up afvalwijzer platform for sensor

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/afvalwijzer/sensor.py", line 68, in async_setup_platform afvalwijzer = await hass.async_add_executor_job( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/afvalwijzer/provider/afvalwijzer.py", line 69, in __init__ ( TypeError: cannot unpack non-iterable NoneType object
1 Like

HI @xirixiz

upon updating to HA 2021.8.2, I see this in the ha core check:

INFO:custom_components.afvalwijzer.const.const:
-------------------------------------------------------------------
Afvalwijzer
This is a custom integration!
If you have any issues with this you need to open an issue here:
https://github.com/xirixiz/homeassistant-afvalwijzer/issues
-------------------------------------------------------------------

not even sure what it means, but maybe worth a look? (didnt yet raise an issue in the GitHub, because I am not sure yet what the implications are…)

Hehehe, I just followed the HACS basics by integrating this :).
It’s just to make sure people are aware that it’s a custom component and where to open an issue, if any :).

right :wink: never saw it afterwards must confess… not using HACS anyways

hello ,

can anybody tel me where i can find the images
it was not in the zip file
the images that i use now it for testing

image

which images?
did you check the thread above? there are many images available…

even on the repo: https://github.com/xirixiz/my-hass-config/tree/master/www/afvalwijzer

so stupid. is missed that

thx

Any news on the error above? I have the same problem

Can you tell me what you did so the sensors where found?
I’m trying to install but get the same error as you before.

Same here, I have been trying to install it as well and keep getting the same error too. I will wait for an update on the integration.

since the template was posted here, this is for now a placeholder in migration to 2021.10 + given the templating changes that were made on the default values one templates. This:

{%- set tracker_timestamp = as_timestamp(strptime(states('sensor.afvalwijzer_next_date'),'%d-%m-%Y')) %}
          {%  set months = ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'] %}
          {%- set wdays = ['Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag'] %}
          {%- set wday = tracker_timestamp|timestamp_custom('%w')|int %}
          {%- set month = tracker_timestamp |timestamp_custom('%m')|int %}
          {{tracker_timestamp|timestamp_custom(wdays[wday]  ~ ' ' '%-d' ' ' ~ months[month-1])}}

results in 3 errors (repeating)

2021-10-12 00:53:36 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'strptime' got invalid input 'Geen' when rendering template '{%- set tracker_timestamp = as_timestamp(strptime(states('sensor.afvalwijzer_next_date'),'%d-%m-%Y')) %} {%  set months = ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'] %} {%- set wdays = ['Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag'] %} {%- set wday = tracker_timestamp|timestamp_custom('%w')|int %} {%- set month = tracker_timestamp |timestamp_custom('%m')|int %} {{tracker_timestamp|timestamp_custom(wdays[wday]  ~ ' ' '%-d' ' ' ~ months[month-1])}}' but no default was specified. Currently 'strptime' will return 'Geen', however this template will fail to render in Home Assistant core 2021.12
2021-10-12 00:53:36 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'Geen' when rendering template '{%- set tracker_timestamp = as_timestamp(strptime(states('sensor.afvalwijzer_next_date'),'%d-%m-%Y')) %} {%  set months = ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'] %} {%- set wdays = ['Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag'] %} {%- set wday = tracker_timestamp|timestamp_custom('%w')|int %} {%- set month = tracker_timestamp |timestamp_custom('%m')|int %} {{tracker_timestamp|timestamp_custom(wdays[wday]  ~ ' ' '%-d' ' ' ~ months[month-1])}}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2021.12
2021-10-12 00:53:36 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_custom' got invalid input 'None' when rendering template '{%- set tracker_timestamp = as_timestamp(strptime(states('sensor.afvalwijzer_next_date'),'%d-%m-%Y')) %} {%  set months = ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'] %} {%- set wdays = ['Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag'] %} {%- set wday = tracker_timestamp|timestamp_custom('%w')|int %} {%- set month = tracker_timestamp |timestamp_custom('%m')|int %} {{tracker_timestamp|timestamp_custom(wdays[wday]  ~ ' ' '%-d' ' ' ~ months[month-1])}}' but no default was specified. Currently 'timestamp_custom' will return 'None', however this template will fail to render in Home Assistant core 2021.12

i have posted it also in a dedicated thread on the templating changes for some help, but thought a repost here might be a good idea.

Not sure if simply defaulting any of these should be the solution, maybe we need the entities which are used in this template, specifically the sensor.afvalwijzer_next_date to have another state than Geen…

to be continued

this should be it:

      - unique_id: volgende_afval_ophaal_dag
        name: Volgende afval-ophaal dag
        state: >
          {%- set tracker_timestamp = as_timestamp(strptime(states('sensor.afvalwijzer_next_date'),'%d-%m-%Y',none),none) %}
          {%  set months = ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'] %}
          {%- set wdays = ['Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag'] %}
          {%- set wday = tracker_timestamp|timestamp_custom('%w',default=none)|int %}
          {%- set month = tracker_timestamp |timestamp_custom('%m',default=none)|int %}
          {{tracker_timestamp|timestamp_custom(wdays[wday]  ~ ' ' '%-d' ' ' ~ months[month-1],default=none)}}

Marius, I am using your card.
It’s looking great! :grinning:
Recently the HA templates have been changed and a default has to be added.
You mentioned in an example a “default=none”.

Where do I need to add the default’s in your card?

Other question:
The card shows the month in short format and in English i.e. Oct.
I would like to see the month in full format and in Dutch, so: oktober in stead of Oct.
This will look much better on the card because the text is in Dutch.
I know it’s a small detail.

It shows:
Restafval komende Dinsdag (3 dagen) 19 Oct
Preferred is:
Restafval komende dinsdag (3 dagen) 19 oktober

you can use this for the month in Dutch

      - unique_id: maand
        name: Maand
        state: >
          {% set maanden = ['Januari','Februari','Maart','April','Mei','Juni','Juli',
                            'Augustus','September','Oktober','November','December'] %}
          {% set maand = maanden[now().month -1] %}
          {{maand}}

as for the defaults, see 1 post above yours…
as far as my template entity row card goes, I haven’t received a warning yet in the logs… so will leave it as it is for now.
Petro has summed all necessary changes in a dedicated post, you should check that

2 Likes

can someone please explain what i have to do, to get the sensors shown?
thanks.

what i did is the following:
install the integration in HACS

You can follow the README at this repo: GitHub - xirixiz/homeassistant-afvalwijzer: Provides sensors for the Dutch waste collector mijnafvalwijzer.nl and/or afvalstoffendienstkalender.nl
You need to add some config manually in order to make it work.

Hi, is there anyone able to help me out creating a config flow for GitHub - xirixiz/homeassistant-afvalwijzer: Provides sensors for the Dutch waste collector mijnafvalwijzer.nl and/or afvalstoffendienstkalender.nl. I’ve tried but I wasn’t able to make it work properly. I hope someone can help here as I don’t have enough time to create the config flow on my own currently.

i tried before many times, give it a change again and it works.
thnx.

1 Like

since yesterday the sensor is not loaded anymore and the logs show this

Error while setting up afvalwijzer platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/afvalwijzer/sensor.py", line 67, in async_setup_platform
    afvalwijzer = await hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/afvalwijzer/provider/afvalwijzer.py", line 69, in __init__
    (
TypeError: cannot unpack non-iterable NoneType object