SMART Sniffer Home Assistant Notifications

smart-sniffer-home-assistant-notifications.md
title SMART Sniffer Home Assistant Notifications
date
author VahaC
read 10 min read
category Self-Hosting, Smart home
tags #Docker #HomeAssistant #Homelab #SmartHome
SMART Sniffer Home Assistant Notifications

In my previous post we got SMART Sniffer running and every drive showing up as a Home Assistant device. The persistent notification system that ships with SMART Sniffer is great when you’re actively looking at HA — but if a drive starts failing while you’re away from home, you’ll only see it when you next open the dashboard. ⚠️

This post covers building proper SMART Sniffer Home Assistant Notifications — mobile push to your phone, plus Telegram as a second channel — that fire exactly once when a drive’s health degrades, and never when HA restarts. Plus a bonus section on disk space alerts. 🎯

The naive automation for SMART Sniffer Home Assistant Notifications is one of the most common Home Assistant traps: a basic state trigger will spam you every time HA restarts, every time the agent reconnects, every time a sensor flickers. We’ll do it properly.


Prerequisites 🛠️

Before you start:

  • A working SMART Sniffer Home Assistant Notifications pipeline needs the integration installed and at least one drive showing up as a device — see the SMART Sniffer setup guide if you haven’t done that yet
  • The Home Assistant Mobile App installed and logged in on at least one phone
  • A Telegram account (only if you want Telegram notifications — it’s optional)

Step 1 — Set Up Mobile Push Notifications 📱

This is the easy part — push to your phone is the first leg of any SMART Sniffer Home Assistant Notifications pipeline. Install the official Home Assistant Companion app from the App Store or Google Play and log in to your HA instance.

Once logged in, HA automatically creates a notify.mobile_app_<device_name> service for each device. To find yours:

  1. Go to Developer Tools → Actions (older versions: Services)
  2. In the action dropdown, type notify.mobile_app_
  3. Pick yours from the list — note the exact name, you’ll need it later

Quick test — paste this into the Actions tab and run it:

action: notify.mobile_app_your_phone
data:
  title: "Test"
  message: "If you see this, push works"

If your phone buzzes, you’re good. ✅


Step 2 — Set Up Telegram Notifications (Optional) 💬

Push notifications can fail — your phone can be silenced, the app can be killed by Android battery optimizers, your iPhone can decide notifications aren’t important enough today. Adding Telegram as a second channel makes your SMART Sniffer Home Assistant Notifications redundant in a good way: it works on everything — phone, desktop, tablet, web.

Create a bot:

  1. Open Telegram → search for @BotFather
  2. Send /newbot and follow the prompts
  3. Save the API token — looks like 123456789:ABC-DEF...

Get your chat ID:

  1. In Telegram, send any message to @id_bot
  2. It replies with your numeric ID — that’s your chat ID
  3. Open a chat with your new bot and send /start (bots can’t message you first)

Add the integration through the HA UI:

  1. Settings → Devices & Services → Add Integration → Telegram bot
  2. Platform — pick Polling. It works without exposing HA to the internet
  3. API key — paste the token from BotFather
  4. Submit, then add a subentry to allowlist your chat ID (the integration will prompt for this — paste the ID from @id_bot)

That’s it — no configuration.yaml editing needed. The integration creates a telegram_bot.send_message action you can call from any automation.

Test it from Developer Tools → Actions:

action: telegram_bot.send_message
data:
  message: "Telegram notifications are working"

Full setup details and platform comparison at the official Telegram bot integration docs.


Step 3 — Why Naive Automation Breaks 💥

Before writing anything, let’s understand why most SMART Sniffer Home Assistant Notifications automations spam you.

A basic state trigger looks like this:

trigger:
  - platform: state
    entity_id: binary_sensor.attention_needed_dev_sda

It triggers on every state change. That means:

  • HA restarts → entity goes NOunavailableNO again → fires twice
  • Agent reconnects after a network blip → another transition → fires again
  • Drive recovers from MAYBE to NO → not actually a problem, but still fires
  • Sensor flickers between values for any reason → fires every time

The fix has three parts:

  1. Filter out unavailable and unknown states — these are not real health changes
  2. Only fire on degradationNO → MAYBE, NO → YES, MAYBE → YES. Never on recovery
  3. Add a for: debounce — the new state must hold for at least a minute. This kills startup races and brief flickers

Build all three into the automation and notifications become trustworthy: when your phone buzzes, something actually went wrong.


Step 4 — Build the Drive Degradation Automation 🔔

This is the heart of your SMART Sniffer Home Assistant Notifications setup. Adjust entity IDs to match yours (find them in Settings → Devices & Services → SMART Sniffer → click a drive).

alias: "SMART Drive Health Degraded"
description: "Notify on real drive health degradation, never on restarts"
mode: parallel

trigger:
  - platform: state
    entity_id:
      # List every Attention Needed entity you want to monitor
      - sensor.dev_sda_attention_needed
      - sensor.dev_sdb_attention_needed
      - sensor.dev_nvme0n1_attention_needed
    not_from:
      - "unavailable"
      - "unknown"
    not_to:
      - "unavailable"
      - "unknown"
    for: "00:01:00"

condition:
  # Only fire on real degradation, never on recovery
  - condition: template
    value_template: >
      {% set old = trigger.from_state.state %}
      {% set new = trigger.to_state.state %}
      {{ (old == 'NO' and new in ['MAYBE', 'YES']) or
         (old == 'MAYBE' and new == 'YES') }}

action:
  - variables:
      drive: "{{ trigger.to_state.attributes.friendly_name | default(trigger.entity_id) }}"
      old_state: "{{ trigger.from_state.state }}"
      new_state: "{{ trigger.to_state.state }}"
      severity: "{{ '🔴 CRITICAL' if new_state == 'YES' else '⚠️ WARNING' }}"

  # Mobile push
  - action: notify.mobile_app_your_phone
    data:
      title: "{{ severity }}: Drive Health Degraded"
      message: >
        {{ drive }} state changed: {{ old_state }} → {{ new_state }}.
        Check Home Assistant for details.
      data:
        priority: high
        ttl: 0

  # Telegram (remove this block if you skipped Step 2)
  - action: telegram_bot.send_message
    data:
      message: |
        {{ severity }}: Drive Health Degraded

        Drive: {{ drive }}
        State: {{ old_state }} → {{ new_state }}

        Check Home Assistant for details.

What each piece does:

  • mode: parallel — if multiple drives degrade at once, send all notifications simultaneously instead of queuing
  • not_from / not_to — official HA state trigger filters that prevent firing when transitioning to/from unavailable or unknown. This is the single most important line for avoiding restart spam
  • for: "00:01:00" — the new state must hold for 60 seconds before firing. Kills brief flickers and startup races where states settle in the first few seconds after a restart
  • condition template — explicit list of “this counts as degradation” transitions. Recovery (MAYBE → NO, YES → NO) is intentionally excluded
  • priority: high, ttl: 0 — mobile data flags telling iOS/Android to deliver immediately and never expire silently

To add this in HA: Settings → Automations & Scenes → Create Automation → Edit in YAML, paste it in, save. This single automation handles the SMART side of your SMART Sniffer Home Assistant Notifications — every monitored drive on every machine flows through it.

📚 Reference: State Trigger documentation for not_from/not_to/for semantics.


Step 5 — Testing It Without Waiting for a Drive to Fail 🧪

You don’t want to wait months for a real drive failure to find out if your SMART Sniffer Home Assistant Notifications work. Two safe ways to test:

Option A — trigger the automation directly:

Settings → Automations & Scenes → SMART Drive Health Degraded → three-dot menu → Run

⚠️ This skips triggers entirely, so any template that references trigger.* will throw UndefinedError: 'dict object' has no attribute 'to_state' and the automation stops before reaching the notify actions. Useless for testing this specific automation. Use Option B instead.

Option B — fake the state in Developer Tools:

  1. Go to Developer Tools → States
  2. Find one of your binary_sensor.attention_needed_* entities
  3. In the State field, type MAYBE (with the original state being NO) and click Set State
  4. Wait 60 seconds (the for: debounce)
  5. Phone should buzz, Telegram should chime

⚠️ Race condition heads-up. The integration polls the agent every 60 seconds and will overwrite your manually-set state back to the real value. If your for: debounce is 00:01:00, the next poll wins the race and the trigger never fires. For testing only, temporarily lower the debounce to for: "00:00:05" in your automation, run the test, then restore it to 00:01:00 afterward. The 1-minute debounce is what protects you from HA restart spam in production — don’t leave it at 5 seconds.

⚠️ Set State only changes the state in HA’s memory. The next time the integration polls the agent (within ~60 seconds), it’ll overwrite back to the real value. Don’t set state to YES and panic about a real drive — it’s just a UI test.

After testing, restart HA and confirm no notifications fire during the restart cycle. That’s the real proof that your SMART Sniffer Home Assistant Notifications filter logic works.


Bonus — Disk Space Notifications 💾

Drive failure is one risk, drives filling up is another. Adding disk usage alerts to your SMART Sniffer Home Assistant Notifications stack covers both. If you enabled disk usage monitoring during agent install, you got a “Disk Usage” device per host with one sensor per mountpoint. Setting up alerts is similar to the SMART one but simpler — we use a numeric threshold instead of categorical state changes.

alias: "Disk Usage High"
description: "Notify when any monitored mountpoint crosses 85% used"
mode: single

trigger:
  - platform: numeric_state
    entity_id:
      # Add your disk usage sensors here
      - sensor.disk_usage_pve_root
      - sensor.disk_usage_omv_srv_dev_disk_by_uuid_xxx
    above: 85
    for: "00:05:00"

condition:
  - condition: template
    value_template: >
      {{ trigger.from_state.state not in ['unavailable', 'unknown', 'none'] }}

action:
  - variables:
      mount: "{{ trigger.to_state.attributes.friendly_name | default(trigger.entity_id) }}"
      pct: "{{ trigger.to_state.state }}"

  - action: notify.mobile_app_your_phone
    data:
      title: "💾 Disk Almost Full"
      message: "{{ mount }} is at {{ pct }}% capacity"

  - action: telegram_bot.send_message
    data:
      message: |
        💾 Disk Almost Full

        Mountpoint: {{ mount }}
        Usage: {{ pct }}%

How this differs from the SMART degradation automation:

  • platform: numeric_state with above: 85 — fires only when the sensor crosses 85 going up. If the value oscillates around 85 (e.g. 84 → 86 → 84 → 86), each upward cross fires once. Stays above 85 forever? Fires once, then waits until it drops below before re-arming
  • for: "00:05:00" — value must stay above 85% for 5 minutes. Filters out brief spikes (a temp file, a backup running)
  • mode: single — if it’s already running, ignore subsequent triggers. We don’t need three notifications for the same mountpoint
  • Template condition — same unavailable/unknown filter as before

If you want multi-tier alerts (warning at 85%, critical at 95%), make two automations — one for each threshold. Don’t try to handle both in one automation, it gets messy fast. Layering simple automations like this is the cleanest way to extend your SMART Sniffer Home Assistant Notifications without losing readability.

📚 Reference: Numeric State Trigger documentation for the crossing semantics.


What to Expect in Practice 🐾

With these two automations in place, here’s what your SMART Sniffer Home Assistant Notifications experience looks like:

  • HA restart → silence ✅
  • Agent reconnect after a network blip → silence ✅
  • Drive temperature spikes briefly during a backup → silence ✅
  • Drive’s Attention Needed flips from NO to MAYBE → one push, one Telegram message ✅
  • Same drive escalates from MAYBE to YES → another push, another Telegram message ✅
  • Drive recovers from MAYBE to NO after you replaced cables → silence (intentional — recovery isn’t an alert) ✅
  • A mountpoint crosses 85% full and stays there → one push, one Telegram message ✅

That’s the whole point: when your phone buzzes about a drive, it actually means something.


If you’re running multiple Proxmox nodes and want similar treatment for your VMs and containers, the Proxmox VE post-install script guide lays the foundation for a stable host before you add any monitoring.

And if your NAS drives keep waking up from sleep too often (and skewing the SMART data), how to disable disk sleep and spindown on Linux and OpenMediaVault explains how to get them to behave.

Set up these SMART Sniffer Home Assistant Notifications once, and you’ll never miss a failing drive again — without the noise. 🎯

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.