Simple Mailbox Mail Detection and Notifier

Happy Thanksgiving!

I thought I’d share my simple project, and seek any potential enhancements.

I’m using a SkyConnect USB (Zigbee) and one Aqara switch on the mailbox door to detect when mail is delivered. I have two automations to control it: 1) Detects when the door is opened with conditions (it’s after 10am and before 6pm; the input boolean switch “Mailbox Acknowledged” is off; and the input boolean switch “Confirm Mail Arrived” is off); and Takes action (sets the input boolean switch “Mail Arrived” to on; sets the date/time on another helper; sends notifications with two being confirmable to my wife and I; and turns on the “Mailbox Acknowledged” input boolean). 2) The second automation resets the input boolean switches to “off” at midnight. I designed it this way because our mail usually comes around noon, and I only wanted to get notifications for the first opening. I’ve been thinking about adding another sensor to the mailbox flag, which the mailman/lady usually flips up if mail has been delivered, but sometimes I also flip it up if I have mail to deliver which they will pick up.

Here is the YAML for both automations:

  1. Mail Arrived
alias: "Mailbox: Mail Arrived"
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.lumi_lumi_sensor_magnet_aq2_opening
    to: "on"
condition:
  - condition: state
    entity_id: input_boolean.mailbox_acknowledged
    state: "off"
  - condition: state
    entity_id: input_boolean.mailbox_opened
    state: "off"
  - condition: time
    after: "10:00:00"
    before: "18:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
action:
  - variables:
      acknowledge: "{{ 'ACKNOWLEDGE_' ~ context.id | default('None') }}"
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.mailbox_opened
  - service: input_datetime.set_datetime
    data:
      datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
    target:
      entity_id: input_datetime.mailbox_first_open_time
  - service: notify.alexa_media_kitchen
    data:
      message: The mail has arrived
  - service: notify.mobile_app_iphone_1
    data:
      message: Acknowledge?
      data:
        entity_id: camera.front
        actions:
          - action: "{{ acknowledge }}"
            title: "Yes"
      title: The Mail Arrived
  - service: notify.mobile_app_iphone_2
    data:
      message: Acknowledge?
      title: The Mail Arrived
      data:
        entity_id: camera.front
        actions:
          - action: "{{ acknowledge }}"
            title: "Yes"
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ acknowledge }}"
        context: {}
    timeout:
      hours: 7
      minutes: 0
      seconds: 0
      milliseconds: 0
    continue_on_timeout: false
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.mailbox_acknowledged
mode: single
  1. Reset Switches at Midnight
alias: "Mailbox: Reset Switches at Midnight"
description: ""
trigger:
  - platform: time
    at: "00:00:00"
condition: []
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id:
        - input_boolean.mailbox_acknowledged
        - input_boolean.mailbox_opened
mode: single
  1. Lovelace Panel
type: entities
entities:
  - entity: input_boolean.mailbox_opened
    secondary_info: last-changed
  - entity: input_boolean.mailbox_acknowledged
    secondary_info: last-changed
  - entity: input_datetime.mailbox_first_open_time
  - entity: binary_sensor.lumi_lumi_sensor_magnet_aq2_opening
  - entity: sensor.lumi_lumi_sensor_magnet_aq2_battery
title: Mailbox
show_header_toggle: false
state_color: true
  1. Helpers

“Mail Arrived” - input_boolean.mailbox_opened
“Mailbox Acknowledged” - input_boolean.mailbox_acknowledged
“Mailbox Open Time” - input_datetime.mailbox_first_open_time

I appreciate any thoughts on making this better!

5 Likes