🤗 Please consider subscribing to my YouTube channel Your subscription goes a long way in backing my work.
The Mailbox Guard is a device that detects when a new letter or package has been delivered to your mailbox using a PIR sensor and door reed switch. It can send a signal to your LoRa gateway, then the gateway sends a message via WiFi to Home Assistant "MQTT" or its "API"
or to WhatsApp
allowing you to receive notifications directly into your phone. Or you can use it offline, the gateway display will show the number of letters received, Battery status, and signal strength.
YouTube video https://youtu.be/gf1WWKyEnbg
My Shop
Gateway on Aliexpress LILYGO® TTGO LoRa32 V2.1_1.6 Version 433/868/915Mhz
Pogo Pin Clamp 6 Pin Minimum 2.54mm pitch
Reed Switch "Normally open When the magnet is far away" "For soldering on PCB" https://s.click.aliexpress.com/e/_DkA1Sjp
Reed Switch with cable "Normally open When the magnet is far away" https://s.click.aliexpress.com/e/_DFNJv1h
Battery Li-Ion 14500 800mA
USB Battery charger "just in case" https://s.click.aliexpress.com/e/_DkDAztD
[!NOTE] If you're ready to contribute to the project, your support would be greatly appreciated.
LoRa_Gateway_MQTT_JSON.ino
Mailbox_Guard_Sensor_MQTT_JSON.ino
[!NOTE] For the Library "megaTinyCore" the official recommendation is. Only versions of the Arduino IDE downloaded from https://arduino.cc should be used, NEVER from a Linux package manager. The golden standard is "V1.8.13".
Additional Boards Manager URLs
Libraries Used
LoRa_Gateway_MQTT_JSON.ino
- 🆕 "Home Assistant MQTT Autodiscovery": Automatically discovers and integrates sensors with Home Assistant via MQTT.
LoRa_Gateway_OLED.ino
- "For Offline Use": Displays new mail notifications, including letter count, signal strength, and battery status. Requires a reset after mail retrieval.
LoRa_Gateway_WhatsApp.ino
- Sends a "You have new mail" message to WhatsApp.
LoRa_Gateway_MQTT.ino
- Sends raw messages and RSSI to an MQTT server.
LoRa_Gateway_HARestAPI.ino
- Sends new mail notifications to Home Assistant via REST API.
[!NOTE] If you are using CapiBridge Gateway, configure it using the Capibridge page.
ESP32 Dev Module
board.h
according to your Lilygo gateway HW Version " 1 = ENABLE / 0 = DISABLE ".#define LORA_V1_0_OLED 0
#define LORA_V1_2_OLED 0
#define LORA_V1_3_OLED 0
#define LORA_V1_6_OLED 0
#define LORA_V2_0_OLED 1
Name | V1.0 | V1.2(T-Fox) | V1.3 | V1.6 | V2.1 |
---|---|---|---|---|---|
OLED RST | 16 | N/A | N/A | N/A | N/A |
OLED SDA | 4 | 21 | 4 | 21 | 21 |
OLED SCL | 15 | 22 | 15 | 22 | 22 |
SDCard CS | N/A | N/A | N/A | 13 | 13 |
SDCard MOSI | N/A | N/A | N/A | 15 | 15 |
SDCard MISO | N/A | N/A | N/A | 2 | 2 |
SDCard SCLK | N/A | N/A | N/A | 14 | 14 |
DS3231 SDA | N/A | 21 | N/A | N/A | N/A |
DS3231 SCL | N/A | 22 | N/A | N/A | N/A |
LORA MOSI | 27 | 27 | 27 | 27 | 27 |
LORA MISO | 19 | 19 | 19 | 19 | 19 |
LORA SCLK | 5 | 5 | 5 | 5 | 5 |
LORA CS | 18 | 18 | 18 | 18 | 18 |
LORA RST | 14 | 23 | 23 | 23 | 23 |
LORA DIO0 | 26 | 26 | 26 | 26 | 26 |
LoRa_Gateway_MQTT_JSON.ino
config.h
/////////////////////////// Gateway Key ///////////////////////////
#define GATEWAY_KEY "xy" // Keep it short
///////////////////////////////////////////////////////////////////////////////
////////////////////////////// WIFI / MQTT ////////////////////////////////////
#define WIFI_SSID "wifi-name"
#define WIFI_PASSWORD "wifi-password"
#define MQTT_USERNAME "mqtt-username"
#define MQTT_PASSWORD "mqtt-password"
#define MQTT_SERVER "IP-Address"
#define MQTT_PORT 1883
////////////////////////// LoRa Config ////////////////////////////////////////
#define SIGNAL_BANDWITH 125E3 // signal bandwidth in Hz, defaults to 125E3
#define SPREADING_FACTOR 8 // ranges from 6-12, default 7 see API docs
#define CODING_RATE 5 // Supported values are between 5 and 8, corresponding to coding rates of 4/5 and 4/8. The coding rate numerator is fixed at 4.
#define SYNC_WORD 0xF3 // byte value to use as the sync word, defaults to 0x12
#define PREAMBLE_LENGTH 6 // Supported values are between 6 and 65535.
#define TX_POWER 20 // TX power in dB, defaults to 17, Supported values are 2 to 20
#define BAND 868E6 // 433E6 / 868E6 / 915E6
///////////////////////////////////////////////////////////////////////////////
The remaining is to upload the code into the LilyGo board after that the "LoRaGateway" RSSI entity will appear in the MQTT devices list.
For programming MailBox Guard, you need any 3.3V "UPDI programmer" You can use my other open-source project "UNIProg Programmer" GitHub
UNIProg | MailBox Guard |
---|---|
GND | GND |
3v3 | 3v3 |
UPD | UPD |
Mailbox_Guard_Sensor_MQTT_JSON.ino
then change sensor name
, gateway key
, and LoRa
settings according to your needs.[!NOTE] The LoRa settings must match the gateway ones.
///////////////////////////////// CHANGE THIS /////////////////////////////////
#define SIGNAL_BANDWITH 125E3
#define SPREADING_FACTOR 8
#define CODING_RATE 5
#define SYNC_WORD 0xF3
#define PREAMBLE_LENGTH 6
#define TX_POWER 20
#define BAND 868E6 // 433E6 / 868E6 / 915E6
#define NODE_NAME "mbox" // The name of your sensor must be unique.
#define GATEWAY_KEY "xy" // must match the Gateway key.
///////////////////////////////////////////////////////////////////////////////
Done! Once the sensor is triggered for the first time, it will appear in the MQTT devices list on Home Assistant.
alias: 📬 LoRa MailBox Sensor Notification
description: ""
trigger:
- platform: state
entity_id:
- sensor.mbox_state
to: mail
for:
hours: 0
minutes: 0
seconds: 1
from: null
condition: []
action:
- service: notify.mobile_app_doogee_v20pro
data:
message: Mailbox is Full !
title: New Mail!
data:
url: /lovelace/home
persistent: true
importance: high
channel: MailBox
tag: mailbox
image: /media/local/notify/mailbox.jpg
actions:
- action: received
title: I took the parcel
mode: single
alias: 📬 LoRa MailBox Dismiss Notification
description: ""
trigger:
- platform: event
event_data:
action: received
event_type: mobile_app_notification_action
condition: []
action:
- service: mqtt.publish
data:
qos: 0
retain: true
topic: homeassistant/sensor/YourSensorName/state
payload: empty
- service: notify.mobile_app_doogee_v20pro
data:
message: clear_notification
data:
tag: mailbox
- service: notify.mobile_app_oneplus8t
data:
message: clear_notification
data:
tag: mailbox
mode: single
alias: MailBox Status Reset and Dismiss Notification
sequence:
- service: mqtt.publish
data:
qos: "0"
retain: true
topic: homeassistant/sensor/YourSensorName/state
payload: empty
- service: notify.mobile_app_doogee_v20pro
data:
data:
tag: mailbox
message: clear_notification
- service: notify.mobile_app_oneplus8t
data:
message: clear_notification
data:
tag: mailbox
mode: single