By Casey Liss
Mailbox Delivery Notifications

Ultimately, it’s all John’s fault.

I was listening to one of my absolute favorite podcasts, and on this particular episode, John was discussing how he wanted a way to be aware of when someone in his house leaves the refrigerator door open. This seems like a very difficult challenge to solve, because refrigerators tend to be not terribly penetrable to radio waves or other means of getting data out of the fridge.

Affiliate links abound from here, but that's not the point. I really do love this stuff.

John landed on LoRa, specifically YoLink temperature sensors. These little doodads can sit in the fridge, and send “LOng RAnge” transmissions to the required hub, which in turn can be viewed in their app.

While this ended up being relevant for me due to simultaneous refrigerator disasters, that wasn’t what piqued my interest at the time. What got me intrigued was the alleged range of LoRa: roughly a quarter mile, or around 400 meters.

Our driveway is quite short — less than 20 meters long — but it was annoying going out there a couple times a day just to see if the mail had been delivered. Sometimes we could hear the dilapidated exhaust of the mail truck as it rolled by, but often not.

Surely technology — LoRa specifically — could fix this problem.

I found a YoLink “starter pack” that included two contact sensors and a hub. This was $50 at the time, and had everything I needed to get going. Once it arrived, I attempted to install the contact sensor in the mailbox, but couldn’t quite get the fitment right. So I installed it outside the mailbox instead, on the trailing side, from the carrier’s perspective.

Erin often points out to me how much this looks like it’s wired to explode. She’s… not wrong. But it’s been in place and working for nearly a year now.

A close-up of a mailbox, with a contact sensor mounted to both the door
              and the box itself. There's a wire running from the outside of the mailbox
              to a covered area of the post the mailbox is mounted to. It looks shady as hell.

This got me to the point that the YoLink app would notify me — and only me — when the mail was delivered. But I can do better.


I’ve become of of those people. Sometime last year, I decided that I should give Home Assistant another shot. I had tried it once several years earlier, found it entirely inscrutable, and bailed. I went with Homebridge instead, which was far easier for me to understand. But the call of Home Assistant was strong… especially because the zealots are many, and they are loud.

(One of us! One of us!)

I’m now very much one of these jackasses. I can’t help it. They got me.

(One of us! One of us!)

So, armed with my new contact sensor powered by YoLink, I wanted to see if I could make Home Assistant aware of when the mailbox is opened. This was trivial, as there is an official YoLink integration.

Now that Home Assistant is aware of the state of the mailbox’s door, I could have some fun. However, the door doesn’t tell me whether or not there’s mail within the mailbox; only the state of the door. Can I do better?

Our mail is pretty consistent; it almost never comes before noon. If the mailbox is opened before noon, 99% of the time it’s because we’re putting outgoing mail in there.

This is where my automation can start: the when of the automation is, of course, when the mailbox is opened. The conditions (And if) is if the time is after 10 AM, to leave a little buffer.

In YAML form, here’s what we’re working with so far:

alias: Mailbox Opened
description: ""
triggers:
  - type: opened
    device_id: [device ID]
    entity_id: [entity ID]
    domain: binary_sensor
    trigger: device
conditions:
  - condition: time
    after: "10:00:00"
    weekday:
      - sun
      - mon
      - tue
      - thu
      - wed
      - sat
      - fri

Everything was working great; I added a Pushover notification action to my automation, and my phone would now get a push notification whenever the mail was delivered.

However, I was also getting the same notification when the mail was checked. That could not stand. It was time to get smart.


What I landed on was taking note of the last time the mailbox was opened; that is stored in an input_datetime Helper. Based on this, we can take different actions.

If the mailbox was last opened yesterday, then we should consider this a new delivery, and notify my phone. If the mailbox was last opened today, then this is probably one of the family going to check it.

My actual automation is a fair bit more complicated than this, but here’s the general gist:

Flow of the mailbox automation, which is described above, and YAML is linked below.

The actual automation — a slightly sanitized version of the YAML can be seen here — is a fair bit more complicated. I’m using MQTT as a bus to drop state-of-the-house information onto, and my automation deals with some of that. (I’ll probably post more about that another time.) The meat of the automation, however, is the above flowchart.

Also not shown in that flow is another neat trick: the YoLink hub has a speaker on it, so you can use Home Assistant to make announcements over the hub. Our hub is sitting in the back of our entertainment center, on the main floor of the house. When the mail is delivered, it will announce that the mail is waiting, and anyone in the family can choose to get it. Mikaela in particular is often excited to go see what’s waiting.

In a stereotypical stroke of absolute genius, Erin pointed out that message should be “You’ve got mail!”. So, on weekday afternoons, when the postal worker comes by the house, the 1990s are alive again.