How to Limit Automation Triggers for Mailbox Notifications

Hi everyone, I’m excited to share my experience with setting up an automated mailbox notification system using ESPHome. This setup has been a game-changer for keeping track of my mail without having to physically check the mailbox every time. However, I recently encountered an issue that I thought I’d walk through in case others are facing similar challenges.

The Setup

I have an ESPHome device connected to a contact sensor on my mailbox. The sensor is set to ON when the mailbox is closed and switches to OFF when the mailbox opens. This setup worked flawlessly for quite some time, sending me a notification each time the mailbox opened. However, things took a turn recently with the onset of colder weather.

The Problem

During the colder months, my ESPHome device started showing as unavailable intermittently. This led to a flood of false notifications, which was overwhelming. Even after adjusting my automation to account for the device’s availability, I noticed that after 11 PM, I was receiving genuine notifications but with excessive frequency.

The Solution

After some research and experimentation, I found a way to limit the notifications to just one every 30 minutes, regardless of how many times the sensor triggers. This ensures that I don’t miss any deliveries but also prevents my inbox from being spammed.

Here’s how I did it:

  1. Modify the Automation Trigger: I adjusted the trigger to only send a notification when the sensor changes from ON to OFF.
  2. Add a Delay: I introduced a delay of 30 minutes after each notification. This means that if the mailbox opens again within this window, it won’t send another notification until the 30 minutes have passed.
  3. Test and Refine: I tested this setup over a few days to ensure it works as intended and made minor tweaks based on the results.

Automation Code

Here’s the updated automation code I’m using:
yaml

  • alias: “Mailbox Notification”
    trigger:
    • platform: state
      entity_id: binary_sensor.mailbox
      from: “on”
      to: “off”
      action:
    • service: notify.telegram
      data:
      title: “Mailbox Notification”
      message: “Mail has been delivered. Please check the mailbox.”
    • service: timer.start
      data:
      duration: “00:30:00”
      action:
      service: input_boolean.turn_off
      data:
      entity_id: input_boolean.mailbox_notification_enabled

Conclusion

This solution has significantly reduced the number of unnecessary notifications while still keeping me informed about new mail deliveries. I hope this helps anyone else dealing with similar issues with their mailbox sensors or other automated systems. If you have any questions or suggestions, feel free to reach out!

Happy automating! :smile: