2025-12-08 21:01:59 +00:00
< div align = "center" >
< img src = "brands/icon.png" width = "128" height = "128" alt = "sleepd icon" >
2025-12-07 14:13:29 +00:00
# sleepd
2025-04-13 18:59:27 +00:00
2025-12-08 21:01:59 +00:00
**real-time sleep state tracking for home assistant**
[](https://hacs.xyz/docs/faq/custom_repositories)
[](LICENSE)
2025-04-13 18:59:27 +00:00
2025-12-08 21:01:59 +00:00
*processes sleep mqtt messages from android apps and exposes states, events, and controls to home assistant - automate your smart home based on whether you're awake or asleep.*
2025-04-15 18:37:36 +00:00
---
2025-12-08 21:01:59 +00:00
< / div >
2025-04-13 19:38:44 +00:00
2025-12-08 21:01:59 +00:00
## ✨ 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
2025-12-07 14:23:20 +00:00
- [sleep as android ](https://sleep.urbandroid.org/ ) (primary)
2025-12-08 21:01:59 +00:00
- any app that publishes sleep events via mqtt
2025-12-07 14:13:29 +00:00
2025-12-08 21:01:59 +00:00
## 📊 sensors
2025-12-07 14:13:29 +00:00
| sensor | description |
|--------|-------------|
| wake status | `awake` or `asleep` based on configurable states and durations |
2025-12-07 14:23:20 +00:00
| sleep stage | current stage (light, deep, rem, awake) |
2025-12-07 14:13:29 +00:00
| 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 |
2025-12-08 21:01:59 +00:00
## 🎮 buttons
2025-12-07 14:13:29 +00:00
*requires home assistant companion app*
- alarm dismiss / snooze
- lullaby stop
- sleep tracking start / stop / pause / resume
- sleep tracking start with smart alarm
2025-12-08 21:01:59 +00:00
## 📥 installation
### option 1: hacs (recommended)
2025-12-07 14:13:29 +00:00
1. add this repo to HACS custom repositories:
```
https://github.com/sudoxnym/sleepd
```
2. search for **sleepd** in HACS and install
3. restart home assistant
2025-12-08 21:01:59 +00:00
4. add integration via UI:
2025-12-07 14:13:29 +00:00
2025-12-07 14:23:20 +00:00
[](https://my.home-assistant.io/redirect/config_flow_start/?domain=saas)
2025-12-07 14:13:29 +00:00
2025-12-08 21:01:59 +00:00
### option 2: manual
copy `custom_components/saas` to your HA `custom_components` directory
## ⚙️ configuration
2025-12-07 14:13:29 +00:00
| option | description |
|--------|-------------|
| name | identifier for this user/device |
2025-12-07 14:23:20 +00:00
| topic | mqtt topic to subscribe to |
2025-12-07 14:13:29 +00:00
| awake duration | seconds of awake events before marking as awake |
| sleep duration | seconds of sleep events before marking as asleep |
| awake states | which states indicate being awake |
| sleep states | which states indicate being asleep |
| mobile app | companion app target for buttons (optional) |
2024-05-17 02:03:13 +00:00
2025-12-08 21:01:59 +00:00
## 📡 mqtt setup
2025-12-07 14:23:20 +00:00
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"}
```
2025-12-08 21:01:59 +00:00
### sleep as android config
2025-12-07 14:13:29 +00:00
2025-12-08 21:01:59 +00:00
1. open sleep as android → settings → services → automation → MQTT
2025-12-07 14:13:29 +00:00
2025-12-07 14:23:20 +00:00
2. connection string:
2025-12-07 14:13:29 +00:00
```
tcp://user:pass@your-ha-ip:1883
```
3. set topic to match your sleepd config
4. enable automatic tracking
2025-12-08 21:01:59 +00:00
## ⌚ tested wearables
2025-12-07 14:13:29 +00:00
- xiaomi mi band 7 (via notify for mi band)
2025-12-07 14:23:20 +00:00
- garmin fenix 7x (via garmin alternative)
- amazfit gtr3 pro
2025-04-13 18:59:27 +00:00
< details >
2025-12-07 14:23:20 +00:00
< summary > mi band 7 auth key extraction< / summary >
2025-12-07 14:13:29 +00:00
```bash
2025-12-07 14:23:20 +00:00
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}'
2025-12-07 14:13:29 +00:00
```
2025-04-13 18:59:27 +00:00
< / details >
2025-12-08 21:01:59 +00:00
## 📜 license
2025-04-13 18:59:27 +00:00
2025-12-08 21:01:59 +00:00
MIT — do whatever you want with it
2025-04-13 18:59:27 +00:00
2025-12-07 14:13:29 +00:00
---
2025-12-08 21:01:59 +00:00
< div align = "center" >
made by [sudoxnym ](https://sudoxreboot.com ) ⚡
2025-12-07 14:23:20 +00:00
*formerly known as saas*
2025-12-08 21:01:59 +00:00
< / div >