Skip to content

sudoxnym/saas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Add to HACS

SAAS - Sleep As Android Status

Description:

Sleep As Android Status is my solution for wake/sleep state within HA. It listens for the Sleep As Android MQTT Messages, so it does require being on the same network. As of 0.0.4 Buttons that link with the Companion app have been added.

This integration works best with a Xioami MiBand (7 or older) mixed with the Notify app and Sleep As Android configured.

Known working:

Xioami Mi Band 7, 8 and 9 may work, but they have a different os that jumps through hoops to work.
Garmin Fenix 7X with Garmin Alternative, NOT the free one.

This integration will create 8 Sensors, 8 Buttons, 1 service, and 1 device per user:

Sensors

Message Received *State
Wake Status
Sound
Disturbance
Alarm
Lullaby
Sleep Tracking
Sleep Stage

This should intelligently and dynamically allow for state changes in the Wake Status Sensor.

Buttons

Alarm Dismiss
Alarm Snooze
Lullaby Stop
Sleep Tracking Pause
Sleep Tracking Resume
Sleep Tracking Start
Sleep Tracking Start with Optimal Alarm
Sleep Tracking Stop

Service

Set alarm service
service: saas.saas_example_alarm_set
data:
  message: Example Message!
  day: monday
  hour: 7
  minute: 30

Installation:

Add https://www.github.com/sudoxnym/saas to your Custom Repositories in HACS

Search and Download SAAS - Sleep As Android Status
Restart Home Assistant
Add To My Home Assistant
Add Integration: SAAS - Sleep As Android Status

Configuration:

Name: Name of user
Topic: MQTT Topic from Sleep As Android
QoS: Quality of Service

Awake Duration: This is for tuning. Time in seconds in which awake states = true to indicate awake. Sensor usually updates within 30 seconds or so after the duration, not entirely sure why the delay. FIXED
Asleep Duration: This is for tuning. Time in seconds in which sleep states = true to indicate asleep. Sensor usually updates within 30 seconds or so after the duration, not entirely sure why the delay. FIXED
Awake States: States to indicate being awake
Asleep States: States to indicate being asleep
Mobile App: Target for buttons REQUIRES COMPANION APP

Set Up Notify for MiBand 7 (as of August 10, 2024)

1. Pair MiBand 7 as you normally would with Mi Fitness app
2. Obtain auth key for Notify app. Connect to pc with usb and open your adb SDK Platform-Pools, or if you're more advanced, connect wirelessly
Windows:
  2a. Open folder with adb in it
  2b. Right click a blank spot within the folder
  2c. Open in terminal
  2d. Ensure usb debugging is on on your android and plug it into the pc.
  2e.
./adb shell
  2f.
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}'
  2g. Copy/clipboard the output. Disconnect phone, close ADB.
     Credit: iamfosscad
3. Uninstall Mi Fitness
4. Download/Install Notify for Mi Band (up to 7)
5. Follow the prompts, enable any permission it asks for, create the profile, input Auth Key, and select Mi Fitness is not installed
6. Open the hamburger menu on the top left
7. Search > Search for "Sleep"
8. Turn on Sleep as Android
9. Enjoy

1. Open the app and follow setup
2. Settings wheel in top right > Services > Automation
3. MQTT
  3a. URL
(tcp/ssl)://(MQTT User):(MQTT Pass)@(HA URL):(port)
  3b. Topic > something recognizable. You need this exact topic in HA Integration Config.
  3c. Client ID > I set the same, not sure if it should be, but it works.
  3d. Test > Wait for "Success" toast message
4. Back to app settings > Sleep tracking >
  4a. Automatic Sleep Tracking > After fall asleep
  4b. Sensor > Sonar (if placing phone on a bedside table) Accelerometer (if placing on bed next to you)
  4c. Wearables >
    4c1. Wearables > Xiaomi Mi Band > Test sensor
    4c2. Heart rate monitoring (optional)
  4d. Pair tracking (optional)
5. Enjoy (optional)

Changes:

0.0.6a
Initial Beta Release
Added persistant states through HA restart
Added attributes for the Alarm Event sensor

0.1.0
Fixed Wake Status Timing (HUGE)
Fixed bug with Sound sensor
Modified AlarmEvent, Disturbance, and Sound sensors to update to None accurately
Organized Readme.md

Known issues:

Error in logs:
Logger: homeassistant.helpers.service
Source: /usr/src/homeassistant/homeassistant/helpers/service.py:708
First occurred: 3:55:19 PM (1 occurrences)
Last logged: 3:55:19 PM

Failed to load integration: saas NoneType: None

No known effects. Just an error message, everything works as expected. Please report any issues.
This is my first integration.