Last active
December 29, 2015 05:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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