A Mailbox Alert

I wanted a Home Assistant alert when someone puts something in my letterbox which is down the driveway a bit. That would give me a visual indication on the tablet on the kitchen wall, and an alert on my phone.


Mail flap down
Mail flap up

One way to trigger the electronics doing the signalling is using a magnet on a flap which gets pushed over when a letter is inserted in the letter slot, closing a reed relay. Above left is a view inside the letterbox with the flap down, showing the hinges 3D printed in PLA for the job. They are stuck on using double-sided tape. (The letter slot is obscured by the lid being up.)
A reed switch has the advantages over a press-button switch of not needing any force, and inherently waterproof. The disadvantage is a magnet in the letterbox. Fortunately, magnetic-stripe cards have largely been replaced by smart cards. I used the magnet from an old 2.5″ disk drive.
Above right is the flap up waiting for a letter, with the magnet stuck to the back then covered over with some tape. The cable tie is holding on the electronics box underneath, with a reed switch positioned below where the magnet will fall. -The letterbox is made of non-magnetic alloy.

I 3D printed a box customised to the size I needed for the project.
That was an interesting exercise. I’d never used a SCAD file before. Loaded OpenSCAD onto my Ubuntu OS, and was able to customise all sorts of box parameters, output an STL then sliced it using Cura slicer.

For my sender, I am using an ESP01. Cheap from Aliexpress, easy to program with an adapter, can be unplugged to reprogram if necessary. (Doesn’t have enough memory to allow OTA programming.) If anyone wants to use one of these, I suggest the ESP01S variant. Some useful resistors on board, and no power LED that needs removing for battery use. (Any Arduino style module with onboard WiFi would do the job.)
I’m using ESPHome on the module. Tried Tasmota, but it won’t send the internal voltage without recompiling the source, which defeats the purpose of using maintained packages IMHO.

Electronics and box
Circuit box under letterbox

An 18650 Li-Ion cell powers the circuit, through a silicon diode to drop voltage a bit. I have plenty from old laptop and jump-starter batteries. Usually one or two cells die in a pack but others are still OK. Heaps of juice and rechargeable when necessary. An alternative would be a couple of AA cells.
The “on/off switch” is the connecting plug.
On the right side is the ESP01 plugged into a socket on a solder board, with wiring and components roughly soldered on. Left of that is the reed soldered onto a couple of wires.
My intention was to keep the reed inside the box. But unless I used a really strong magnet, it didn’t get switched. So I hacked the box edge a bit and hung the reed outside the box, level with its top, ie removing the thickness of the lid. As is evident in the right side photo above, I stuck black tape over the box top and reed for a bit of protection. The top of the box is located with double-sided tape onto the mailbox bottom. The bottom slots onto it (no screws) and is held in place by a cable tie. Not very secure, but strong enough.

Thought I was stymied by the ESP01 WiFi unable to get to my router. Fixed the problem by putting a cheap WiFi repeater in my bedroom at the front of the house. Now I can add gadgetry to the front garden knowing it can communicate. (The ESP8266 12F based moisture sender in the front garden is doing OK going direct. Either because it is a bit closer, or its WiFi is better. -That uses raw C++ code.)


Sender circuit

The circuit is drawn with KiCad.
The ESP01 is normally asleep, drawing maybe 20uA. (I removed the power-on LED from the ESP01.)
The flap magnet closes the reed switch, resetting the ESP01 with a momentary pulse through the 1uF capacitor. (I used an electrolytic because that is what I had. Same for the power bypass capacitor.)
The reset capacitor is gradually discharged by the 1M resistor, once the flap is reset, removing the magnet. The software puts the micro to sleep after 20secs, whether the flap is up or down.
The components I used are what I had to hand, values aren’t too critical.


Here is the YAML code used to program ESPHome onto the ESP01.
Just needs the WiFi router SSID and password filled in.

  name: mailbox

  board: esp01
# Enable logging

# Enable Home Assistant API
  password: ""

  password: ""

  ssid: "..."
  password: "..."

  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Mailbox Fallback Hotspot"
    password: ""


  run_duration: 20s
  - platform: adc
    pin: VCC
    name: "Mailbox VCC"   
    update_interval: 5s
      - homeassistant.service:
          service: input_boolean.turn_on
            entity_id: input_boolean.mail_flag

  - platform: wifi_signal
    name: "Mailbox WiFi Signal Strength"
    update_interval: 5s

Home Assistant will auto-discover the device. I temporarily commented out the YAML deep_sleep section (above) so the sender could keep sending, to make this easier.
When the internal voltage is sent, a homeassistant.service call is made to turn on the ‘input_boolean.mail_flag‘ in HA.

Home Assistant

In Settings / Devices & Services / Helpers, I added a toggle called Mail.
(It is that toggle that gets switched on by the mailbox sender with a homeassistant.service call.)
On a dashboard, I added a Button with a mailbox icon. Its Tap action is to turn off the target input_boolean.mail_flag entity. When the mail sender triggers, this button turns orange. Pressing it resets the flag and returns it to blue.
I also added an Entities card, showing the sender VCC and WiFi signal strength. Keeping an eye on the VCC will let me know when its time to recharge the battery, should last many months.

In automations.yaml I have the following, to send an alert to my phone.
Only one notification will be sent, until the mail flag is cleared by pressing the ‘Mailbox‘ button.

- id: '1688044135038'
  alias: You have post
  description: Sends message to Ken's phone when the mail flag goes on.
  - platform: state
    - input_boolean.mail_flag
    from: 'off'
    to: 'on'
  condition: []
  - device_id: ......
    domain: mobile_app
    type: notify
    message: Check the letterbox!
    title: You have post
  mode: single


Still to be done: Triggering when the mailbox lid is opened to put a parcel in.
I’m thinking either a mechanical linkage that drops the front flap, or a magnet on a string that gets pulled alongside the reed switch when the lid goes up.

Using ESPHome (or Tasmota) isn’t a good choice for something sending every few minutes or so. Too slow, with no real control over the sequence. (ESPHome does multiple sends to HA before the connection to is is even established.) The battery will last a lot longer using code which just sends MQTT packets using an Arduino MQTT library.

This page is a work in progress. It will get edits to improve it, and changes as I change the project.
The construction is pretty rough, but cost very little. Time will tell if it is good enough.

I’ve benefited from the work of others published on the net, so I’m hoping publishing what works for me can help or encourage others, as a bit of payback. I will respond to questions, but spam won’t make it.

Leave a Reply

Your email address will not be published. Required fields are marked *