Unofficial Python API for SmartRent devices
Project description
SmartRent API
smartrent.py
is a simple library for SmartRent devices
Uses websockets for communication and supports async functions
Feel free to ⭐️ this repo to get notified about the latest features!
Supported Devices
This client supports:
- 🔐 Door Locks
- 🌡 Thermostats
- 💧 Leak Sensors
- 💡 Binary Switches
- 🎚 Multilevel (Dimmer) Switches
Usage
Installation
pip install smartrent.py
Getting an API Object
In order to get an api object to interact with, you must login with the async_login
function. This starts and handles a web session with SmartRent.
import asyncio
from smartrent import async_login
async def main():
api = await async_login('<EMAIL>', '<PASSWORD>')
asyncio.run(main())
Getting Devices
You can get lists of your devices from the api with the get_locks
, get_thermostats
, get_switches
and get_leak_sensors
functions. You can then interact with the devices with their getter and setter functions.
import asyncio
from smartrent import async_login
async def main():
api = await async_login('<EMAIL>', '<PASSWORD>')
lock = api.get_locks()[0]
locked = lock.get_locked()
if not locked:
await lock.async_set_locked(True)
asyncio.run(main())
Automatic Updating
If you need to get live updates to your device object from SmartRent, you can do that by calling start_updater
. You can stop getting updates by calling stop_updater
.
You can also set a callback function via set_update_callback
that will be called when an update is triggered.
For example, if you want to set your thermostat to Dad Mode
you can trigger an event every time the cooling_setpoint
is changed and just change it back to your own desired value.
import asyncio
from smartrent import async_login
async def main():
api = await async_login('<EMAIL>', '<PASSWORD>')
thermo = api.get_thermostats()[0]
thermo.start_updater()
CONSTANT_COOL = 80
async def on_evt():
if CONSTANT_COOL != thermo.get_cooling_setpoint():
await thermo.async_set_cooling_setpoint(CONSTANT_COOL)
thermo.set_update_callback(on_evt)
while True:
await asyncio.sleep(60)
asyncio.run(main())
Development
Setting up dev enviornment
pip install -r requirements_test.txt
Running the code formatter
Black is used for quick and easy code formatting
black smartrent
Special thanks
Much inspiration was taken from these projects:
AMcPherran/SmartRent-MQTT-Bridge
natanweinberger/smartrent-python
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Adding Unsupported Devices!
This library is built in a way that it is easy to add any smartrent device. If you find that one of the devices you own is not supported, we should be able to add it to this libray.
Two things are needed to get the info to add a new device:
- We have to get some device info from smartrents api
- We need to get info about how the device reacts when it enters different states
Both of these can be done in one script.
You have to run python3 ./tools/device_helper.py
It will print out some output and a table with Device ID
s and Device Names
. The device you wish to add should be listed in that table.
Device ID: Device Name:
==============================
2211234 Thermostat
2212345 Front Door - Lock
2212347 Washer - Leak Sensor
The program will then ask for a Device ID
that you wish to track. Enter in the Device ID
you want to gather information from.
Put in the Device ID you wish to track: 2211234
Joining topic for 2211234...
{'response': {}, 'status': 'ok'}
You can now change the state of your device either physically in your apartment/house or through the SmartRent app. For example, this is a thermostat's cooling point being turned up, and then the thermostat sending an update about the current humidity
ThermostatSetpoint cooling_setpoint 77
MultiLvlSensor current_humidity 53
Once you get a good amount of info, open up an issue describing that you wish to add support for a new device and paste all of the output from device_helper.py
. Feel free to hide your Device ID
s if you wish.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file smartrent.py-0.4.2.tar.gz
.
File metadata
- Download URL: smartrent.py-0.4.2.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.9 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2663a585ce5c6d8dd48392a40e51a26cbecca4935d3244ee6b9992e4c5c252db |
|
MD5 | eff987c63a587ed226ec9d6ac3500c31 |
|
BLAKE2b-256 | b0f817a07d4e46aec7732a1547cc1eab653711c02ca4d073a7eebe9699181266 |
File details
Details for the file smartrent.py-0.4.2-py3-none-any.whl
.
File metadata
- Download URL: smartrent.py-0.4.2-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.9 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc65bd5e75c482a57700d64e99374389df1699548c0c9f0ef3dea924b5e10812 |
|
MD5 | d218decbb981067b4d1523b85272d1f3 |
|
BLAKE2b-256 | 6b9ae218b6c6f59852e965598d9754e6a43ddfb3484bde35d8d2cf7aed8202ec |