/pyblinky

belkin brand wemo plug control

Primary LanguagePythonMIT LicenseMIT

pyblinky

Control Belkin brand Wemo smart plugs synchronously or asynchronously.

Install

Install from pypi.org

pip install pyblinky

Options

Parameter Default Description
ip Required Network location of plug1
timeout 3 Seconds to wait for response
name_cache_age 0 Seconds to store plug name before re-querying it

Actions

Action Parameters Description
on None Turn plug on
off None Turn plug off
toggle None Change plug status
burst seconds Turn on plug, wait num seconds, then turn off
status None Get status of plug as (bool)
identify None Get name of plug (str)
rename name Rename plug

A more thorough list of available actions on the plug is documented here and some may be implemented here in the future.

Examples

Synchronous

from pyblinky import Wemo

plug = Wemo('192.168.1.87')
print(plug.status())
print(plug.identify())
plug.on()

Asynchronous

import asyncio

from pyblinky import AsyncWemo

plugs = [
	AsyncWemo('192.168.1.87'),
	AsyncWemo('192.168.1.88'),
	AsyncWemo('192.168.1.89')
]

async def main():
    result = await asyncio.gather(
        *(
            [
                x.status()
                for x in plugs
            ] +
            [
                y.identify()
                for y in plugs
            ]
        )
    )
    print(result)

if __name__ == '__main__':
    asyncio.run(main())

Footnotes

  1. This project does not implement UPnP interface for device discovery, instead talking to plugs directly by IP address. It is highly recommended to set static IPs for plugs. Discovery may be added at a later date if a suitable library can be found.