Skip to main content

ASync SleepIQ API

Project description

AsyncSleepIQ

AsyncSleepIQ is an library for accessing the SleepIQ API from Python. SleepIQ is an addon for SleepNumber beds.

Installation

pip install asyncsleepiq

Usage

The library is structured with classes SleepIQBed, SleepIQSleeper, and SleepIQFoundation that get updated with data fetched through the API.

After creating an intsance of AsyncSleepIQ() the login function should be called, followed by the init_beds() function to initialize the data structures and fetch the static data from the API. Following that, the fetch_bed_statuses() function can be called to get updated bed occupancy and sleep number values.

There are two authentication methods available: The older API with key parameter and the newer cookie-based Authentication header. As of Feb-2022 both work equally well.

The login() function should only be called once when the program is started, the fetch_bed_statuses() can be called more frequently to get the bed state. When implementing, do not poll the API by calling login each time, instead keep the same AsyncSleepIQ object and fetch data as needed. The library will re-authenticate automtically if the original authentication expires.

Here is a full example:

import asyncio
from asyncsleepiq import AsyncSleepIQ, LOGIN_KEY, LOGIN_COOKIE

email = "user@example.com"
password = "passw0rd"

async def main():
    api = AsyncSleepIQ(login_method=LOGIN_COOKIE)

    print(f"Logging in as {email}...")
    await api.login(email, password)

    print("Initializing bed data...")
    await api.init_beds()
    await api.fetch_bed_statuses()
    print("Beds:")
    for bed in api.beds.values():
        print(bed)

    bed = list(api.beds.values())[0]
    await bed.fetch_pause_mode()
    print (f"Pause mode: {bed.paused}")
    await bed.set_pause_mode(not bed.paused)
    await bed.fetch_pause_mode()
    print (f"New Pause mode: {bed.paused}")

    print("Calibrating...")
    await bed.calibrate()
    print("Stopping pump...")
    await bed.stop_pump()

    return api

if __name__ == "__main__":
    loop_ = asyncio.get_event_loop()
    api_ = loop_.run_until_complete(main())
    loop_.run_until_complete(api_.close_session())
    loop_.close()

Future Development

Without documentation for the API, development requires obvserving how other interfaces interact with it. Given the hardware dependencies are fairly high, any future development requires someone with the appropriate bed to be able to obvserve and test against.

Special Thanks

Thanks to all the other people that have tried to dig into this API, especially the projects:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncsleepiq-1.7.1.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asyncsleepiq-1.7.1-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file asyncsleepiq-1.7.1.tar.gz.

File metadata

  • Download URL: asyncsleepiq-1.7.1.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asyncsleepiq-1.7.1.tar.gz
Algorithm Hash digest
SHA256 80e8357317763ac0d18398ed73a31f10cb0af53d02ae8a3c2b58f3b2f6c06dd6
MD5 b2a95e431c8d2048a7ad89db2f3c678c
BLAKE2b-256 1289cf3ee30b63a99d66f0ea30df868bf1b41e7927b59a223f563a4ecdeaf6be

See more details on using hashes here.

File details

Details for the file asyncsleepiq-1.7.1-py3-none-any.whl.

File metadata

  • Download URL: asyncsleepiq-1.7.1-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asyncsleepiq-1.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6e67ae3e61117b837780899d2b5e9ebfbd1a876305697008a4f7572392ec717d
MD5 9fac05559254264dec83717d74aacf27
BLAKE2b-256 f33007f680f401d432a1d6b00996a3eb67c42d2c70964c01c5139de4ae185022

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page