Navigate back to the homepage

Home Assistant: You have got mail

September 5th, 2020 · 3 min read

Today I want to share a little holiday project I build this week: a mailbox sensor to make a dumb mailbox smart and notifying us if we got new mail. I’m talking about real physical mail here - letters, postcards, newspapers etc. dropped into our mailbox.

How does it work?

The project is build using two Xiaomi ZigBee contact sensors I had leftover. You can get these from Gearbest, AliExpress, or Amazon. Our smart home setup already has a ZigBee network running using a Conbee II stick. Of course, it is integrated with Home Assistant already.

This is how the setup looks like:


The hard(ware) part

Not much is needed for this project:

  • 2 ZigBee contact sensors (e.g. Xiaomi…)
  • ZigBee network (for example via Deconz)
  • Home Assistant
  • Duck tape, hot glue, etc. to fix the sensors

The setup depends a little on the construction of the actual mailbox. Ours has a flap on the front side where the mail is thrown in and a door on the backside to empty it. So I needed two sensors, one to detect if the mail was inserted and a second one to detect when we cleared the mailbox. For a mailbox with just one door or flap, only one sensor would be needed. Our mailbox is made of metal, like most mailboxes here, built into a concrete column. I first thought having a metal frame like this might be problematic with the ZigBee signal but that is not the case.

For a first prototype, I just duck taped the sensor inside the mailbox. On the door sensor the original magnet was too small so I replaced it with a bigger one.

Mailbox flap with magnet

First prototype

This is it for the hardware assembly, actually not really hard.

The fun part

With the hardware part done we can now have a look at the software part. Since our ZigBee network was already running it was easy to connect the two new sensors via the Deconz UI.

Mailbox sensor in deCONZ

With Deconz integrated into Home Assistant the new sensors are immediately available in Home Assistant as well.

Mailbox sensors in Home Assistant

No extra configuration is needed here. Just name the sensors are you prefer. Adding some ZigBee sensors to Home Assistant - pretty easy. Additionally to the two deCONZ sensors I use one boolean input helper plus a corresponding template sensor to keep the state of there is mail or not. deCONZ also creates battery level sensors for each battery-powered device. These are not really used here, but there are other automations that notify us of batteries running low. For convenience one more boolean input helper is used to enable/disable the mailbox notifications. In total there are 5 sensors and 2 inputs used for this project.

Mailbox sensors in Home Assistant

The last step is to build out the automations. I’m still having all automations in YAML, so the mailbox automations are added here as well. For the mailbox sensor three automations are needed:

  1. set the mailbox state if the mail was inserted
  2. Reset the mailbox state once we have cleared the mailbox
  3. Reminder in case we forgot to empty the mailbox in the evening

All of them are relatively simple and short.

The mail detection automation is executed when the flap of the mailbox has been opened the sensor triggered. It sets the mail state to on and sends a notification. Notifications are only sent if the second condition is also met.

2alias: "[Mailbox] Mail detection"
4 - platform: state
5 entity_id: binary_sensor.garden_mailbox_flap
6 from: "off"
7 to: "on"
9 - service: input_boolean.turn_on
10 data:
11 entity_id: input_boolean.garden_mailbox
12 - condition: state
13 entity_id: input_boolean.garden_mailbox_notification
14 state: "on"
15 - service: notify.mobile_app_xyz
16 data:
17 title: JaMa Villa - 📬
18 message: Trari, trara, die Post ✉️ ist da!
19 data:
20 push:
21 thread-id: "ha-mailbox-notification-group"

The mailbox door automation is even simpler. It just resets the mail status to off if the mailbox door got open which is the indication that the mailbox has been emptied.

2alias: "[Mailbox] Reset"
4 - platform: state
5 entity_id: binary_sensor.garden_mailbox_door
6 from: "off"
7 to: "on"
9 - service: input_boolean.turn_off
10 data:
11 entity_id: input_boolean.garden_mailbox

The reminder automation is also very simple. At a certain time it checks the mailbox state and sends us a reminder in case there is still mail in the mailbox. We decided to have two reminders: first at 6 pm, second at 8 pm.

2alias: "[Mailbox] Notification"
4 - platform: time
5 at:
6 - "18:00:00"
7 - "20:00:00"
9 - condition: state
10 entity_id: input_boolean.garden_mailbox_notification
11 state: "on"
12 - condition: state
13 entity_id: input_boolean.garden_mailbox
14 state: "on"
16 - service: notify.mobile_app_xzy
17 data:
18 title: JaMa Villa - 📬
19 message: Der Briefkasten wurde noch nicht geleert, da ist noch ✉️ drin.
20 data:
21 push:
22 thread-id: "ha-mailbox-notification-group"

That is, not much needed for this little fun project.

Soure hero image: Flickr - Helgi Halldórsson

Read More

Building Experiences - AEM & Magento Commerce Integration

On July 28th I was a guest on Mark Szulc's Building Experiences using Adobe Experience Cloud show. We discussed how Adobe Experience Manager works together with Magento, using the latest release of the Commerce Integration Framework.

July 31st, 2020 · 1 min read

Our home sweet smart home

Our Home Assistant setup is pretty simple - everything currently runs on a single board computer - smooth and stable for 12+ months. This is how our setup looks like.

January 14th, 2020 · 1 min read
© 2017–2021 | Made with ❤ by Markus Haack | Built with: Gatsby.js & Novela theme
Link to $ to $ to $ to $