All Projects β†’ andrewsayre β†’ Pysmartthings

andrewsayre / Pysmartthings

Licence: apache-2.0
A python library for interacting with the SmartThings cloud API build with asyncio and aiohttp.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pysmartthings

Homeassistant
Example Home Assistant Configs
Stars: ✭ 846 (+1558.82%)
Mutual labels:  home-automation, iot, internet-of-things
Home Assistant Config
🏠 My Home Assistant configuration, a bit different that others :) Be sure to 🌟 this repository for updates!
Stars: ✭ 1,050 (+1958.82%)
Mutual labels:  home-automation, iot, internet-of-things
Broadlink Mqtt
MQTT client to control BroadLink devices
Stars: ✭ 169 (+231.37%)
Mutual labels:  home-automation, iot, internet-of-things
Home assistant files
Here are my Home Assistant configuration files
Stars: ✭ 159 (+211.76%)
Mutual labels:  home-automation, iot, internet-of-things
Smarthome
Eclipse SmartHomeβ„’ project
Stars: ✭ 867 (+1600%)
Mutual labels:  home-automation, iot, internet-of-things
Homeassistant
Example Home Assistant Configs
Stars: ✭ 168 (+229.41%)
Mutual labels:  home-automation, iot, internet-of-things
Home Assistant Config
Home Assistant config files, rewritten to use the latest features, 100+ documented automations, automatically generated ToC 🏠 πŸ€–
Stars: ✭ 926 (+1715.69%)
Mutual labels:  home-automation, iot, internet-of-things
Core
🏑 Open source home automation that puts local control and privacy first.
Stars: ✭ 48,265 (+94537.25%)
Mutual labels:  home-automation, iot, internet-of-things
Awesome Home Assistant
A curated list of amazingly awesome Home Assistant resources.
Stars: ✭ 3,487 (+6737.25%)
Mutual labels:  home-automation, iot, internet-of-things
Homeassistant Config
Stars: ✭ 211 (+313.73%)
Mutual labels:  home-automation, iot, internet-of-things
Entity Controller
Entity and lighting controller for managing devices via timers, scripts, and sun-based time restrictions.
Stars: ✭ 156 (+205.88%)
Mutual labels:  home-automation, iot, internet-of-things
Openhab Core
Core framework of openHAB
Stars: ✭ 472 (+825.49%)
Mutual labels:  home-automation, iot, internet-of-things
Openhab Ios
The repository of the iOS client
Stars: ✭ 141 (+176.47%)
Mutual labels:  home-automation, iot, internet-of-things
Coapnet
CoAPnet is a high performance .NET library for CoAP based communication. It provides a CoAP client and a CoAP server. It also has DTLS support out of the box.
Stars: ✭ 23 (-54.9%)
Mutual labels:  home-automation, iot, internet-of-things
Ha Floorplan
Floorplan for Home Assistant
Stars: ✭ 1,626 (+3088.24%)
Mutual labels:  home-automation, iot, internet-of-things
Home Assistant
Home-Assistant-Config
Stars: ✭ 182 (+256.86%)
Mutual labels:  home-automation, iot, internet-of-things
Rpieasy
Easy MultiSensor device based on Raspberry PI
Stars: ✭ 85 (+66.67%)
Mutual labels:  home-automation, iot, internet-of-things
Psmqtt
Utility reporting system health and status via MQTT
Stars: ✭ 95 (+86.27%)
Mutual labels:  home-automation, iot, internet-of-things
Blynk Server
Blynk is an Internet of Things Platform aimed to simplify building mobile and web applications for the Internet of Things. Easily connect 400+ hardware models like Arduino, ESP8266, ESP32, Raspberry Pi and similar MCUs and drag-n-drop IOT mobile apps for iOS and Android in 5 minutes
Stars: ✭ 8 (-84.31%)
Mutual labels:  home-automation, iot, internet-of-things
Freedomotic
Open IoT Framework
Stars: ✭ 354 (+594.12%)
Mutual labels:  home-automation, iot, internet-of-things

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, & Generate
  5. InstalledApps: List, Get, Delete
  6. Subscriptions: List, Get, Create, Delete, Delete All
  7. Scenes: List, Execute
  8. OAuth: Generate refresh/access token pair

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.values)
    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(component_id, capability, command, args=None) function. The component_id parameter is the identifier of the component within the device (main is the device itself); capability is the name of the capability implemented by the device; and command is one of the defined operations within the capability. args is an array of parameters to pass to the command when it accepts parameters (optional). See the SmartThings Capability Reference for more information.

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

    result = await device.command("main", "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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].