Garbage pickup date (mijnafvalwijzer.nl) custom_component

thnx for you’re reply, but stil not one card but spaces .
When want to edit this “card” it’s also displayed as separate cards:

yes I feared you are using the UI editor, hence the strange order of keys… using yaml mode here.

must be an indent, I only changed your own code, to have the better readable order. If you check carefully with my setup, you might find one or the other card listed under another main type?

Check the types that stack the other cards with special attention.
Maybe check the order also? As I have it, just to see if that makes a difference?

Using the UI , and then the RAW editor

this is most awkward, because when I enter your exact code (and change one of the states to ‘plastic’) I see this:

all nicely attached… (never mind the rounded corners, its because Im experimenting with a global setting in my theme)
corrected as follows:

1 perfect vertical-stack-in-card

1 Like

Has somebody an idea. Have this error for two sensors:
One trash_restafval and the trash_papier

Update for sensor.trash_restafval_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 238, 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

like to post an update to the lovelace card I made, which makes the entity_picture cards ‘blink’ when today or tomorrow 's trash is active, (and a persistent notification has ben made, and the trash hasn’t been moved outside yet) (or the input_boolean hasn’t been switched (which dismisses the persistent notification in my setup):

only the part for the 3 pictures in my card:

      - type: horizontal-stack
        cards:
          - type: picture-entity
            style: |
              ha-card {
                border-radius: 0px;
                animation: {% if is_state('persistent_notification.trash_notification', 'notifying') and
                                   states('sensor.trash_today') != 'Geen' %} blink 2s linear infinite;
                           {% else %} none
                           {% endif %}
              }
              @keyframes blink {
                100% {opacity: 0;}
                }

#              ha-card {
#                border-radius: 0px;
#                animation: {% if is_state('persistent_notification.trash_notification', 'notifying') %} wiggle 1s linear infinite alternate;
#                           {% else %} none
#                           {% endif %}
#              }
#              @keyframes wiggle {
#                0% {
#                  -webkit-transform: rotate(5deg);
#                  transform: rotate(5deg);
#                }
#                100% {
#                  -webkit-transform: rotate(-5deg);
#                  transform: rotate(-5deg);
#                }
#              }
            entity: sensor.trash_today
            name: Vandaag
            show_state: false
            state_image:
              'gft': /local/mijnafvalwijzer/gft3.png
              'papier': /local/mijnafvalwijzer/papier3.png
              'restafval': /local/mijnafvalwijzer/restafval3.png
              'plastic': /local/mijnafvalwijzer/plastic.png
              'Geen': /local/mijnafvalwijzer/kliko_geen.png
          - type: picture-entity
            style: |
              ha-card {
                border-radius: 0px;
                animation: {% if is_state('persistent_notification.trash_notification', 'notifying') and
                                   states('sensor.trash_tomorrow') != 'Geen' %} blink 2s linear infinite;
                           {% else %} none
                           {% endif %}
              }
              @keyframes blink {
                100% {opacity: 0;}
                }
            entity: sensor.trash_tomorrow
            name: Morgen
            show_state: false
            state_image:
              'gft': /local/mijnafvalwijzer/gft3.png
              'papier': /local/mijnafvalwijzer/papier3.png
              'restafval': /local/mijnafvalwijzer/restafval3.png
              'plastic': /local/mijnafvalwijzer/plastic3.png
              'Geen': /local/mijnafvalwijzer/kliko_geen.png
          - type: picture-entity
            style: |
              ha-card {
              border-radius: 0px;
              }
            entity: sensor.afval_overmorgen
            name: Overmorgen
            show_state: false
            state_image:
              'Gft': /local/mijnafvalwijzer/gft3.png
              'Papier': /local/mijnafvalwijzer/papier3.png
              'Restafval': /local/mijnafvalwijzer/restafval3.png
              'Plastic': /local/mijnafvalwijzer/plastic3.png
              'Geen': /local/mijnafvalwijzer/kliko_geen.png

commented is another way to draw attention: wiggle the picture-entity, which is also nice :wink:
for completenes’s sake, and because I use a different automation logic than @xirixiz’s repo Ill share these below too:

##############################################################################################################
# Automations
##############################################################################################################

automation:

##############################################################################################################
# Vandaag moet het afval worden voorgezet
##############################################################################################################

  - alias: 'Afval vandaag'
    id: 'Afval vandaag'
    trigger:
      platform: time
      at: '07:00:00'
    condition:
      condition: template
      value_template: >
        {{states('sensor.trash_today') != 'Geen'}}
    action:
      - service: script.intercom_message
        data_template:
          message_nl: >
            Het is {{now().strftime('%A %-d %B')}}: vandaag wordt {{states('sensor.trash_today')}} opgehaald!
          message_en: >
            It is {{now().strftime('%A %-d %B')}}: today {{states('sensor.trash_today')}} will be collected!
      - service: script.notify_trash_today
      - service: script.persistent_trash_today
      - service: script.trash_outside_today

##############################################################################################################
# Morgen moet het afval worden voorgezet
##############################################################################################################

  - alias: 'Afval morgen'
    id: 'Afval morgen'
    trigger:
      platform: time
      at: '21:00:00'
    condition:
      - condition: template
        value_template: >
          {{states('sensor.trash_tomorrow') != 'Geen'}}
    action:
      - service: script.intercom_message
        data_template:
          message_nl: >
              Het is {{ now().strftime('%d %B') }}: Morgen wordt
              {{states('sensor.trash_tomorrow')|title}} opgehaald!
          message_en: >
              It is {{ now().strftime('%d %B') }}: Tomorrow
              {{states('sensor.trash_tomorrow')|title}} will be picked up!
      - service: script.notify_trash_tomorrow
      - service: script.persistent_trash_tomorrow
      - service: script.trash_outside_tomorrow

  - alias: Reset trash notification
    trigger:
      platform: state
      entity_id: input_boolean.trash_outside
      to: 'on'
      for:
        hours: 5
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.trash_outside

  - alias: Mark trash as moved outside from notification
    trigger:
      platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: MARK_TRASH_MOVED
    condition:
      condition: template
      value_template: >
        {{(trigger.event.data.actionName == 'MARK_TRASH_MOVED')}}
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.trash_outside
      - service: persistent_notification.dismiss
        data:
          notification_id: trash-notification
      - service: notify.ios_phone
        data:
          title: 'Ios notification:'
          message: >
            Afval staat aan de straat
          data:
            push:
              badge: 0
              sound: US-EN-Morgan-Freeman-Garage-Door-Closed.wav
##############################################################################################################
# Scripts
##############################################################################################################

script:
  notify_trash_today:
    alias: 'Notify trash today'
    sequence:
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_utility', 'on')}}
      - service: notify.notify
        data_template:
          title: >
            {{ now().strftime('%d %B') }}: Afvalmelding vandaag
          message: >
            {{states('sensor.trash_today')|title}} wordt vandaag opgehaald!

  persistent_trash_today:
    alias: Persistent trash today
    sequence:
      - condition: template
        value_template: >
          {{ is_state('input_boolean.persistent_notification_create', 'on')}}
      - service: persistent_notification.create
        data_template:
          notification_id: >
            trash-notification
          title: >
            {{ now().strftime('%d %B') }}: Afvalmelding vandaag
          message: >
            {{states('sensor.trash_today')|title}} wordt vandaag opgehaald!

  notify_trash_tomorrow:
    alias: 'Notify trash tomorrow'
    sequence:
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_utility', 'on')}}
      - service: notify.notify
        data_template:
          title: >
            {{ now().strftime('%d %B') }}: Afvalmelding morgen
          message: >
            {{states('sensor.trash_tomorrow')|title}} wordt morgen opgehaald!

  persistent_trash_tomorrow:
    alias: 'Persistent trash tomorrow'
    sequence:
      - condition: template
        value_template: >
          {{ is_state('input_boolean.persistent_notification_create', 'on')}}
      - service: persistent_notification.create
        data_template:
          notification_id: >
            trash-notification
          title: >
            {{ now().strftime('%d %B') }}: Afvalmelding morgen
          message: >
            {{states('sensor.trash_tomorrow')|title}} wordt morgen opgehaald!

  trash_outside_tomorrow:
    alias: Trash outside tomorrow
    sequence:
      - condition: template
        value_template: >
          {{is_state('input_boolean.trash_outside','off')}}
      - condition: template
        value_template: >
          {{is_state('input_boolean.trash_reminder','on')}}
      - service: notify.ios_phone
        data_template:
          title: 'Ios notification'
          message: >
            {{ states('sensor.trash_tomorrow')|title }} wordt morgen opgehaald, zet het afval aan de straat
          data:
            push:
              badge: 5
              category: 'afval'
              sound: US-EN-Alexa-Garage-Door-Opened.wav

  trash_outside_today:
    alias: Trash outside today
    sequence:
      - condition: template
        value_template: >
          {{is_state('input_boolean.trash_outside','off')}}
      - condition: template
        value_template: >
          {{is_state('input_boolean.trash_reminder','on')}}
      - service: notify.ios_phone
        data_template:
          title: 'Ios notification'
          message:  >
            {{ states('sensor.trash_today')|title }} wordt vandaag opgehaald, zet het afval aan de straat
          data:
            push:
              badge: 5
              category: 'afval'
              sound: US-EN-Alexa-Garage-Door-Opened.wav
            action_data:
              entity_id: input_boolean.trash_outside

###############################################################################################################
## Ios
###############################################################################################################
#
ios:
  push:
    categories:
      - name: Afval
        identifier: 'afval'
        actions:
          - identifier: 'MARK_TRASH_MOVED'
            title: 'Afval verwerkt'
            activationMode: 'background'
            authenticationRequired: no
            destructive: yes
#            behavior: 'default'

###############################################################################################################
## Inputs
###############################################################################################################

input_boolean:
  trash_outside:
    name: Trash is outside
    initial: 'off'
    icon: mdi:delete-empty

  trash_reminder:
    name: Trash reminder enabled
    #initial: 'on'
    icon: mdi:cellphone-message
3 Likes

Hi Dennis,

I guess the data you receive doesn’t have any value. Maybe I should build in some verification as more people tend to have this in the past. However, could you run HASS in de debug mode for the custom_component? Can you see data when you logon to mijnafvalwijzer.nl?

logger:
  default: warn
  logs:
    homeassistant.components.sensor: debug
    custom_components.sensor.mijnafvalwijzer: debug

@xirixiz The sensors don 't get an value I guess. Because for paper afvalwijzer uses opk. And for restafval we don 't use the grey trash. Think that’s a problem.
But Let me check to debug mode when i’m at home.

@silver323 Then that’s the problem most probably. Unfortunatly mijnafvalwijzer doesn’t use a naming convention, so sensors are being populated based on the name mijnafvalwijzer returns from the api call. You need to check which sensors are being populated in HASS and use that name.

http(s)://<hass_url>/developer-tools/state

and search for:

sensor.trash_

Now I removed the two sensor that where not in use. Not getting the errors anymore. So only the sensors thats getting information are left in the files.

added another nicety for the afvalwijzer setup: a simple button to confirm the trash has been moved outside (after a persistent notification has been made to do so). This button works for both todays and tomorrows notification. And is in fact a substitute in the frontend for dismissing the notification and blink/wiggle by acting upon the iOS notification, which does the same:

type: conditional
conditions:
  - entity: persistent_notification.trash_notification
    state: notifying
card:
  type: custom:button-card
  template: button_body
  entity: automation.mark_trash_as_moved_outside_from_notification
  name: Mark trash outside
  label: >
    [[[ var trash = states['sensor.trash_today'].state != 'Geen' 
        ? states['sensor.trash_today'].state : states['sensor.trash_tomorrow'].state;
    return trash.charAt(0).toUpperCase() + trash.slice(1); ]]]
  icon: mdi:delete-alert
  show_state: false
  styles:
    card:
      - animation: blink 2s ease infinite
      - background-color: lightgrey
    label:
      - color: >
          [[[ var trash = states['sensor.trash_today'].state != 'Geen' 
              ? states['sensor.trash_today'].state : states['sensor.trash_tomorrow'].state;
          if (trash == 'papier') return 'blue';
          if (trash == 'gft' ) return 'green';
          if (trash == 'plastic') return 'orange';
          if (trash == 'restafval') return 'black';
          return 'ivory'; ]]]
    icon:
      - color: >
          [[[ var trash = states['sensor.trash_today'].state != 'Geen' 
              ? states['sensor.trash_today'].state : states['sensor.trash_tomorrow'].state;
          if (trash == 'papier') return 'blue';
          if (trash == 'gft' ) return 'green';
          if (trash == 'plastic') return 'orange';
          if (trash == 'restafval') return 'black';
          return 'ivory'; ]]]
  tap_action:
    action: navigate
    navigation_path: /lovelace/tijd_agenda
  hold_action:
    action: call-service
    service: automation.trigger
    service_data:
      entity_id: entity

tap the button , and navigate to the page with the other afvalwijzer card(s), hold it and dismiss. Purposely used this and not vice versa to prevent accidental dismissing.

of course you can change to your liking, just thought Id share

1 Like

Thanks for sharing Marius! Good job! Do you have a screenshot perhaps?

sure, though its a bit difficult right now, as no trash is picked today or tomorrow… and the state keeps flipping back to ‘Geen’…

faked it quickly:

39

btw, the automation, was posted already above

I’ve decided to give it another shot and integrate mijnafvalwijzer with hass. Anyone like to contribute? I’m more of an advanced scripter rather than a programmer, so I could use some help from a programmer… :grinning:

I’d like to do the same thing as Twente Milleu: https://github.com/home-assistant/home-assistant/tree/dev/homeassistant/components/twentemilieu

2 Likes

The first release of the Python library has been added to PyPi!
The next step is to add a component to HASS making use of the Python library.

2 Likes

I tried again, but still not attached together .
Did you try the code within the yaml itself, or in de raw UI editor ? it seems to be that the custom card isn’t recognized correctely

I use yaml mode

All, I decided to stop improving this component. I’ve created a python library which can be used, and maybe someone else can create a new component to use with HASS. I really liked HASS but, but I decided to go with a more mature (payed) platform. I faced to many issues with for example my Philips HUE setup and I really like things just to work instead of reparing it often.

o that’s too bad really, sorry to hear you say that.
Really enjoying the component as it is today, it is one of the more helpful ones in the setup!

As for Hue: ever since upgrading to I think 101 + there have been no more issues in 3 of my HA instances. (and I was one of the heavy posters on the various issues…)
Hue has been rock solid, even with the Hue custom component installed. And I have a lot of customized entities, and control the Hue api from within HA by means of several very complex scripts and automations. I can set all thresholds, schedules etcetera. No errors at all…

So if you need some Hue assistance, don’t hold back.
And, as expressed many times before: thanks for the CC!

1 Like

Just tryed the link not working :frowning: