Your Levoit air purifier doesn't have a speaker—but your Sonos does.

Whenever PM2.5 spikes in the room, this script uses Gemini TTS to scold you out loud over your Sonos speaker like an angry mom who literally just finished cleaning.

Levoit Purifier ──► VeSync Cloud (pyvesync) ──► PM2.5 Spike Detector
                                                         │
Sonos Speaker ◄── Local HTTP Audio Server ◄── Gemini TTS (Kore + acting prompt)
  • Angry Mom Voice Persona: Powered by Gemini TTS (gemini-2.5-flash-preview-tts , voiceKore ) with expressive acting direction—supports Turkish (tr ), English (en ), or any language via--language .
  • Broad Levoit Support: Works with standardpyvesync air purifiersplus newer models not yet inpyvesync 's device map (like theEleva 300X / LAP-C341S-WEU ) via direct deviceProp parsing.
  • Smart Spike Detection: Triggers on either an absolutePM25_THRESHOLD or a sudden upward jump (PM25_DELTA ), with a configurableCOOLDOWN_SECONDS so it doesn't yell every 45 seconds.
  • Sonos Snapshot & Resume: UsesSoCo Snapshot to capture current Sonos state, play the scolding clip at your chosen volume, and restore playback afterward.
  • On-Demand Trigger & Custom Lines: Speak immediately withlevoit-blame say or pass-s /--sentence to deliver any exact phrase.
  • Clip Caching & Offline Fallbacks: Caches generated audio inaudio_cache/ and automatically falls back from Gemini TTS → Edge TTS → macOSsay if offline or unconfigured.
  • Python 3.12+ anduv
  • macOS (uses/usr/bin/afconvert and/usr/bin/afinfo for M4A conversion & duration inspection, plussay as the offline fallback)
  • A Levoit smart air purifier connected toVeSync
  • A Sonos speaker on the same local network
  • A Google Gemini API key (optional if you use--backend edge or--backend macos )

1. Clone and install dependencies:

git clone https://github.com/guneriu/levoit-mom-mode.git
cd levoit-mom-mode
uv sync

2. Create your .env file from .env.example:

cp .env.example .env

3. Fill in your credentials in .env:

  • VESYNC_EMAIL &VESYNC_PASSWORD : Your VeSync mobile app email and password.Signed up with Google? VeSync doesn't provide a separate API key andpyvesync cannot use Google SSO directly. Log out of the VeSync mobile app, tapForgot Password with the same Gmail address, and set a standalone VeSync password (this does not change your Google password).
  • VESYNC_COUNTRY_CODE : Your VeSync account region (US ,DE , etc.).
  • GEMINI_API_KEY : Your Gemini API key for Gemini TTS.
  • SONOS_IP : Optional—leave blank to auto-discover your Sonos speaker, or set its LAN IP.

Check Sonos discovery (read-only) and live Levoit PM2.5 telemetry:

uv run levoit-blame status --sonos-only
uv run levoit-blame status

Generate a TTS clip locally without playing on Sonos:

uv run levoit-blame test-tts -l tr
uv run levoit-blame test-tts -l en -s "I just cleaned it, why are you doing this?!"

Trigger an immediate scolding clip on Sonos (say or test-sonos):

# Random angry Turkish mom line
uv run levoit-blame say -l tr

# Random angry English mom line
uv run levoit-blame say -l en

# Exact custom sentence
uv run levoit-blame say -l en -s "I just cleaned it, why are you doing this?!"
uv run levoit-blame test-sonos -l tr -s "Ya daha yeni temizledim burayı!"

Simulate a PM2.5 spike end-to-end (dry-run by default; add --play-sonos to play):

uv run levoit-blame simulate --pm25 45 -l tr
uv run levoit-blame simulate --pm25 45 -l en --play-sonos

Run the continuous polling monitor:

uv run levoit-blame run --dry-run
uv run levoit-blame run -l tr
uv run levoit-blame run -l en -s "I just cleaned it, why are you doing this?!"

| Variable | Default | Description | |---|---|---| | VESYNC_EMAIL | "" | VeSync account email | | VESYNC_PASSWORD | "" | VeSync account password | | VESYNC_TIMEZONE | Europe/Berlin | IANA timezone | | VESYNC_COUNTRY_CODE | DE | VeSync account country code | | SONOS_IP | "" | Sonos speaker IP (blank = auto-discover) | | SONOS_VOLUME | 35 | Announcement volume ( 0–100 ) | | PM25_THRESHOLD | 20 | Trigger when PM2.5 reaches this value (µg/m³) | | PM25_DELTA | 10 | Or trigger on a single-poll jump of this size | | POLL_INTERVAL_SECONDS | 45 | VeSync polling interval (keep ≥ 30s to avoid rate limits) | | COOLDOWN_SECONDS | 300 | Minimum seconds between announcements | | TTS_BACKEND | gemini | gemini ,edge , ormacos | | GEMINI_API_KEY | "" | Google Gemini API key | | TTS_MODEL | gemini-2.5-flash-preview-tts | Gemini TTS model | | TTS_VOICE | Kore | Voice name ( Kore ,Gacrux ,Algenib ,Charon , etc.) | | TTS_LANGUAGE | tr | Default phrase & prompt language ( tr ,en , or any code) | | TTS_STYLE_PROMPT | Angry Turkish mom prompt | Custom acting direction prepended for Gemini TTS | | HTTP_PORT | 8765 | Local HTTP port for serving clips to Sonos |

Want to switch back to a grumpy uncle or try another vibe? Update .env:

  • Angry Mom (default):TTS_VOICE=Kore (orGacrux for a slightly more mature tone)
  • Grumpy Uncle:TTS_VOICE=Algenib (deep/gravelly) and customizeTTS_STYLE_PROMPT
uv run pytest -v

原文来源:github.com