Automating a letter box sensor

I have a put a Hue Motion sensor in the back of my mailbox, looking towards the flap. I have integrated it into HA & I would like to use to detect whether mail has arrived. What I would like is …

  • If / when first movement each day is detected, turn a button on the dashboard “yellow” - ie assume letters have been delivered.
  • If a second movement in a day is detected, turn the button on the dashboard “blue” again - ie assume letters have been removed.
  • If no movement is detected in a day, do nothing.

… but I am at a loss to know where to start. Can this be done within HA, or do I need to use Node-RED or similar to do the legwork?

TIA

You could do it with a triggered binary template sensor that toggles the state whenever movement is detected, but this could get out of sync if movement is detected more than twice a day:

template:
  - trigger:
      - platform: state
        entity_id: binary_sensor.your_movement_sensor_here
        to: 'on'
    binary_sensor:
      - name: Mailbox Full
        state: "{{ not is_state('binary_sensor.mailbox_full', 'on') }}"

To prevent this you could use an automation instead that toggles an input boolean called “Mailbox Full” as you could add conditions to the automation. Like only toggle it on around the time your mail is usually delivered.

What if during the first delivery, the flap is opened/closed more than once? It will be reported not as a “first movement” but second or third movement. Some sort of “cooldown” period is needed.

What if a package or envelope is inserted in a manner that obstructs the motion sensor’s view of the flap? It will be unable to detect the next movement until the obstruction is cleared. Not sure of a way to avoid this unless the motion sensor can be located in a way that it cannot be obstructed.

Yeah an automation would be better.

This condition for an automation should sort that:

And only turn it off around the time you check your mail.

Though that depends on regular delivery times and regular checking times.

I use a fibaro battery operated water sensor tied to a reed switch. When the mailbox is opened I have an automation notify our phones. I have never been able to figure out a bullet proof scenario where you always know what is going on. I have thought of a second reed switch on the bottom that would be activated from the weight of the mail. This creates another problem for when you send mail from your box not to mention the variable weight of mail.

Another idea I had was to create a mail retrieved input sensor in HA to show when mail was retrieved.

Watching with great interest hoping someone has a better idea.

Thanks All - very helpful & much appreciated.

  • The mail is “usually” delivered anytime between 08:30 - 14:00, but that is such a large window that I would look to ignore a condition based on it.
  • The mail box is wall mounted with a slot above a key operated door below; I have tested the Hue sensor and it accurately detects motion post in & post out (turning the button shown above from blue to yellow for ~10 seconds, then back to blue), and won’t be dislodged by letters hitting it etc. So I am relaxed that the hardware side of things is good / reliable.

I wonder whether I should create a Conditional Card within Lovelace instead of “just” a coloured blue / yellow button; I already have a couple of those (warning me when the oil tank is low for example). But not sure what form of syntax can be used to cancel the alert on second movement in any one day…

TIA

How is the motion sensor mounted within the mailbox so that a deposited envelope doesn’t obstruct its view of a second delivery on the same day? I assume it must be on either side of the mailbox’s interior because it would be easily obstructed if located on the bottom.

The mailbox is metal, and the Hue sensor magnetises well to the top of the rear internal wall; I’ve aimed it down and towards the flap & door & picks up both being opened immediately (& repeatedly).

1 Like

How about this as a start?

- id: '162522222229'
  alias: Mailbox Full/Emptied
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: 6f94fxxx7cdc5
    entity_id: binary_sensor.mailbox_pir_motion
    domain: binary_sensor
  condition: []
  action:
  - service: notify.mobile_app_dfg
    data:
      message: Mailbox FULL
  - wait_template: ''
    timeout: 00:00:20
    continue_on_timeout: true
  - wait_for_trigger:
    - type: motion
      platform: device
      device_id: 6f94fxxx7cdc5
      entity_id: binary_sensor.mailbox_pir_motion
      domain: binary_sensor
    timeout: 00:00:01
  - service: notify.mobile_app_dfg
    data:
      message: Mailbox Emptied
  mode: single

Not sure how to reset things at midnight to revert to “waiting for mail”, nor how I might get this in to Lovelace as opposed to just a notification on my phone.

EDITED TO CHANGE Code format as requested :blush:

Please take the time to learn how to properly format code on the forums. Look at the FAQ number 11 for a guide.

1 Like

This automation reports the box is full the first time motion is detected, waits 20 seconds (the cooldown period) then waits indefinitely until the next detection which it assumes to be an emptying of the box because that’s what it reports.

It doesn’t appear to do what you requested in your first post. Have the requirements changed? (i.e. where are the color-change indicators).

I believe you will need it to set an entity’s state (perhaps an input_boolean) so that there’s something to reference when determining which color to use.

Thanks @123 - no, my requirements haven’t changed, but I was just trying to make a start & don’t know how to do what I ideally want.

EDITED #2 TO UPDATE ON FURTHER PROGRESS

Actually, it now does seem to work; one Lovelace Grid Card button (aimed at binary_sensor.mailbox_pir_motion) changes from blue to yellow on first activation, stays yellow for maybe 10 seconds, then reverts back to blue. I will probably remove this button when I have improved the next one.

Meanwhile, in parallel, a Lovelace entity card (aimed at input_boolean.postbox_state) changes from Off to On and remains like that until I cause a second activation of the PIR after more than 20 seconds (& not otherwise), when it goes from On to Off.

This is so close to what I want, but with two exceptions:

  1. How can I change the displayed state in the latter to be either Yes/No or FullEmpty, instead of Off/On?
  2. How can I get the mdi:mailbox icon to change to yellow in this card? This one stays on blue whether Off or On is shown.
  3. How might I code a reset at midnight, so even if no second activation happens on a particular day, at midnight the system is reset to Off (/Empty) as this would fit in to our needs better than a pure toggle.

TIA

.
.
.

EDITED #1 TO UPDATE PROGRESS

Following on from your input_boolean prompt, I have created a Helper & an entity input_boolean.postbox_state (see below). I have created an Entity Card in Lovelace, and if I trigger(?) the Helper the Entity Card changes from Off to On & back again (but the colour of the icon doesn’t change, which I would like it to).

- id: '16256ccccc6'
  alias: Postbox
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.mailbox_pir_motion
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: input_boolean.toggle
    target:
      entity_id: input_boolean.postbox_state
  - wait_template: ''
    timeout: 00:00:20
  mode: single

I have created an Automation called Postbox, with the intention that if the Hue PIR senses motion it should trigger the 'input_boolean.postbox_state` and then wait for 20 seconds.

But it doesn’t work and I don’t see why not …


.

I am obviously missing something, but not sure what! :grimacing:

@hottl I just read your post the other day and then saw this today. I know it’s about a year later but maybe it will still help you or even someone else.

Ring Mailbox Sensor - $29.99 USD

1 Like