Skip to main content

Lightweight Python module to discover and control WeMo devices

Project description

Python 3 module to setup, discover and control WeMo devices.

Dependencies

pyWeMo depends on Python packages: requests, ifaddr, lxml, urllib3

How to use

>>> import pywemo
>>> devices = pywemo.discover_devices()
>>> print(devices)
[<WeMo Insight "AC Insight">]

>>> devices[0].toggle()

If discovery doesn’t work on your network

On some networks discovery doesn’t work reliably, in that case if you can find the ip address of your Wemo device you can use the following code.

>>> import pywemo
>>> url = pywemo.setup_url_for_address("192.168.1.192", None)
>>> print(url)
http://192.168.1.192:49153/setup.xml
>>> device = pywemo.discovery.device_from_description(url, None)
>>> print(device)
<WeMo Maker "Hi Fi Systemline Sensor">

Please note that discovery.device_from_description call requires a url with an IP address, rather than a hostnames. This is needed for the subscription update logic to work properly. In addition recent versions of the WeMo firmware may not accept connections from hostnames, and will return a 500 error.

The setup_url_for_address function will lookup a hostname and provide a suitable url with an IP address.

Device Reset and Setup

pywemo includes the ability to reset and setup devices, without using the Belkin app or needing to create a Belkin account. This can be particularly useful if the intended use is fully local control, such as using Home Assistant.

Reset can be performed with the reset method, which has 2 boolean input arguments, data and wifi. Setting data=True will reset data (“Clear Personalized Info” in the Wemo app), which resets the device name and clears the icon and rules. Setting wifi=True will clear wifi information (“Change Wi-Fi” in the Wemo app), which does not clear the rules, name, etc. Setting both to true is equivalent to a “Factory Restore” from the app. It should also be noted that devices contain a hardware reset procedure as well, so using the software is for convenience or if physical access is not available.

Device setup is through the setup method. The user must first connect to the devices locally broadcast access point, then discover the device there. Once done, pass the desired SSID and password (AES encryption only) to the setup method to connect it to your wifi network.

Important Note for Device Setup - OpenSSL is Required!

OpenSSL is used to encrypt the password by the pywemo library. It must be installed and available on the path via calling openssl with a terminal (or command prompt, if on Windows). This is not required if connecting the device to an open network, since that requires no password, although an open network certainly isn’t recommended.

Firmware Warning

Starting in May of 2020, Belkin started requiring users to create an account and login to the app (Android app version 1.25). In addition to the account, most of the app functionality now requires a connection to the cloud (internet access), even for simple actions such as toggling a switch. All of the commands that go through the cloud are encrypted and cannot be easily inspected. This raises the possibility that Belkin could, in the future, update Wemo device firmware and make breaking API changes that can not longer be deciphered. If this happens, pywemo may no longer function on that device. It would be prudent to upgrade firmware cautiously and preferably only after confirming that breaking API changes have not been introduced.

Developing

Setup and builds are fully automated. You can run build pipeline locally by running.

# Setup, build, lint and test the code:

./scripts/build.sh

History

This started as a stripped down version of ouimeaux, but has since taken its own path.

License

Some of the code in pywemo/ouimeaux_device was originally written by by Ian McCracken (and is copyright). It is released under the BSD license. The overall library is released under the MIT license.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pywemo-0.6.3.tar.gz (73.1 kB view details)

Uploaded Source

Built Distribution

pywemo-0.6.3-py3-none-any.whl (81.3 kB view details)

Uploaded Python 3

File details

Details for the file pywemo-0.6.3.tar.gz.

File metadata

  • Download URL: pywemo-0.6.3.tar.gz
  • Upload date:
  • Size: 73.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.9 Linux/5.4.0-1039-azure

File hashes

Hashes for pywemo-0.6.3.tar.gz
Algorithm Hash digest
SHA256 4f92aa048658c5209c0d4ea2cd84348ed44bac26db13159033d754225e9e603e
MD5 c3550071b0a85fa3fbe7069dc91cc989
BLAKE2b-256 b97bdf3abbb172c1771f0a9cabbfe28446ff78d375d68941a78218ac534b8cd5

See more details on using hashes here.

Provenance

File details

Details for the file pywemo-0.6.3-py3-none-any.whl.

File metadata

  • Download URL: pywemo-0.6.3-py3-none-any.whl
  • Upload date:
  • Size: 81.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.9 Linux/5.4.0-1039-azure

File hashes

Hashes for pywemo-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c13411b2aa1137ef6e2ba6621fc2bdba7311efff394aadb1c2b59dc3d323b780
MD5 8761509bd64f058c1bf7ebf356ecd4de
BLAKE2b-256 3ed9dc0dfb329c9287e5ea54e0b7f8d12e9f32bd5099159160d8771a01b6d417

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page