tlyakhov / python-decora_wifi

Python Library for Interacting with Leviton Decora Smart WiFi Switches & Dimmers
MIT License
37 stars 21 forks source link

python-decora_wifi

Python Library for Interacting with Leviton Decora Smart WiFi Switches & Dimmers.

The code is reverse engineered from the myLeviton Android app and includes an "API scraper" python script that generates model classes for invoking Leviton Cloud Services REST APIs.

See cli-test.py for a usage example.

Create a session first:

session = DecoraWiFiSession()
session.login(decora_email, decora_pass)

After that, the logged in user is accessible in session.user.

To get the user's residences, go through the ResidentialPermissions model like this:

perms = session.user.get_residential_permissions() # Usually just one of these

for permission in perms:
  acct = ResidentialAccount(session, permission.residentialAccountId)
  residences = acct.get_residences()

Now from each residence, you can get a list of switches:

  for residence in residences:
    switches = residence.get_iot_switches()
    for switch in switches:
      print(switch)

Other useful methods:

Notes: