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.
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.
With Deconz integrated into Home Assistant the new sensors are immediately available in Home Assistant as well.
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.
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:
- set the mailbox state if the mail was inserted
- Reset the mailbox state once we have cleared the mailbox
- 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.
1---2alias: "[Mailbox] Mail detection"3trigger:4 - platform: state5 entity_id: binary_sensor.garden_mailbox_flap6 from: "off"7 to: "on"8action:9 - service: input_boolean.turn_on10 data:11 entity_id: input_boolean.garden_mailbox12 - condition: state13 entity_id: input_boolean.garden_mailbox_notification14 state: "on"15 - service: notify.mobile_app_xyz16 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.
1---2alias: "[Mailbox] Reset"3trigger:4 - platform: state5 entity_id: binary_sensor.garden_mailbox_door6 from: "off"7 to: "on"8action:9 - service: input_boolean.turn_off10 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.
1---2alias: "[Mailbox] Notification"3trigger:4 - platform: time5 at:6 - "18:00:00"7 - "20:00:00"8condition:9 - condition: state10 entity_id: input_boolean.garden_mailbox_notification11 state: "on"12 - condition: state13 entity_id: input_boolean.garden_mailbox14 state: "on"15action:16 - service: notify.mobile_app_xzy17 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