Skip to main content

Provides an API to the Lutron Smartbridge

Project description

pylutron-caseta

A Python API to control Lutron Caséta devices.

Coverage Status

Getting started

If you don't know the IP address of the bridge, the leap-scan tool (requires the cli extra, pip install pylutron_caseta[cli]) will search for LEAP devices on the local network and display their address and LEAP port number.

Authentication

In order to communicate with the bridge device, you must complete the pairing process. This generates certificate files for authentication. pylutron_caseta can do this two ways.

lap-pair

If pylutron_caseta is installed with the cli extra (pip install pylutron_caseta[cli]), the lap-pair tool can be used to generate the certificate files. Simply running lap-pair <BRIDGE HOST> (note the LEAP port number should not be included) will begin the pairing process. The certificate files will be saved in $XDG_CONFIG_HOME/pylutron_caseta (normally ~/.config/pylutron_caseta) in the files [BRIDGE HOST]-bridge.crt, [BRIDGE HOST].crt, [BRIDGE HOST].key. Check lap-pair --help if you want to use different files.

The pairing module

If pylutron_caseta is being integrated into a larger application, the pairing functionality can be reused to allow pairing from within that application.

async def pair(host: str):
    def _ready():
        print("Press the small black button on the back of the bridge.")

    data = await async_pair(host, _ready)
    with open("caseta-bridge.crt", "w") as cacert:
        cacert.write(data["ca"])
    with open("caseta.crt", "w") as cert:
        cert.write(data["cert"])
    with open("caseta.key", "w") as key:
        key.write(data["key"])
    print(f"Successfully paired with {data['version']}")

Connecting to the bridge

Once you have the certificate files, you can connect to the bridge and start controlling devices.

import asyncio

from pylutron_caseta.smartbridge import Smartbridge

async def example():
    # `Smartbridge` provides an API for interacting with the Caséta bridge.
    bridge = Smartbridge.create_tls(
        "YOUR_BRIDGE_IP", "caseta.key", "caseta.crt", "caseta-bridge.crt"
    )
    await bridge.connect()

    # Get the first light.
    # The device is represented by a dict.
    device = bridge.get_devices_by_domain("light")[0]
    # Turn on the light.
    # Methods that act on devices expect to be given the device id.
    await bridge.turn_on(device["device_id"])

    await bridge.close()


# Run the example function within an asyncio loop.
asyncio.run(example())

The leap tool

For development and testing of new features, there is a leap command in the cli extras (pip install pylutron_caseta[cli]) which can be used for communicating directly with the bridge, similar to using curl.

Getting information about the bridge:

$ leap 192.168.86.49/server | jq
{
  "Servers": [
    {
      "href": "/server/1",
      "Type": "LEAP",
      "NetworkInterfaces": [
        {
          "href": "/networkinterface/1"
        }
      ],
      "EnableState": "Enabled",
      "LEAPProperties": {
        "PairingList": {
          "href": "/server/leap/pairinglist"
        }
      },
      "Endpoints": [
        {
          "Protocol": "TCP",
          "Port": 8081,
          "AssociatedNetworkInterfaces": null
        }
      ]
    }
  ]
}

Turning on the first dimmer:

$ ip=192.168.86.49
$ device=$(leap "${ip}/zone/status/expanded?where=Zone.ControlType:\"Dimmed\"" | jq -r '.ZoneExpandedStatuses[0].Zone.href')
$ leap -X CreateRequest "${ip}${device}/commandprocessor" -d '{"Command":{"CommandType":"GoToLevel","Parameter":[{"Type":"Level","Value":100}]}}'

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

pylutron_caseta-0.28.0.tar.gz (56.6 kB view details)

Uploaded Source

Built Distribution

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

pylutron_caseta-0.28.0-py3-none-any.whl (35.5 kB view details)

Uploaded Python 3

File details

Details for the file pylutron_caseta-0.28.0.tar.gz.

File metadata

  • Download URL: pylutron_caseta-0.28.0.tar.gz
  • Upload date:
  • Size: 56.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.1 cpython/3.13.12 HTTPX/0.28.1

File hashes

Hashes for pylutron_caseta-0.28.0.tar.gz
Algorithm Hash digest
SHA256 266a806f29e6fca6f6a572c5739734f5041c0b5aec16e03a189455a7ac80b72f
MD5 073021471eb4d2e84a05f07714a40861
BLAKE2b-256 0198ebf87849d83d619d1ce179fd962ba7791e684857abd41e7cbd1a06e00a4c

See more details on using hashes here.

File details

Details for the file pylutron_caseta-0.28.0-py3-none-any.whl.

File metadata

  • Download URL: pylutron_caseta-0.28.0-py3-none-any.whl
  • Upload date:
  • Size: 35.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.1 cpython/3.13.12 HTTPX/0.28.1

File hashes

Hashes for pylutron_caseta-0.28.0-py3-none-any.whl
Algorithm Hash digest
SHA256 459d8c4361db6f6b01e5e1f1dc77e963fdeb458ea560386e0a2f0c96d16798f5
MD5 f5a336134a43fd822bd929837ceb5ed4
BLAKE2b-256 3f3ff03b18d271356e6e7de293971b2a79a58695ed7bcaf7a0e1fabd238ffa50

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