> Back to the Wemo concept, ... it should be doable if someone who knows Python has a computer on the same wifi network.
OK, finally did it. This is a ElementaryOS linux box (debian/ubuntu flavor, the best distro I've found to date with 4K display), a test with a chest freezer. (I no longer can conveniently slow-charge my Zero, since somebody decided to give me a parking ticket for parking on the sidewalk overnight to charge, I pretty much only do the attended rapid-charge.)
Should also work with Raspberry Pi if you get it on the same Wifi network as the WeMo Insight
Here's how I installed:
$ sudo apt-get install python-setuptools python-dev virtualenvwrapper python-pip
$ virtualenv ouimeaux
$ cd ouimeaux/
$ pip install ouimeaux
Obviously, if you use Windows or Mac, you'll need to install it the way your OS requires. Also, you'll need to be sure any firewall rules allow WeMo packets through.
Here's a program that measures power up to a peak value, and then stops charging when power is reduced by a particular percentage.
$ cat read_wemo_insight_power_and_turn_off.py
#!/usr/bin/python2.7
import ouimeaux.environment
import time
import os
INTERVAL_SEC=3
MIN_REDUCTION_PCT_TURN_OFF= 50
def on_switch(switch):
print "Switch found!", switch.name
def on_motion(motion):
print "Motion found!", motion.name
env = ouimeaux.environment.Environment(on_switch, on_motion)
env.start()
env.discover(seconds=3)
switches_name_power= dict()
for name in env.list_switches():
s= env.get_switch(name)
print name, s.current_power, "milliwatts"
switches_name_power[name]= s.current_power
if len(switches_name_power) == 0:
print "no switches detected"
os.exit(1)
time.sleep(INTERVAL_SEC)
am_done= 0
while not am_done:
for name in env.list_switches():
s= env.get_switch(name)
print name, s.current_power, "milliwatts"
prior_power_mw= switches_name_power[name]
if s.current_power < prior_power_mw:
reduction_mw= prior_power_mw-s.current_power
reduction_pct=(reduction_mw*100/prior_power_mw)
print "%s: reduction=%d mw %d pct" % (name,reduction_mw,reduction_pct)
if reduction_pct < MIN_REDUCTION_PCT_TURN_OFF:
print "%s: reduction too small" % name
else:
print "%s: turn off" % name
s.off()
am_done=1
else:
print "%s: %dmw no reduction" % (name,s.current_power)
# no reduction
switches_name_power[name]= s.current_power
if am_done: break
time.sleep(INTERVAL_SEC)
Here's the output of a run of that program. First there's no load I plug in a chest freezer and turn the switch on by hand:
$ python read_wemo_insight_power_and_turn_off.py
Switch found! WeMo Insight
WeMo Insight 0 milliwatts
WeMo Insight 0 milliwatts
WeMo Insight: 0mw no reduction
WeMo Insight 0 milliwatts
WeMo Insight: 0mw no reduction
WeMo Insight 0 milliwatts
WeMo Insight: 0mw no reduction
WeMo Insight 212785 milliwatts
WeMo Insight: 212785mw no reduction
WeMo Insight 158665 milliwatts
WeMo Insight: reduction=54120 mw 25 pct
WeMo Insight: reduction too small
WeMo Insight 74445 milliwatts
WeMo Insight: reduction=138340 mw 65 pct
WeMo Insight: turn off
$
Obviously, if you have more than one Wemo Insight, you'd have to identify the one in question, match it up, trivial exercises left to the reader : - )