Home Automation – Mailbox Delivery Detection

In the continuing quest to build out my Home Assistant based home automation platform, it’s time to set something up to let us know when mail has been delivered. This will save some effort in walking up a long driveway, esp. during the winter. Plus, it’s cool. This project utilizes a z-wave device, a Home Assistant automation, and notification using PushOver.

I wanted to use a battery powered z-wave device to eliminate the need for any kind of wiring. I avoid wifi based methods simply because they aren’t as reliable and don’t have good energy efficiency. In looking around, the best candidate is the Ecolink Door & Window Sensor (part number DWZWAVE2.5-ECO). The normal use case is with the included magnet, e.g. for door and window open/close detection. However, my mailbox is an all aluminum interior, so that rules out a transmitter inside.

Ecolink_DoorWindow_Sensor_1B

I like this device as it offers a (not well advertised or documented) external trigger via a terminal block inside (see above). So you can ditch the separate magnet, and instead use it with a dry contact (normally open) switch. I chose the Gikfun MC-38 Magnetic Switch.

First test all this on the bench.
Ecolink_DoorWindow_Sensor_4B
For the planned installation, I first needed to extend the switch leads to ~36″ using some 22 gauge wire.

Ecolink_DoorWindow_Sensor_3B
This shows how the leads are attached to the terminal block. Note that for final mounting, you want to run the leads through the small opening in the bottom so that the cover can be put back on.

Set up the Home Assistant automation too, and make sure that works ok.

  # Mailbox - Notification on door opening
  - alias: 'Mailbox Open Notification'
    trigger:
      - platform: state
        entity_id: binary_sensor.ecolink_door_window_sensor_sensor
        # When magnet moves away on door open, state goes from off to on for this dry contact reed switch.
        from: 'off'
        to: 'on'
        for:
          # So that one can peek in the mailbox to check on mail. But mailman is fast!
          milliseconds: 500
    action:
      - service: script.notify_mqtt
        data:
          source: "mailbox"
          target: "sensor/mailbox"
          message: "Mailbox Door Open Detected"

I started using a script call to centralize notification handling. I want everything published to the mqtt server. The script allows me to test a variety of notification services. The current service being evaluated is Pushover. Here is the script.

script:
  # Sends the message to the mqtt server
  # Inputs:
  #  source: friendly name of the source
  #  target: the mqtt channel. e.g. sensor/mailbox
  #  message: message body
  notify_mqtt:
    sequence:
      - alias: Publish to MQTT
        service: mqtt.publish
        data_template:
          payload: '{{ now().strftime("%H:%M %Y-%m-%d") }}:{{ source }}-{{ message }}'
          topic: ha1/"{{ target }}"
          retain: true
      - alias: Pushover Notification
        service: notify.pushover
        data_template:
          title: "HA {{ source }}"
          message: "{{ message }}"
          data:
            sound: >
              {% if 'Front Porch' in source  %}
                pushover
              {% else %}
                incoming
              {% endif %}

You’ll note that the notification sound is based on the name of the source. Done here to abstract the details of the pushover sound names away from the automation script. Ultimately there will be a variety of sounds set here as the sensor build out continues.

Starting with the magnetic sensor pieces close together, move them apart and confirm it triggers. You’ll see the led on the z-wave device flash briefly.

Now on to installation. My mailbox happens to be mounted inside a stone covered pillar.
Mailbox_2B

It houses an interior light inside with some room for the z-wave device to sit on top of the mailbox housing below. This provides a good place to be protected from the weather, and have radio line of sight to another z-wave+ device nearby in the garage. This z-wave device is not weatherproof, so you’ll need to make sure it is in an enclosure of some kind. The z-wave package comes with a mounting clip, so I screwed that to a small section of painted plywood for stability and attached the z-wave device to this mount.

I drilled a hole in the top rear of the mailbox for the leads to run through and used dabs of silicone sealant to affix the leads to the upper corner so they don’t get snagged on mail going in and out.
Mailbox_1B
The magnetic sensor pieces attach to the mailbox frame and door respectively with the included double sided tape. Care must be used to ensure vertical alignment and that the door mounted magnet piece is within the maximum allowed separation when the door is closed.

Results are good, and I’m really liking Pushover so far.