Code Monkey home page Code Monkey logo

wemosetup's Introduction

wemosetup

A simple Python script to set up WeMo devices supporting:

  • connecting to a home Wi-Fi network (via calling a SOAP method ConnectHomeNetwork)
  • showing a list of discovered devices (via SSDP)
  • adding new bulbs to WeMo bridges, showing state of paired bulbs, removing bulbs
  • toggling state of WeMo switch and WeMo bridge devices
  • connecting to IFTTT
  • working on Windows too

I have tested it with WeMo Insight and WeMo Bridge.

Examples

# discover devices (with their IPs and ports)
python3 wemosetup.py discover

# connect to home wi-fi
python3 wemosetup.py connecthomenetwork --ip 10.22.22.1 --port 49152 --ssid <mywifinetworkname> --password <mywifinetworkpassword>

# add bulbs
python3 wemosetup.py addenddevices --ip 10.22.22.1 --port 49152

# list bulbs
python3 wemosetup.py getenddevices --ip 10.22.22.1 --port 49152

# remove bulbs
python3 wemosetup.py removeenddevices --ip 10.22.22.1 --port 49152

# reset bulbs (remove all bulbs and add all bulbs in one shot)
python3 wemosetup.py resetenddevices --ip 10.22.22.1 --port 49152

# toggle bubls
python3 wemosetup.py toggle --ip 10.22.22.1 --port 49152

# pair with IFTTT (will ask to follow a web link and then execute JavaScript from DevTools console), imei may be an arbitrary number 
python3 wemosetup.py ifttt --ip 10.22.22.1 --port 49152 --imei 123456789

Resetting WeMo

WeMo devices are not very stable and may require resets of bridges, switches and bulbs.

Dependencies

  • Python 3
  • openssl (or openssl.exe) binary discoverable in system $PATH

Credits and references

  1. https://web.archive.org/web/20130429034218/http://www.mgalisa.com/?p=91
  2. https://github.com/issackelly/wemo
  3. https://gist.github.com/hardillb/ffa9b458109fb8af7d0f#file-wemo-control-js
  4. https://github.com/pavoni/pywemo/blob/master/pywemo/ouimeaux_device/bridge.py
  5. https://www.scip.ch/en/?labs.20160218

wemosetup's People

Contributors

spectre5 avatar vadimkantorov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wemosetup's Issues

error linux en raspberry pi

$ python3 wemosetup.py discover

File "wemosetup.py", line 200
['''NO{}{}{}'''.format(bulb_device_id, 10006, new_binary_state) for bulb_device_id in bulbs.keys()]
^
SyntaxError: invalid syntax

new changes for python3 throwing errors in linux

pagusph@pagusph-MBP:/Downloads/wemosetup$ python3 wemosetup.py discover
File "wemosetup.py", line 145
print(f'Device failed to connect to the network: ({connect_status}, {network_status}). Try again.') if network_status not in ['1', '3'] or close_status != 'success' else f'Device {device} connected to network "{ssid}"')
^
SyntaxError: unmatched ')'
pagusph@pagusph-MBP:
/Downloads/wemosetup$ which openssl
/usr/bin/openssl
pagusph@pagusph-MBP:~/Downloads/wemosetup$

encode hex no longer working in python3

Looks like the encode hex command in the encrypt_wifi_password is failing in python3 when trying to add a device. I tried importing codecs and changing it to
codecs.encode(salt, 'hex')
and
codecs.encode(iv,'hex')

but it still seems to fail with it complaining about it being a string and not byte coded
``
Discovered 3 networks with SSID "wifissid", using the first available..."
Traceback (most recent call last):
File "/usr/lib/python3.8/encodings/hex_codec.py", line 15, in hex_encode
return (binascii.b2a_hex(input), len(input))
TypeError: a bytes-like object is required, not 'str'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "wemosetup.py", line 258, in
cmd(**args)
File "wemosetup.py", line 137, in connecthomenetwork
'password' : device.encrypt_wifi_password(password, meta_array),
File "wemosetup.py", line 90, in encrypt_wifi_password
stdout, stderr = subprocess.Popen(['openssl', 'enc', '-aes-128-cbc', '-md', 'md5', '-S', codecs.encode(salt, 'hex'), '-iv', codecs.encode(iv,'hex'), '-pass', 'pass:' + keydata], stdin = subprocess.PIPE, stdout = subprocess.PIPE).communicate(password)
TypeError: encoding with 'hex' codec failed (TypeError: a bytes-like object is required, not 'str')
``

I can poke through python a bit but not extremely versed in it so not sure what to try next.

Crashes on setup, can't find file. openssl missing on windows?

Do I need to install openssl on windows 10?

C:\Users\robert.bruce\Downloads\wemosetup-master\wemosetup-master>wemosetup.py discover

Discovery of WeMo devices

Discovered:

  • WeMo Switch (10.22.22.1:49152)

C:\Users\robert.bruce\Downloads\wemosetup-master\wemosetup-master>wemosetup.py connecthomenetwork --ip 10.22.22.1 --port 49152 --ssid prettyflyforawifi --password notmypassword
Traceback (most recent call last):
File "C:\Users\robert.bruce\Downloads\wemosetup-master\wemosetup-master\wemosetup.py", line 256, in
cmd(**args)
File "C:\Users\robert.bruce\Downloads\wemosetup-master\wemosetup-master\wemosetup.py", line 135, in connecthomenetwork
'password' : device.encrypt_wifi_password(password, meta_array),
File "C:\Users\robert.bruce\Downloads\wemosetup-master\wemosetup-master\wemosetup.py", line 88, in encrypt_wifi_password
stdout, stderr = subprocess.Popen(['openssl', 'enc', '-aes-128-cbc', '-md', 'md5', '-S', salt.encode('hex'), '-iv', iv.encode('hex'), '-pass', 'pass:' + keydata], stdin = subprocess.PIPE, stdout = subprocess.PIPE).communicate(password)
File "C:\Python27\lib\subprocess.py", line 394, in init
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 644, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.