mirror of
https://github.com/sudoxnym/sleepd.git
synced 2026-04-14 19:47:29 +00:00
Compare commits
7 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f2786e8a7 | ||
|
|
9f1b774a18 | ||
|
|
bf8830a330 | ||
|
|
b61f04e3e8 | ||
|
|
7ca0571d76 | ||
|
|
f1fd191e85 | ||
|
|
74d5b32c21 |
26 changed files with 145 additions and 94 deletions
215
README.md
215
README.md
|
|
@ -1,22 +1,36 @@
|
|||
# sleepd
|
||||
|
||||
> sleep as android status integration for home assistant
|
||||
**real-time sleep state tracking for home assistant**
|
||||
|
||||
[](https://hacs.xyz/docs/faq/custom_repositories)
|
||||
[](LICENSE)
|
||||
[](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.*
|
||||
|
||||
---
|
||||
|
||||
## what it does
|
||||
## ✨ features
|
||||
|
||||
sleepd listens for Sleep As Android MQTT messages and exposes sleep state, events, and controls to Home Assistant. track when you're asleep, detect snoring, control alarms, and automate your smart home based on your sleep.
|
||||
- **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
|
||||
|
||||
## sensors
|
||||
## 📱 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 from sleep as android (light, deep, rem, awake) |
|
||||
| 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 |
|
||||
|
|
@ -24,104 +38,141 @@ sleepd listens for Sleep As Android MQTT messages and exposes sleep state, event
|
|||
| lullaby | lullaby playback status |
|
||||
| state | raw event from last mqtt message |
|
||||
|
||||
## buttons
|
||||
## 🎮 buttons
|
||||
|
||||
*requires home assistant companion app*
|
||||
|
||||
- alarm dismiss / snooze
|
||||
- lullaby stop
|
||||
- sleep tracking start / stop / pause / resume
|
||||
- sleep tracking start with smart alarm
|
||||
| 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
|
||||
## 📥 installation
|
||||
|
||||
1. add this repo to HACS custom repositories:
|
||||
```
|
||||
https://github.com/sudoxnym/sleepd
|
||||
```
|
||||
### 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 or click below:
|
||||
4. add integration via UI:
|
||||
|
||||
[](https://my.home-assistant.io/redirect/config_flow_start/?domain=sleepd)
|
||||
[](https://my.home-assistant.io/redirect/config_flow_start/?domain=saas)
|
||||
|
||||
## configuration
|
||||
### 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"}
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary><strong>📲 set up Notify for Mi Band 7</strong></summary>
|
||||
<ol>
|
||||
<li>pair **Mi Band 7** as you normally would with <a href="https://play.google.com/store/apps/details?id=com.xiaomi.wearable&hl=en_US">Mi Fitness</a></li>
|
||||
<li>obtain auth key for Notify app using ADB</li>
|
||||
</ol>
|
||||
|
||||
<pre>
|
||||
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}'
|
||||
</pre>
|
||||
|
||||
<p>credit: <a href="https://www.reddit.com/r/miband/comments/15j0rfq/comment/kxlyzc6/">iamfosscad</a></p>
|
||||
|
||||
<ol start="3">
|
||||
<li>uninstall **Mi Fitness**</li>
|
||||
<li>download/install <a href="https://play.google.com/store/apps/details?id=com.mc.miband1&hl=en_US">Notify for Mi Band</a></li>
|
||||
<li>follow prompts, input auth key, select Mi Fitness is not installed</li>
|
||||
<li>enable Sleep As Android in Notify settings</li>
|
||||
</ol>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>🔐 extracting the Zepp <code>authKey</code> on a rooted android device</strong></summary>
|
||||
<pre>
|
||||
su
|
||||
cd /data/data/com.huami.watch.hmwatchmanager/databases/
|
||||
ls origin_db_*
|
||||
sqlite3 origin_db_1234567890 "SELECT AUTHKEY FROM DEVICE;"
|
||||
</pre>
|
||||
|
||||
<ul>
|
||||
<li>⚠️ do not unpair before extracting</li>
|
||||
<li>use with caution – root required</li>
|
||||
<li>modified apps are available on <a href="https://geekdoing.com">GeekDoing</a> and <a href="https://freemyband.com">FreeMyBand</a></li>
|
||||
</ul>
|
||||
</details>
|
||||
|
||||
<h3>🛌 <a href="https://play.google.com/store/apps/details?id=com.urbandroid.sleep&hl=en_US">sleep as android setup</a></h3>
|
||||
<ol>
|
||||
<li>open the app and follow setup</li>
|
||||
<li>settings wheel > services > automation > MQTT</li>
|
||||
</ol>
|
||||
|
||||
<pre>
|
||||
(tcp/ssl)://(MQTT User):(MQTT Pass)@(HA URL):(port)
|
||||
</pre>
|
||||
|
||||
<ul>
|
||||
<li>topic: must match config</li>
|
||||
<li>client id: any unique id</li>
|
||||
</ul>
|
||||
|
||||
<ol start="4">
|
||||
<li>enable automatic tracking</li>
|
||||
<li>sensor: sonar or accelerometer</li>
|
||||
<li>wearables > **Xiaomi Mi Band** > test sensor</li>
|
||||
</ol>
|
||||
|
||||
## ⚙️ configuration
|
||||
|
||||
| option | description |
|
||||
|--------|-------------|
|
||||
| name | identifier for this user/device |
|
||||
| topic | mqtt topic (must match sleep as android settings) |
|
||||
| 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) |
|
||||
|
||||
## sleep as android setup
|
||||
## ⌚ tested wearables
|
||||
|
||||
1. open sleep as android > settings > services > automation > MQTT
|
||||
|
||||
2. connection string format:
|
||||
```
|
||||
tcp://user:pass@your-ha-ip:1883
|
||||
```
|
||||
or with ssl:
|
||||
```
|
||||
ssl://user:pass@your-ha-ip:8883
|
||||
```
|
||||
|
||||
3. set topic to match your sleepd config
|
||||
|
||||
4. enable automatic tracking
|
||||
|
||||
## compatible wearables
|
||||
|
||||
tested with:
|
||||
- xiaomi mi band 7 (via notify for mi band)
|
||||
- garmin fenix 7x (via garmin alternative - paid)
|
||||
- amazfit gtr3 pro (may require root for auth key)
|
||||
|
||||
<details>
|
||||
<summary>mi band 7 setup with notify</summary>
|
||||
|
||||
1. pair band with mi fitness app
|
||||
2. extract auth key via adb:
|
||||
```bash
|
||||
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}'
|
||||
```
|
||||
3. uninstall mi fitness
|
||||
4. install [notify for mi band](https://play.google.com/store/apps/details?id=com.mc.miband1)
|
||||
5. enter auth key during setup
|
||||
6. enable sleep as android in notify settings
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>zepp auth key extraction (rooted)</summary>
|
||||
|
||||
```bash
|
||||
su
|
||||
cd /data/data/com.huami.watch.hmwatchmanager/databases/
|
||||
sqlite3 origin_db_* "SELECT AUTHKEY FROM DEVICE;"
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## changelog
|
||||
|
||||
**1.0.0** - rebranded from saas to sleepd, removed next alarm sensor
|
||||
|
||||
**0.2.1** - fixed manifest error, config reconfigure now works
|
||||
|
||||
**0.2.0** - fixed deprecation warnings for HA 2025.12 (breaking: re-add integration after update)
|
||||
|
||||
**0.1.0** - fixed wake status timing, sound sensor bugs
|
||||
| device | method |
|
||||
|--------|--------|
|
||||
| xiaomi mi band 7 | notify for mi band |
|
||||
| garmin fenix 7x | garmin alternative |
|
||||
| amazfit gtr3 pro | native |
|
||||
|
||||
---
|
||||
|
||||
*formerly known as [saas](https://github.com/sudoxnym/saas)*
|
||||
<div align="center">
|
||||
|
||||
made by [sudoxnym](https://sudoxreboot.com) ⚡
|
||||
|
||||
*formerly known as [saas - sleep as android status](https://github.com/sudoxreboot/saas/tree/main) — the app is capable of working with any mqtt sleep app now*
|
||||
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"""Constants for the sleepd - Sleep As Android Stats integration."""
|
||||
|
||||
DOMAIN = "sleepd"
|
||||
DOMAIN = "saas"
|
||||
|
||||
INTEGRATION_NAME = "sleepd - Sleep As Android Stats"
|
||||
MODEL = "sleepd - Version 0.0.1"
|
||||
10
custom_components/saas/manifest.json
Normal file
10
custom_components/saas/manifest.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"domain": "saas",
|
||||
"name": "sleepd - sleep mqtt processor",
|
||||
"codeowners": ["@sudoxnym"],
|
||||
"config_flow": true,
|
||||
"dependencies": ["mqtt", "mobile_app"],
|
||||
"documentation": "https://github.com/sudoxnym/sleepd",
|
||||
"issue_tracker": "https://github.com/sudoxnym/sleepd/issues",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"domain": "sleepd",
|
||||
"name": "sleepd - Sleep As Android Status",
|
||||
"codeowners": ["@sudoxnym"],
|
||||
"config_flow": true,
|
||||
"dependencies": ["mqtt", "mobile_app"],
|
||||
"documentation": "https://www.github.com/sudoxnym/sleepd",
|
||||
"issue_tracker": "https://www.github.com/sudoxnym/sleepd/issues",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"name": "sleepd - Sleep As Android Status",
|
||||
"name": "sleepd - sleep mqtt processor",
|
||||
"render_readme": true
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue