Sensor to Check if mail is in the mailbox

I once put a zigbee motion sensor in my mailbox, and it worked, but the battery ran down really fast.

Now I just use the USPS informed delivery service. Every morning I get an email with images of that day’s mail, and then I get another email when the mail is delivered.

1 Like

Hey @lighthouse, regarding the false positives, I recommend using a reed switch instead of a PIR motion sensor. PIRs are very sensitive to small vibrations, changes in brightness and even small insects, which often leads to unwanted triggers over time. It’s also important to fine tune the gap between the magnet and the reed switch, and to adjust the debounce period on the device. This helps avoid multiple signals when the mail carrier opens the flap.

In my project, I’m using the LoRaWAN protocol, which sits on top of the LoRa radio layer and provides secure communication and standardized message handling. The messages are forwarded by the gateway to a LoRaWAN Network Server (LNS), which then routes and decrypts the payload before publishing it to an MQTT broker, similar to what I implemented here: https://github.com/vhuynen/Kerlink-LoRaWAN-To-AWS-IoT-Core

I moved away from the Helium network and now use a personal Kerlink LoRaWAN gateway. For the moment, I’m relying on AWS IoT Core as my NLS, but I plan to switch to a local LNS using the open-source ChirpStack stack: https://www.chirpstack.io/

The final architecture will look like this:
Device → LoRaWAN Gateway → ChirpStack → MQTT → Node-Red → MQTT → Home Assistant

thanks a lot @vhuynen for your explanation. I got the Adeunis Dry Contact and am using the following config together with a Lorawan-Gateway and Chirpstack.

TOR1: Omron D2HW-C242M Micro-Switch (https://components.omron.com/us-en/sites/components.omron.com.us/files/datasheet_pdf/B105-E1.pdf) normally closed

TOR2: magnetic NC reed contact for the parcel door.

Codec:

function decodeUplink(input) {
    const bytes = input.bytes;

    // Sicherheitscheck
    if (!bytes || bytes.length < 11) {
        return {
            errors: ["Payload too short"]
        };
    }

    // Status-Byte laut Adeunis Spec
    const status = bytes[10];

    // Channel 1 (A)
    const ch1_current  = Boolean(status & 0x01);
    const ch1_previous = Boolean(status & 0x02);
    const ch1_changed  = ch1_current !== ch1_previous;

    // Channel 2 (B)
    const ch2_current  = Boolean(status & 0x04);
    const ch2_previous = Boolean(status & 0x08);
    const ch2_changed  = ch2_current !== ch2_previous;

    // Keep Alive = kein Channel hat sich geändert
    const keepAlive = !(ch1_changed || ch2_changed);

    return {
        data: {
            keepAlive: keepAlive,

            channel1: {
                state: ch1_current ? "closed" : "open",
                changed: ch1_changed
            },

            channel2: {
                state: ch2_current ? "closed" : "open",
                changed: ch2_changed
            }
        }
    };
}

The TOR2 is working fine, I have configured it to edge high & low. When the door opens I get open via MQTT, and closed when its closed.
closed, keepAlive: false because the input event has triggered


open, keepAlive: false because the input event has triggered

issue

TOR1 is configured with only high edge. The micro-switch is normally closed, meaning the lever pushes on the micro-switch. I would like that I get “open” when the lever does not push anymore on the micro-switch because a letter has been put into the box and the flap opens.

However I get either state open and keepAlive true (where I would expect keepAlive is false and state open). The next time I get keepAlive false and state “closed”.

question: What do I need to modify in order to get keepAlive false and state to open when the micro-switch is not being pushed down from the lever?

Whenever I release the the micro-switch I get Lora-frames

Appreciate any help, I spent hours with Chat GPT, Github etc. and could not find the reason for this behaviour.

Just some info that might be interesting.

This thread: Are mailbox notification possible with this mailbox?

And another source for a DIY route: Build a Long‑Range LoRa Gateway for Home Assistant with M5Stack | m5stack-store

@jonathanathe idk why its replying to you sorry lol
@zBernie this is for you:

if i were to take a go at it id do contact sensor on mail box plus sign upf or USPS informed delivery which sends email if mail is even expected that day, imap cans scrape email for the usps informed delivery. So if mailbox is opened within a window of time when mail is expected it marks a sensor mail has been delivered. Also note someone linked the Mail&Packages Integration you need that it skips the hasle of creating imap scrape logic it also does other cool things like package tracking.

Truth is theres no one clear shot way but im willing to help you, your gonna have to leverage data from multiple places to get exactly what you want but so far it seems like your halfway there

I have to walk 247 feet to retrieve my email. I want to know if it has actually arrived yet. I finally got this working in the “bank vault” of a mailbox using a YoLink LoRa Smart Outdoor Contact Sensor & Hub Starter Kit.

if google still had massive free tier api the solution would be so simple, exacly this camera in mailbox and let ai determine if mail is in the box, the triger would be the cameras motion detection, and the action would be . I abused this setup when google let you call 100’s of ai api calls a day.

description: ""
mode: single
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.hallway_sensor_presence
    from: null
    to:
      - "on"
conditions: []
actions:
  - action: ai_task.generate_data
    metadata: {}
    data:
      task_name: Check if mail in mailbox
      instructions: >-
        This is a mailbox camera, if you see mail inside return yes if not
        reutrn no,  do not append anything to beggining or end of your statement
      entity_id: ai_task.google_ai_task_2
      attachments:
        media_content_id: >-
          media-source://camera/camera.hallway_floor_2_camera_high_resolution_channel
        media_content_type: application/vnd.apple.mpegurl
        metadata:
          title: Hallway Floor 2 Camera High resolution channel
          thumbnail: >-
            /api/camera_proxy/camera.hallway_floor_2_camera_high_resolution_channel
          media_class: video
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: app
              media_content_id: media-source://camera
    response_variable: mail
  - if:
      - condition: template
        value_template: (enter variable if repsonse = yes)
    then:
      - action: notify.notify
        metadata: {}
        data:
          message: Mail has been delivered
          title: Mail

thanks for the inputs. If anyone is planning to use the Adeunis Dry contact sensor as I do, you can download the codec under https://www.download.codec-adeunis.com/adeunis-codecs-libs-1.7.1.tgz and choose the Dry contact javascript file, paste it 1:1 into the codec and it just works fine.

Thanks a lot to @vhuynen who pointed me into the right direction :slight_smile: