← 206YALL.COM

HA.206YALL.COM

Home Assistant Projects


Mailbox Item Tracker

Part of pwnkw_ha — Kenneth’s collection of Home Assistant projects.

Know how many pieces of mail are waiting in your remote / CMRA mailbox before you drive over. This turns your mailbox provider’s “N new mail item(s)” notification emails into a live count on your dashboard — and clears it automatically when you show up to collect.

Control What it does
Items waiting Live count of uncollected items, updated the moment a notice email arrives
Arrive at the mailbox Presence zone auto-resets the count to 0 (you collected everything)
Reset button Manual “set to 0” backstop

Why it’s built this way

The naive version — a scheduled script that tallies the emails — lags. Mail arrives at 11am, you grab it at 2pm, and the next morning’s run happily re-adds it, so the dashboard sends you on a wasted trip.

This design has no script and no polling in the counting path. Home Assistant’s IMAP integration fires an event the instant a notice email lands; an automation reads the item count out of the email and adds it. The count is a real-time function of email arrivals, so there’s nothing running “later” to get it wrong. Presence at the mailbox zeroes it. That’s the whole system.

Provider "new item" email ─► your inbox ─► HA IMAP ─(imap_content event)─► +N ─┐
                                                    parse count, dedup by UID   ▼
                                                                    ┌─────────────────────────┐
   You arrive at the mailbox ─► zone enter (+1-min dwell) ─► reset ─► │ input_number.           │
                                                                    │   mailbox_items_waiting │  ─► dashboard
                                                                    └─────────────────────────┘

How it works

No cloud webhook, no external server, no LLM — just an IMAP event and a zone.

Requirements

Install

  1. IMAP integration (HA UI — not YAML): Settings ▸ Devices & Services ▸ Add Integration ▸ IMAP.
    • Server / port: your IMAP host, e.g. imap.fastmail.com : 993. Use an app password, not your login password.
    • Folder: INBOX.
    • Search: SUBJECT "New Mail" FROM "anytimemailbox" — matches only the notices. Adjust to your provider’s sender/subject.
    • Include “Body text” so the event carries the body to parse.
    • Tip: don’t filter on UnSeen if something marks these read quickly (you’d match nothing) — filter by sender/subject as above; the UID dedup handles the rest.
  2. Package: copy packages/mailbox_tracker.yaml into your HA packages/ folder and add the include from configuration.example.yaml.
  3. Edit two references in the package: list everyone who collects the mail under the pickup trigger (person.you, person.partner, …), and ensure a zone.mailbox exists at your mailbox’s address (or rename the zone reference).
  4. Restart Home Assistant.
  5. Dashboard: add the card from dashboard/mailbox_card.yaml.
  6. Seed the current real count via the button/helper — you’re live.

Verify without waiting for mail

From Developer Tools ▸ Events, fire event type imap_content with:

subject: "New Mail"
uid: 999999
initial: true
text: "1 new mail item(s) have been added to your mailbox."

mailbox_items_waiting should jump by 1 and mailbox_last_uid to 999999. Re-fire with the same or a lower UID → no change (dedup proven). Set both back to 0 when done.

initial: true is not a typo. Real imap_content events carry initial: True on an add and False on a removal — it is not a startup flag, despite the integration docs reading that way. An earlier version of this project tested with initial: false, which passed the synthetic test and then dropped every real notice on the floor. If you hand-test, test with true, or you are testing the wrong path.

Files

packages/mailbox_tracker.yaml   # helpers (count, UID mark, pickup time, reset button) + 1 automation
dashboard/mailbox_card.yaml     # glanceable entities card
configuration.example.yaml      # the packages: include line

Security

No credentials are committed. The IMAP app password is entered in the HA UI and stored in the config entry — not in this repo and not in secrets.yaml. .storage/ is git-ignored.

Credits & Attribution

Trademarks (Anytime Mailbox, Fastmail) belong to their respective owners; this project is not affiliated with or endorsed by any of them.


Built with Claude Code. Never drive to an empty mailbox again. 📬