home assistant rubbish collection

Quick Project: Follow up to my Home Assistant Rubbish Collection Panel

This post may contain affiliate links. Please see the disclaimer for more information.

Last month, I wrote a quick post about the Home Assistant Rubbish Collection panel I made for the Lovelace UI. Well, it looks like amaximus was inspired to create his own custom card to do a similar thing. [NOTE: the author of this card hasn’t contacted me directly (I came across it via HACS), I’m only claiming to be the inspiration based on the relative dates].

This card has a couple of cool capabilities that my previous panel didn’t have. Specifically, you can set colour coded icons for your different bins and the icon will change style and colour (to red) when the bin is due to go out in the next day. You can also hide the card completely if a bin is not due to go out within X days.

home assistant rubbish collection
Cards for all four of my sensors, with colour coded icons
home assistant rubbish collection
If the collection is the next day the icons change to red

Installation and Setup

I installed the card by adding a git submodule to my configuration repository in the www/plugins directory, but you can also install directly from HACS. I’m switching over to adding all my custom components and cards as submodules in order to make my config more easily deployable.

After installation, you need to add the path to the garbage-collection-card.js file in the resources section of your Lovelace UI config:

resources:
  - type: js
    url: /local/plugins/garbage-collection-card/garbage-collection-card.js

Once that’s done you can add cards to the UI. I just put mine in a vertical stack to group them together:

type: vertical-stack
cards:
  - type: 'custom:garbage-collection-card'
    entity: sensor.food_scraps
    hide_date: true
    icon_color: green
    icon_size: 48px
  - type: 'custom:garbage-collection-card'
    entity: sensor.general_recycling
    hide_date: true
    icon_color: yellow
    icon_size: 48px
  - type: 'custom:garbage-collection-card'
    entity: sensor.glass_recycling
    hide_date: true
    icon_color: blue
    icon_size: 48px  
  - type: 'custom:garbage-collection-card'
    entity: sensor.landfill
    hide_date: true
    icon_color: red
    icon_size: 48px

…and that’s it! If you want to hide a card for bins that don’t need to go out soon use hide_before: x (where x is the number of days). I’ll probably use this to hide bins that don’t need to go out in the current week, but I wanted to show all the cards in the screenshots 😉

Conclusion

I think this is a great improvement on my previous panel, so I’m going to stick with it. Thanks to the author another contributors for taking the time to make it!

It’s kinda cool to think that this blog may have inspired someone else to go out and write some code! If you are inspired to make and share something as a result of one of my posts, please get in contact! Your work will most likely get featured in a future blog post.

If you liked this post and want to see more, please consider subscribing to the mailing list (below) or the RSS feed. You can also follow me on Twitter. If you want to show your appreciation, feel free to buy me a coffee.

home assistant rubbish collection

Quick Project: Rubbish Collection Panel for Home Assistant

This post may contain affiliate links. Please see the disclaimer for more information.

With my local council rolling out an increasingly complex system of rubbish bins and collection, I’ve been thinking about getting this integrated with Home Assistant so that we don’t have to remember which bins go out when. I was presently surprised to find the garbage_collection custom component whilst browsing HACS the other day. This component does exactly what I need, so I decided to give it a go.

Rubbish Collection Configuration

After installing the component via HACS, I set about configuring it. Here is the configuration I came up with:

sensor:
  - platform: garbage_collection
    name: Food Scraps
    frequency: "weekly"
    collection_days: !secret rubbish_collection_day
  - platform: garbage_collection
    name: General Recycling
    frequency: "odd-weeks"
    collection_days: !secret rubbish_collection_day
  - platform: garbage_collection
    name: Glass Recycling
    frequency: "even-weeks"
    collection_days: !secret rubbish_collection_day
  - platform: garbage_collection
    name: Landfill
    frequency: "even-weeks"
    collection_days: !secret rubbish_collection_day

That was easy! The only non-obvious thing is working out which bins are collected on even and odd weeks, which is easy to look up online.

Getting it into Lovelace

The garbage_collection component page in HACS has a nice screenshot of the sensors in Lovelace (which doesn’t seem to be in the repository readme). However, the sensors themselves have a state based on whether the bin is due to be put out. The state is nice and machine readable, but I wanted to recreate the panel from the screenshot for the humans that have to look at it. In the end I actually decided to simplify it down to just show “today”, “this week” or “next week” plus the number of days, since the actual date is pretty irrelevant.

home assistant rubbish collection
The finished rubbish collection panel in my Lovelace UI

This proved to be more difficult than I’d expected, since Lovelace doesn’t support templates in cards natively. I had to install the Lovelace Card Templater plugin via HACS. This plugin in turn requires the card-tools plugin, which I couldn’t find in HACS. I ended up installing it by adding it as a git submodule to my configuration repository. I then added the following to my Lovelace config to load the plugins:

resources:
  - type: js
    url: /local/plugins/lovelace-card-tools/card-tools.js?v=1
  - type: js
    url: /community_plugin/lovelace-card-templater/lovelace-card-templater.js

Full Panel YAML

The panel itself is made up of a vertical stack card in which I put two horizontal stack cards. These in turn contain two of the templater cards. The configuration of the templater cards is a little involved since you need to specify the entity twice (which seems to be due to some internal limitation of Lovelace). My template cards are based on the sensor card to show just the data from the template. I use a state_template to do this.

Anyway, here’s the full YAML:

cards:
  - cards:
      - card:
          entity: sensor.food_scraps
          type: sensor
        entities:
          - entity: sensor.food_scraps
            state_template: >-
              {% if state_attr("sensor.food_scraps", "days") == 0 %} Today {%
              elif state_attr("sensor.food_scraps", "days") < 7 %} This Week {%
              else %} Next Week {% endif %} ({{ state_attr("sensor.food_scraps",
              "days") }} days)
        type: 'custom:card-templater'
      - card:
          entity: sensor.general_recycling
          type: sensor
        entities:
          - entity: sensor.general_recycling
            state_template: >-
              {% if state_attr("sensor.general_recycling", "days") == 0 %} Today
              {% elif state_attr("sensor.general_recycling", "days") < 7 %} This
              Week {% else %} Next Week {% endif %} ({{
              state_attr("sensor.general_recycling", "days") }} days)
        type: 'custom:card-templater'
    type: horizontal-stack
  - cards:
      - card:
          entity: sensor.glass_recycling
          type: sensor
        entities:
          - entity: sensor.glass_recycling
            state_template: >-
              {% if state_attr("sensor.glass_recycling", "days") == 0 %} Today
              {% elif state_attr("sensor.glass_recycling", "days") < 7 %} This
              Week {% else %} Next Week {% endif %} ({{
              state_attr("sensor.glass_recycling", "days") }} days)
        type: 'custom:card-templater'
      - card:
          entity: sensor.landfill
          type: sensor
        entities:
          - entity: sensor.landfill
            state_template: >-
              {% if state_attr("sensor.landfill", "days") == 0 %} Today {% elif
              state_attr("sensor.landfill", "days") < 7 %} This Week {% else %}
              Next Week {% endif %} ({{ state_attr("sensor.landfill", "days") }}
              days)
        type: 'custom:card-templater'
    type: horizontal-stack
type: vertical-stack

Each of the templater cards is pretty much the same. I just change the entity ID for each. The only improvement I would make would be to add a line break between the “Today”/”This week”/Next Week” text and the day count, since this would look slightly better. I couldn’t work out how to do that however.

Conclusion

I think I’ve achieved my goal of simplifying the task of remembering which bins go out when. Now I can quickly check that info with a glance at my HASS UI. Of course, now that I have the rubbish collection data in Home Assistant I can use it for other things such as notifications or reminder lights. I already have some ideas for status lighting, so that might become part of a larger project.

I’d like to say thanks to the authors of the custom components and plugins that I’ve used to achieve this. The HASS community really is thriving will all these third party addons at the moment!

If you liked this post and want to see more, please consider subscribing to the mailing list (below) or the RSS feed. You can also follow me on Twitter. If you want to show your appreciation, feel free to buy me a coffee.

Lovelace Multi-room Audio Contols

Quick Project: Lovelace Multi-Room Audio Controller

This post may contain affiliate links. Please see the disclaimer for more information.

Welcome to a new segment on my blog! Here I’m going to do quick write ups of some of the little projects that I complete. These projects often come between the bigger ones that I usually write about. This is going to be bit of an experiment, but I’m aiming to publish these in addition to my usual blogging schedule. However, they will be done as time permits so may not be as regular.

I wanted to start doing posts like this, since I realised I do quite a few small projects which never make it onto the blog. Primarily this is because I just forget about them once they’re complete. Let’s see how it goes and please let me know if you like these posts in the comments or via Twitter.

Today’s Project: a Lovelace Multi-Room Audio Controller

This post is about a bit of playing around I was doing in Lovelace (the new Home Assistant UI) over the weekend. I started out installing the Home Assistant Community Store (HACS) and came across the Mini Media Player card. This struck me as the perfect thing for making better controls for my multi-room audio system. Without further ado, here are the finished Lovelace multi-room audio controller in all its glory:

Lovelace Multi-room Audio Contols
I love the beautifully minimalist look of this

Basically, we have controls of the main Mopidy music player. This is followed by the volume controls for the overall Snapcast group and the individual Snapcast clients. This is pretty much a copy of the layout in the Snapcast Android client. However, that lacks any way to control the player.

Get to the YAML!

Below is the YAML I used to create my Lovelace multi-room audio controller. Is should be noted that this can be entered through the GUI editor, by just switching to the raw editor. You don’t need to be using YAML mode.

type: vertical-stack
cards:
  - artwork: cover
    entity: media_player.mopidy
    group: true
    hide:
      source: true
      volume: true
    icon: 'mdi:music-circle'
    name: Multi-Room Audio
    type: 'custom:mini-media-player'
  - entity: media_player.snapcast_group_mopidy
    group: true
    hide:
      controls: true
      power: true
      power_state: true
      source: true
      volume: false
    icon: 'mdi:speaker-multiple'
    name: Master Volume
    type: 'custom:mini-media-player'
  - entity: media_player.snapcast_client_outdoor_speakers
    group: true
    hide:
      controls: true
      power: true
      power_state: true
      source: true
      volume: false
    icon: 'mdi:speaker-multiple'
    type: 'custom:mini-media-player'
  - entity: media_player.snapcast_client_soundbar
    group: true
    hide:
      controls: true
      power: true
      power_state: true
      source: true
      volume: false
    icon: 'mdi:speaker-multiple'
    type: 'custom:mini-media-player'
  - entity: media_player.snapcast_client_bedroom_tv
    group: true
    hide:
      controls: true
      power: true
      power_state: true
      source: true
      volume: false
    icon: 'mdi:speaker-multiple'
    type: 'custom:mini-media-player'

This consists of a vertical stack card containing several mini media player cards with the group setting set to true to make them nest fine into a what appears visually to be a single control panel. I then just use the hide parameters to get rid of the controls I don’t need on each one and add a custom icon for each. Done!

Conclusion

I really like this layout. The only improvement I can think of would be if the cover artwork for the currently playing track was displayed. You can see I’ve tried this in the YAML above, but it didn’t work for me. This might be more of a limitation of the MPD integration in HASS than of mini media player.

That’s it for now. Again, please let me know if you like this post format and I’ll keep doing them in between my other posts.

If you liked this post and want to see more, please consider subscribing to the mailing list (below) or the RSS feed. You can also follow me on Twitter. If you want to show your appreciation, feel free to buy me a coffee.