Package: pylutron-caseta
pylutron-casetaA Python API to control Lutron Caséta devices.Getting startedIf you don't know the IP address of the bridge, theleap-scantool (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.AuthenticationIn 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-pairIf pylutron_caseta is installed with the cli extra (pip install pylutron_caseta[cli]), thelap-pairtool can be used to generate the certificate files. Simply runninglap-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. Checklap-pair --helpif you want to use different files.The pairing moduleIf pylutron_caseta is being integrated into a larger application, the pairing functionality can be reused to allow pairing from within that application.asyncdefpair(host:str):def_ready():print("Press the small black button on the back of the bridge.")data=awaitasync_pair(host,_ready)withopen("caseta-bridge.crt","w")ascacert:cacert.write(data["ca"])withopen("caseta.crt","w")ascert:cert.write(data["cert"])withopen("caseta.key","w")askey:key.write(data["key"])print(f"Successfully paired with{data['version']}")Connecting to the bridgeOnce you have the certificate files, you can connect to the bridge and start controlling devices.importasynciofrompylutron_caseta.smartbridgeimportSmartbridgeasyncdefexample():# `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")awaitbridge.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.awaitbridge.turn_on(device["device_id"])awaitbridge.close()# Because pylutron_caseta uses asyncio,# it must be run within the context of an asyncio event loop.loop=asyncio.get_event_loop()loop.run_until_complete(example())The leap toolFor development and testing of new features, there is aleapcommand in the cli extras (pip install pylutron_caseta[cli]) which can be used for communicating directly with the bridge, similar to usingcurl.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}]}}'