Skip to content

Instantly share code, notes, and snippets.

@matbor
Last active December 29, 2015 05:39
Show Gist options
  • Select an option

  • Save matbor/7623421 to your computer and use it in GitHub Desktop.

Select an option

Save matbor/7623421 to your computer and use it in GitHub Desktop.
Belkin Wemo discover switches and automatically subscribe to events. Needs the https://github.com/iancmcc/ouimeaux library to work.
import datetime
from ouimeaux.environment import Environment
def on_switch(switch): #discover light switches and register listeners
print('******** Switch found:'+ switch.name+ ', Current state : '+str(switch.get_state()))
x = switch.name.replace(" ", "") #remove spaces
x = env.get_switch(switch.name)
x.register_listener(on_change)
def on_change(value):
now = datetime.datetime.now() #.time()
print(str(now.strftime("%d %B %Y at %I:%M%p"))+' ********* light was switched! Switch: #####'+ ', Current state : ' +value)
env = Environment(switch_callback=on_switch, with_cache=False)
env.start()
env.discover(3)
env.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment