Last active
December 28, 2015 22:59
-
-
Save matbor/7575954 to your computer and use it in GitHub Desktop.
testing wemo ouimeaux script to get the state of my belkin wemo device
This file contains 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
from ouimeaux.environment import Environment | |
def on_switch(switch): | |
print ('******** Switch found:', switch.name) | |
def on_change(value): | |
print('******** light has changed state and has been switched!') | |
env = Environment(switch_callback=on_switch, with_cache=False) | |
env.start() | |
env.discover(3) | |
lounge = env.get_switch('Lounge room lamp') | |
lounge.register_listener(on_change) | |
env.wait() |
update.... just upgraded to 0.5.1 and it seems to of fixed my problem and is detecting the switch changes now ;)
but now it is coming up with this error....
'******** Switch found:', 'Lounge room lamp'
192.168.4.109 - - [2013-11-22 10:10:31] "NOTIFY / HTTP/1.1" 200 161 0.013892
<socket fileno=7 sock=192.168.4.20:8989>: Invalid HTTP method: '\n'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 328, in run
result = self._run(*self.args, **self.kwargs)
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 654, in handle
handler.handle()
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 190, in handle
self.socket.sendall(response_body)
File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 458, in sendall
data_sent += self.send(_get_memory(data, data_sent), flags)
File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 435, in send
return sock.send(data, flags)
error: [Errno 32] Broken pipe
<Greenlet at 0x25c8440: <bound method WSGIServer.handle of <WSGIServer at 0x25bdcb0 fileno=6 address=0.0.0.0:8989>>(<socket at 0x262dd70 fileno=[Errno 9] Bad file des, ('192.168.4.109', 3322))> failed with error
192.168.4.109 - - [2013-11-22 10:10:31] "NOTIFY / HTTP/1.1" 200 161 0.002756
<socket fileno=8 sock=192.168.4.20:8989 peer=192.168.4.109:3323>: Invalid HTTP method: '\n'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 328, in run
result = self._run(*self.args, **self.kwargs)
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 654, in handle
handler.handle()
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 190, in handle
self.socket.sendall(response_body)
File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 458, in sendall
data_sent += self.send(_get_memory(data, data_sent), flags)
File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 435, in send
return sock.send(data, flags)
error: [Errno 32] Broken pipe
<Greenlet at 0x25c8710: <bound method WSGIServer.handle of <WSGIServer at 0x25bdcb0 fileno=6 address=0.0.0.0:8989>>(<socket at 0x262d8f0 fileno=[Errno 9] Bad file des, ('192.168.4.109', 3323))> failed with error
192.168.4.109 - - [2013-11-22 10:10:31] "NOTIFY / HTTP/1.1" 200 161 0.002753
<socket fileno=7 sock=192.168.4.20:8989 peer=192.168.4.109:3324>: Invalid HTTP method: '\n'
192.168.4.109 - - [2013-11-22 10:10:31] "" 400 0 0.002173
'******** light has changed state and has been switched!
192.168.4.109 - - [2013-11-22 10:10:44] "NOTIFY / HTTP/1.1" 200 161 0.015749
<socket fileno=7 sock=192.168.4.20:8989 peer=192.168.4.109:3325>: Invalid HTTP method: '\n'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 328, in run
result = self._run(*self.args, **self.kwargs)
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 654, in handle
handler.handle()
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 190, in handle
self.socket.sendall(response_body)
File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 458, in sendall
data_sent += self.send(_get_memory(data, data_sent), flags)
File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 435, in send
return sock.send(data, flags)
error: [Errno 32] Broken pipe
<Greenlet at 0x25ceb20: <bound method WSGIServer.handle of <WSGIServer at 0x25bdcb0 fileno=6 address=0.0.0.0:8989>>(<socket at 0x262d4d0 fileno=[Errno 9] Bad file des, ('192.168.4.109', 3325))> failed with error
Above was fixed in new release of library,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Above currently doesn't work. It finds the switch and if I run a different script I can turn it on and off, but I can't seem to get the above to tell me when the switch has been turned on or off! Trying to do something similar to the on_motion EVENT https://github.com/iancmcc/ouimeaux#id5
this is the output i get; so it is subscribing, but when I press the on/off button on the wemo it doesn't register this in the above script, have i missed something? please feel free to edit it!
('Switch found:', 'Lounge room lamp')
('Subscribing to basic events from , (WeMo Switch "Lounge room lamp",))