Bin Sensors in Home Assistant - Scrape

Continuing on from last week’s post, I’ll cover the new (and hopefully improved) version which adds to the Mushroom Chips I use at the start of my main dashboard. This is a slightly more complicated approach, but should also be kept up to date if the schedule changes as it uses the Scrape Integration to pull the information directly from a website.

Dashboard Chips

My local council has a webpage per street in the area which shows which bin(s) are due to be collected in the current week. The main index page for this is here - Bin collections and calendar.

Once you select a region and a street, you are presented with something like this:

Bin webpage example

This shows either one or two bins depending on the schedule for the current week, as well as their names. From this I’ll be picking up what the type of bin is as well as the colour for using in the chip.

For each bin, this is the HTML that we ultimately want to extract values from is:

<li>
  <h4>Food and garden <br/><p>No liquids, oils or plastic bags. <a href="https://www.southlanarkshire.gov.uk/info/200156/bins_and_recycling/1841/bins_-_what_goes_in_them/3">More info</a></p></h4>
  <img src="https://www.southlanarkshire.gov.uk/images/bin-red.png" alt="red bin">
</li>

» Continue reading


Bin Sensors in Home Assistant - Shell & Template

As part of my Home Assistant dashboard I want to include useful information which is not directly related to smart devices in my home.

With the uptick in recycling in recent years, we now have 4 different bins that need to go out on the street on different weeks for collection. On the off-chance I’m one of the first in the street to be putting one or more of them out, I wanted a quick way to work out which should be going out.

The bins go out on a fixed day of the week, with a routine like this:

Bin Type Schedule
Black/Green - Non Recyclable Waste Thursday (Fortnightly)
Burgundy - Food and garden Thursday (Fortnightly)
Blue (paper and card) Thursday (4 Weekly)
Light Grey - Glass, cans and plastics Thursday (4 Weekly)

My first version of this dashboard element looks like this:

Dashboard Card

This shows:

  1. The bin(s) that are due to go out next
  2. The day & date of the next collection
  3. The number of days until the next collection

This requires some custom sensors to hold the next collection date and type, and there are (at least) two approaches that can be taken to achieve this:

  1. Using the shell command integration and a pair of python scripts
  2. Using a couple of template sensors

» Continue reading


Counting Sensors in Home Assistant

I have been building up my Home Assistant dashboard for a while, mostly using Mushroom Cards. My main dashboard started off largely inspired by this Everything Smart Home tutorial and has continued to evolve as I have thought of new ways to make it more useful.

At the very top of my dashboard I have a few informational chips:

Dashboard Chips

From left to right is the built-in weather chip, followed by a count of the lights currently on and then a count of devices that have updates available to them.

These latter two chips use custom sensors created using the template integration and took a bit of fiddling to get working right, so I thought it was at least worth sharing my configuration. Yours will likely be a bit different depending on exactly what combination of devices & integrations you use. This integration is not currently configurable through the user interface so requires updates to the Home Assistant configuration.yaml file (or whereever you have your cusom sensors defined).

» Continue reading


Cloudflare Redirects

There have been a couple of scenarios recently where I thought some additional subdomains and/or path redirects would be useful.

  1. I always forget the capitalisation in the URL for my OpenAPIVisualiser tool, so wanted a redirect from “devwithimagination.com/oav” to the full URL for the project
  2. While I have a “.scot” domain for my profile at the moment, I wanted to have “about.devwithimagination.com” redirect to it.

This post, like many of mine, exists as a reminder to myself how this is setup as it took me a few reads of the documentation to understand this and when I did I found that I’ve done this before.

» Continue reading


Restarting PoE via SSH on a USW-Lite-16-PoE

I recently moved my Unifi controller off of my Proliant MicroServer and on to a Raspberry Pi, which is powered via PoE from my main Unifi USW-Lite-16-PoE switch. This evening this Pi was unresponsive, and unlike on the MicroServer there is no out-of-band interface I could use to restart it. If this did not host the Unifi controller I could have used the controller to power-cycle the PoE port, but as the controller couldn’t be accessed either I needed another approach. While I could have just got up and went under the stairs to pull some cables, it would be preferable to be able to solve this via SSH.

There are many posts on the Unifi community forums with solutions for this involving telnet after connecting to the switch via SSH, but telnet is not available on the newer devices like the USW-Lite-16-PoE.

I came across this reddit post which pointed me in the direction of the swctrl poe command.

To list the PoE status of the ports on this device that support PoE:

NetworkRack-USW-Lite-16-US.6.2.5# swctrl poe show id 1-8
Total Power Limit(mW): 45000

Port  OpMode      HpMode    PwrLimit   Class   PoEPwr  PwrGood  Power(W)  Voltage(V)  Current(mA)
                              (mW)                                                               
----  ------  ------------  --------  -------  ------  -------  --------  ----------  -----------
   1    Auto        Dot3at     32000  Class 2      On     Good      1.38       53.24        26.00
   2    Auto        Dot3at     32000  Unknown     Off      Bad      0.00        0.00         0.00
   3    Auto        Dot3at     32000  Class 4      On     Good      3.40       53.11        64.00
   4    Auto        Dot3at     32000  Unknown     Off      Bad      0.00        0.00         0.00
   5    Auto        Dot3at     32000  Unknown     Off      Bad      0.00        0.00         0.00
   6    Auto        Dot3at     32000  Class 4      On     Good      6.81       53.24       128.00
   7    Auto        Dot3at     32000  Unknown     Off      Bad      0.00        0.00         0.00
   8    Auto        Dot3at     32000  Class 3      On     Good      4.63       53.24        87.00

This doesn’t include any of the port labels, but at a guess the highest current draw is likely the Pi that has hung.

This port can be turned off by running swctrl poe set off id 6, then switched back on with swctrl poe set auto id 6.

As a word of caution with this though - originally I had ran swctrl poe set off 6 (note the missing id between off and 6). This is the incorrect syntax, so it ignores the number and turned PoE off on all ports of the switch. This was a problem for me as the Wifi Access Points were also powered by this switch so I needed to go reconnect with a cable to re-enable PoE for the access points too.

A safer option, sent in by Shawn Kelley, is the restart command. So instead of setting poe “off” then “on” you can run swctrl poe restart id 6 to power cycle the port.