# sleepd
**real-time sleep state tracking for home assistant**
[](https://hacs.xyz/docs/faq/custom_repositories)
[](LICENSE)
*processes sleep mqtt messages and exposes states, events, and controls to home assistant - automate your smart home based on whether you're awake or asleep.*
---
## ✨ features
- **wake status sensor** — `awake` or `asleep` based on configurable thresholds
- **sleep stage tracking** — light, deep, rem, awake
- **alarm controls** — dismiss, snooze, skip via HA buttons
- **sound detection** — snore, talk, cough events
- **lullaby control** — playback status and stop button
- **disturbance alerts** — apnea and anti-snoring events
## 📱 compatible apps
| app | notes |
|-----|-------|
| [sleep as android](https://sleep.urbandroid.org/) | primary |
| any mqtt sleep app | publishes sleep events via mqtt |
## 📊 sensors
| sensor | description |
|--------|-------------|
| wake status | `awake` or `asleep` based on configurable states and durations |
| sleep stage | current stage (light, deep, rem, awake) |
| sleep tracking | whether tracking is active or paused |
| alarm event | alarm events like snooze, dismiss, skip |
| sound | snore, talk, cough, and other detected sounds |
| disturbance | apnea and anti-snoring events |
| lullaby | lullaby playback status |
| state | raw event from last mqtt message |
## 🎮 buttons
*requires home assistant companion app*
| button | description |
|--------|-------------|
| alarm dismiss | dismiss active alarm |
| alarm snooze | snooze active alarm |
| lullaby stop | stop lullaby playback |
| sleep tracking start | begin tracking session |
| sleep tracking stop | end tracking session |
| sleep tracking pause | pause tracking session |
| sleep tracking resume | resume paused session |
| sleep tracking start with smart alarm | start with smart alarm enabled |
## 📥 installation
### option 1: hacs (recommended)
1. add to hacs
[](https://my.home-assistant.io/redirect/hacs_repository/?owner=sudoxreboot&repository=sleepd&category=integration)
2. search for **sleepd** in HACS and install
3. restart home assistant
4. add integration via UI:
[](https://my.home-assistant.io/redirect/config_flow_start/?domain=saas)
### option 2: manual
1. copy `custom_components/saas` to your HA `custom_components` directory
2. restart home assistant
## 📡 mqtt setup
sleepd expects json messages with an `event` field:
```json
{"event": "sleep_tracking_started"}
{"event": "sleep_tracking_stopped"}
{"event": "alarm_alert_start", "value1": "1733580000000"}
{"event": "light_sleep"}
{"event": "deep_sleep"}
{"event": "rem"}
```
credit: iamfosscad📲 set up Notify for Mi Band 7
adb shell
grep -E "authKey=[a-z0-9]*," /sdcard/Android/data/com.xiaomi.wearable/files/log/XiaomiFit.device.log |
awk -F ", " '{print $17}' | grep authKey | tail -1 | awk -F "=" '{print $2}'
🔐 extracting the Zepp
authKey on a rooted android device
su
cd /data/data/com.huami.watch.hmwatchmanager/databases/
ls origin_db_*
sqlite3 origin_db_1234567890 "SELECT AUTHKEY FROM DEVICE;"
(tcp/ssl)://(MQTT User):(MQTT Pass)@(HA URL):(port)