My Smart Mailbox (Virtual sensor presence)

I am testing this for a few months and like a charm.

MailBox Notification

I want to create a virtual presence sensor that indicates the presence of mail in my mailbox. My mailbox is on my house door, just attached to it. And the flap or door to leave the mail is the same to take it out. I thought to do something simple:

If the mailbox opens and the door is not being open after or before during X amount of second, this means someone drop content into the mailbox (well could be a thief, but well, let's keep the problem statement simple :slight_smile:

This X amount of second of seconds, let's call them TheOffsetTime


  • 1 Hubitat
  • 2 contact sensors. One attaches to the door, and another connects to the mailbox.
  • The Rule Machine app.

The first step, create the virtual presence sensor. Pick your favorite name. This sensor presence is great for your dashboards.

After that, let's move to the Rule Machine.

So I create a global variable on the RULE MACHINE last_time_front_door_action (number) it will store the last time the door was open in seconds

I create rule ( SetLastTimeFrontDoorOpen) the only thin that it does is to set the variable last_time_front_door_action to now() in seconds.

I create a second rule (Mailbox) with 2 local_variable

  1. time_mailbox_open_with_offset (number). It will store the time where the mailbox was open minus the TheOffsetTime. just a trick to make the condition simple.

  2. is_time_in_range (boolean). This is to simplify the condition, probably not needed, but I can access the rule in the future and see what happened the last time.

The code of the rule:
I get the time in seconds and populate the variable time_mailbox_open_with_offset with now() - 60 (a minute)
I wait for a minute so someone can open the door during that time
I populate is_time_in_range variable to be able to make the following condition:

if time_mailbox_open_with_offset is higher than time_mailbox_open_with_offset
then is_time_in_range is true
Else "I have a mail"

Depending on the value of is_time_in_range I send the notification and set the virtual presence of the sensor

But better to check the next image.

As a cherry on the top. I create a virtual switch and share it with the google home that I use in a routine on my google home, "Hey google, Do I have any letter?" and when this switch is activated with this routine. I send a message to my google home to reply with the value of the present sensor.

And for fun: I set the sensor outside the mailbox. I am using a zigbee sonoof that is pretty bulky. So I took it from the box and created a smaller box (with a poker card :slight_smile: ) And the magnet also outside the box.

I checked different articles before starting to code anything.

I may learn how to create apps inside hubitat and move this into an app.


Nice work. Not something I need personally, but still a good example of a range of different techniques in HE and on the Google platform. Also good to see people sharing details of their setup for others to use or take inspiration from.

1 Like

Have a look in the Aus thread - there were a number of posts dealing with non US letterboxes (TBH I'm surprised there isn't more mail theft in the US given letterboxes there aren't secured in any way :grinning:).

I use a sonoff motion sensor for mail which when triggered sends a TTS to my symfonisk/sonos and lights up a dashboard tile. A contact sensor on the letterbox door resets the tile after I've opened it to fetch the mail. It's been working great so far.

1 Like

I get so little snail mail nowadays, that is why I don't really have a need for this. There are a few letters I still get from some institutions, but I get most banking and other statements via email now.

That said, maybe that puts me in the category of people who do need this, who can make use of a sensor -driven notification of mail arrival given the infrequent nature of it....

1 Like

Just adding to the discussion - I've got a doorbell cam directly over my mailbox and I get a triggered snapshot that goes to SMS when porch activity happens. But I couldn't automate mail monitoring since I get Amazon packages and other deliveries as well.
My box has an outside flap and an inside one. Putting 2 sensors (one on each flap) on it would not be very difficult! It'd be nice to combine the doorbell snap shots (I use BlueIris server with triggers) and the outer contact sensor to determine if it's pickup or pickup/delivery, and the internal contact sensor to flag emptying the box. I use the USPS heavily but I do get the statement that snail mail is an aging animal. (Also, I don't have facial recognition on the camera - but I bet it wouldn't be hard to create a shirt recognition!)

Thanks, @sburke781. I am trying to document what I am doing. So I can replicate it in the future if something goes wrong :slight_smile:
So I thought it would be good to share some of this info.

@jshimota It will be cool to add recognition, but in my case, I just wanted to know if I have any letters. My camera will send a notification also when someone is at the door, So more than for the notification is to have this info in my dashboard. Weirdly, I get a package, and I am not aware of it.
This is more for fun than a necessity, to be honest.

1 Like

@luarmr ".... more fun than a necessity..." that pretty much describes 90% of my smart home! Before smartthings I used a wall switch. What a neanderthal!

Seriously - I'm wondering about some form of beam sensor. The perfect mailbox app would need to be accurate and not just mostly accurate. We hang mail out the box lid for pickup, so something would need to sense the lid isn't perfectly closed. hmmm. but a beam sensor, like a mirror glued to the bottom of the box and a light beam shot down that gets interrupted...
I don't know what 'rural' mailboxes (a flag on the side to inform the postal carrier mail needs pickup?) do exactly.
Maybe another way is to just use a smart button. When the box is checked by homeowner (me) i push the button which informs HE that the mailbox is empty. then every weekday + saturday the status of unchecked fires off at 0600 or something? hmmm

Why don't you just put a motion sensor stuck to the back of the mailbox then do a Pushover? I guess I don't seem to understand the advantage of going through all of that and testing.

@St_Isidore For me, the contact sensor to check if the mailbox is open. And the door minute safeguard allows me to have a virtual sensor with the state of the mailbox.

With the motion sensor you will trigger open and close, so not sure you have any advantage over a contact sensor.

I like the idea of replicating the state of a "no smart thing" in a virtual device. I am doing this with several "things". For me is more about a state of things.

This is cool to have a dashboard with those states and more accurate and meaningful notifications.

So for me get a notification when the mailbox is open doesn't really give me any benefit. In case I need a notification I want to get a notification only when I get mail.

@jshimota The button idea... I am try to not to do anything that I wont do normally. When I pick the mailbox right now, I open the box take the email and done, so we add an extra step that I probably will forget.

But the bean sensor looks like the best way. Also probably little more expensive, no idea.

Download the Hubitat app