Skip to main content

A python library for interacting with the SmartThings cloud API build with asyncio and aiohttp.

Project description

pysmartthings

Build Status Coverage Status image image image image

A python library for interacting with the SmartThings cloud API build with asyncio and aiohttp.

Features

The package is still in beta, but the following features are available:

  1. Locations: List, Get
  2. Rooms: List, Get, Create, Update, Delete
  3. Devices: List, Get, Command, Status
  4. Apps: List, Get, Create, Update, Delete, Settings Get & Update, OAuth: Get & Update
  5. InstalledApps: List, Get, Delete
  6. Subscriptions: List, Get, Create, Delete, Delete All
  7. Scenes: List, Execute

Installation

pip install pysmartthings

or

pip install --use-wheel pysmartthings

Usage

Initialization

The SmartThings class encapsulates the API operations and the constructor accepts the aiohttp WebSession and your personal access token.

import aiohttp
import pysmartthings

token = 'PERSONAL_ACCESS_TOKEN'

async with aiohttp.ClientSession() as session:
    api = pysmartthings.SmartThings(session, token)
    # ...

Locations

A list of locations in SmartThings can be retrieved by invoking the coroutine locations().

    locations = await api.locations()
    print(len(locations))

    location = locations[0]
    print(location.name)
    print(location.location_id) 

Outputs:

2
'Test Home'
'5c03e518-118a-44cb-85ad-7877d0b302e4'

Devices

A list of devices can be retrieved by invoking the coroutine devices(location_ids=None, capabilities=None, device_ids=None). The optional parameters allow filtering the returned list.

    devices = await api.devices()
    print(len(devices))

    device = devices[0]
    print(device.device_id)
    print(device.name)
    print(device.label)
    print(device.capabilities)

Outputs:

19
'0d38d5ca-705f-44f7-89bd-36a8cf73678d'
'GE In-Wall Smart Dimmer'
'Back Patio Light'
['switch', 'switchLevel', 'refresh', 'indicator', 'button', 'sensor', 'actuator', 'healthCheck', 'light']

The current status of the device is populated when the coroutine status.refresh() is called. The DeviceStatus class represents the current values of the capabilities and provides several normalized property accessors.

    await device.status.refresh()    
    print(device.status.attributes)
    print(device.status.switch)
    print(device.status.level)

Outputs:

{'button': 'pressed', 'numberOfButtons': None, 'supportedButtonValues': None, 'indicatorStatus': 'when off', 'switch': 'on', 'checkInterval': 1920, 'healthStatus': None, 'DeviceWatch-DeviceStatus': None, 'level': 100}
True
100

Device Commands

You can execute a command on a device by calling the coroutine command(capability, command, args=None) function. The capability parameter corresponds to one of the capabilities detected and command is one of the define commands. args is an array of parameters to pass to the command (optional). See the SmartThings Capability Reference for more information.

    result = await device.command("switch", "on")
    assert result == True

    result = await device.command("switchLevel", "setLevel", [75, 2])
    assert result == True

Devices with the switch capability have the following coroutines:

    result = await device.switch_on()
    assert result == True

    result = await device.switch_off()
    assert result == True

Devices with the switchLevel capability have the following function that sets the target brightness level and transitions using a specific duration (seconds).

    result = await device.set_level(75, 2)
    assert result == True

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

pysmartthings-0.5.0.tar.gz (30.9 kB view details)

Uploaded Source

Built Distribution

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

pysmartthings-0.5.0-py3-none-any.whl (39.9 kB view details)

Uploaded Python 3

File details

Details for the file pysmartthings-0.5.0.tar.gz.

File metadata

  • Download URL: pysmartthings-0.5.0.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.5.6

File hashes

Hashes for pysmartthings-0.5.0.tar.gz
Algorithm Hash digest
SHA256 98bda1ba82ebd5590a247caa1149ec58e271f8562c83c006585a456e3b44d089
MD5 664502c2c72990bf69d8b93b4eeab1cf
BLAKE2b-256 eb7b570c15d2d96e2d61c62ef30f4208e4d5e046ac2ff0a4480a94501075ac15

See more details on using hashes here.

File details

Details for the file pysmartthings-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pysmartthings-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 39.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.5.6

File hashes

Hashes for pysmartthings-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fdb9de143dc9f9ee7b0ec692c3362bf85a9ced1a4055e7879d52a837b275c3e
MD5 1e5c4dbb1b0e228689713b6a826ec2ed
BLAKE2b-256 ecbbd0d99d5c0f737e9a8409849c33bda8feccc47e499d7ba9fbb88aef022e62

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