Garbage pickup date (mijnafvalwijzer.nl) custom_component

Hey Marius,

try this line

value_template: '{{ now().strftime("%Y-%m-%d") == (as_timestamp(strptime(states.sensor.trash_gft.state, "%Y-%m-%d")) - (24*3600)) | timestamp_custom("%Y-%m-%d") }}          

This will give you a boolean answer, i am not 100% sure it works as of yet, but it looks good.

works here, thanks! don’t really understand why it stopped working in the syntax i posted, got nice notifications before.

Also, without strftime, this works fine:

 - alias: 'Afval vandaag'
    initial_state: on
    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("%d %B") }}.
                    Zet het {{states.sensor.afval_soort.state}} aan de straat!'
      - service: persistent_notification.create
        data_template:
          title: 'Afvalmelding Vandaag: {{states.sensor.afval_soort.state}}'
          message: 'Het is vandaag {{ now().strftime("%d %B") }}.
                    Zet het {{states.sensor.afval_soort.state}} aan de straat!'

Dit you perhaps switch to the latest version? https://github.com/xirixiz/home-assistant-config

I’ve made some date/time modifications…

I did yes.
Ive added the as_timestamp(strptime and the automation seems to run with that, will see on the day of pickup :wink:

any chance an automation like my Afval vandaag, with a value_template and data_templates for Afval Morgen? Yours soes work, but requires the hard coding of the trash types, which id rather set using the template as in Afval Vandaag.

I think I can add those sensors rather easy to the custom_component. I`ll verify it Tonight.

1 Like

cool, would be a nice addition to a really useful HomeAssistant tool :wink: please keep us updated!

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

Please try :slight_smile:

No pickup day today or tomorrow result in an unknown state. If there is some garbage to pickup, the sensor will update sensor.trash_today or sensor.trash_tomorrow with the garbage type to be picked up.

hi,
will test. just to be sure, the component doesn’t create a sensor.trash_ per trash_type anymore, only the trash_today and _tomorrow, which will then have the trash_type as value?

Will need to change a lot of template sensors and automation if so…

It should show all other sensors with just an addition of two more sensors called trash_today and trash_tomorrow. I just modified the module again, I had some datetime parsing issues.

The sensors now look like:

Could you please give it another try?

sure i will!
had given it some effort already trying to customize a bit, indeed found the other sensors were still there :wink:

cant find the right customization to change the state into something prettier yet:

06

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

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

Id like the state to show Gft, instead of gft, (bot sure what the sensor finds for the other values yet) and the Unknown to be ‘Geen’, as my _stateDisplay template is trying to do. No luck yet …

since you brought it up: would you consider changing this format a bit?d = datetime.strptime(item['date'], "%Y-%m-%d") Its almost always the same year, so this order takes away some unnecessary Card space (imho).

Ive change that in the value_templates:

papier:
        friendly_name: 'Papier'
        value_template: 
         `  '{{ as_timestamp(strptime(states.sensor.trash_papier.state, "%Y-%m-%d")) | timestamp_custom("%d %B") }}'` 

which renders the screen I posted. Seems somewhat more to the point than starting each line with 2018 :wink:

Thank you for this component and the additional today and tomorrow sensors. The problem I encountered, and maybe some other people as well, is that in my region there is a possibility of that more than 1 kind of trash will be picked up on the same day. For example today the plastic was picked up, but also the gft/restafval. In the today/tomorrow sensor I can only see the plastic will be picked up today. Below a picture of my dashboard. I can fix this for myself with some templating or python script but maybe the best solution would be if you could implement it in the component.

Afval

Thanks again!

1 Like

hi @xirixiz, your new component seems to work just fine, thanks.

Im using your large template automation for tomorrows pickup, and would like to compress that to:

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

unfortunately the ‘{{ states.sensor.afval_datum.state }}’ renders 19 april, and not ‘tomorrow’ which would make templating easier…
could you help in creating a template the calculates the date of tomorrow, in this case 19 april, to be a day after the current date?
that would enable the automation im looking for, in a way you use yourself with the current big automation, where you subtract (1 * 86400 )…
Hope you understand what im asking here…
Cheers,
Marius

hallo @xirixiz,

I think i’m gonna love this component. The thrash is piling up here, due to bad memory :wink:
The link to your component is not working. I would like to implement this in my hassio. Can you provide the new link to your component?

1 Like

well, of course i had mistyped…
its working just fine with the correct spacing :wink:

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

Cheers,
Marius

MMM, i want to use te same way to display my schedule. but my customize rules don’t apply after restart. Can you see why?

result_afval

It looks like it’s using an older version of my scripts.

Hi,
After installing the latest version of the files from github and the given automations i get the error:

Error:
Error doing job: Task exception was never retrieved

Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/components/automation/init.py”, line 335, in async_trigger
if skip_condition or self._cond_func(variables):
File “/usr/lib/python3.6/site-packages/homeassistant/components/automation/init.py”, line 444, in if_action
return all(check(hass, variables) for check in checks)
File “/usr/lib/python3.6/site-packages/homeassistant/components/automation/init.py”, line 444, in
return all(check(hass, variables) for check in checks)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/condition.py”, line 317, in template_if
return async_template(hass, value_template, variables)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/condition.py”, line 299, in async_template
value = value_template.async_render(variables)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/template.py”, line 132, in async_render
return self._compiled.render(kwargs).strip()
File “/usr/lib/python3.6/site-packages/jinja2/asyncsupport.py”, line 76, in render
return original_render(self, *args, **kwargs)
File “/usr/lib/python3.6/site-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/usr/lib/python3.6/site-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File “/usr/lib/python3.6/site-packages/jinja2/_compat.py”, line 37, in reraise
raise value.with_traceback(tb)
File “”, line 1, in top-level template code
TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘int’

Home Assistant 0.68.0 on Hassio
Automation:

  • alias: ‘Trash - Groene bak’
    trigger:
    • platform: time
      hours: 12
      minutes: 57
      seconds: 0
      condition:
    • condition: template
      value_template: ‘{{ now().strftime("%Y-%m-%d") == (as_timestamp(strptime(states.sensor.trash_gft.state, “%Y-%m-%d”)) - (24*3600)) | timestamp_custom("%Y-%m-%d") }}’
      action:
    • service: notify.bericht_rik_mobiel
      data_template:
      message: ‘Het is vandaag {{ now().strftime("%d-%m-%Y") }}. De groene container wordt morgen geleegd.’

Can you help?

Please check the examples here:

I did check the examples. I get the errors. Who can help me?

After re checking the automations and retry i get the error:
Error during or-condition: unsupported operand type(s) for -: ‘NoneType’ and ‘int’

  • alias: ‘Trash - One day before’
    trigger:
    • platform: time
      hours: 8
      minutes: 50
      seconds: 0
      condition:
      • condition: or
        conditions:
        • condition: template
          value_template: ‘{{- (now().strftime("%Y-%m-%d")) == (as_timestamp(strptime(states.sensor.trash_gft.state, “%Y-%m-%d”)) - (1 * 86400 )) | timestamp_custom("%Y-%m-%d") -}}’
        • condition: template
          value_template: ‘{{- (now().strftime("%Y-%m-%d")) == (as_timestamp(strptime(states.sensor.trash_restafval.state, “%Y-%m-%d”)) - (1 * 86400 )) | timestamp_custom("%Y-%m-%d") -}}’
          action:
    • service: notify.bericht_rik_mobiel
      data_template:
      message: >-
      {% if (now().strftime("%Y-%m-%d")) == (as_timestamp(strptime(states.sensor.trash_gft.state, “%Y-%m-%d”)) - (1 * 86400 )) | timestamp_custom("%Y-%m-%d") %}
      Het is vandaag - {{ now().strftime("%Y-%m-%d") }}. De groene bak wordt geleegd op: {{ states.sensor.trash_gft.state }}!
      {% endif %}
      {% if (now().strftime("%Y-%m-%d")) == (as_timestamp(strptime(states.sensor.trash_restafval.state, “%Y-%m-%d”)) - (1 * 86400 )) | timestamp_custom("%Y-%m-%d") %}
      Het is vandaag - {{ now().strftime("%Y-%m-%d") }}. De grijze bak wordt geleegd op: {{ states.sensor.restafval.state }}!
      {% endif %}