real-time sleep state tracking for home assistant
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.
- wake status sensor —
awakeorasleepbased 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
- sleep as android (primary)
- any app that publishes sleep events via mqtt
| 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 |
requires home assistant companion app
- alarm dismiss / snooze
- lullaby stop
- sleep tracking start / stop / pause / resume
- sleep tracking start with smart alarm
-
add this repo to HACS custom repositories:
https://github.com/sudoxnym/sleepd -
search for sleepd in HACS and install
-
restart home assistant
-
add integration via UI:
copy custom_components/saas to your HA custom_components directory
| option | description |
|---|---|
| name | identifier for this user/device |
| topic | mqtt topic to subscribe to |
| 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) |
sleepd expects json messages with an event field:
{"event": "sleep_tracking_started"}
{"event": "sleep_tracking_stopped"}
{"event": "alarm_alert_start", "value1": "1733580000000"}
{"event": "light_sleep"}
{"event": "deep_sleep"}
{"event": "rem"}-
open sleep as android → settings → services → automation → MQTT
-
connection string:
tcp://user:pass@your-ha-ip:1883 -
set topic to match your sleepd config
-
enable automatic tracking
- xiaomi mi band 7 (via notify for mi band)
- garmin fenix 7x (via garmin alternative)
- amazfit gtr3 pro
mi band 7 auth key extraction
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}'MIT — do whatever you want with it
made by sudoxnym ⚡
formerly known as saas