Help with script for controlling Wemo bulbs.
-
I found this script that is supposed to be able to control all Wemo prodcuts including the Wemo bulbs but I can't quite get it to work. I can use LINK LIST and get all connected devices, I can also use GETSTATE and gets the correct state of my bulbs. But I can't toggle or turn any of them on or off. I get "INFO: Connected to 192.168.0.200:49153" -in response and nothing happens.
Does anyone know how to fix this?
(I had to replace all "==" with "=" to get the script to work)#!/bin/sh # # WeMo Control Script # # Original author: rich@netmagi.com # # Modified 7/13/2014 by Donald Burr # email: <dburr@DonaldBurr.com> # web: <http://DonaldBurr.com> # # Modified 05/12/2014 by Jack Lawry # email: <jack@jacklawry.co.uk> # web: <http://www.jacklawry.co.uk> # # Modified 31/05/2015 by Wagner Oliveira # * Fixed Port parameter and added Support for WeMo Link LED Bulbs # email: <wbbo@hotmail.com> # web: <http://guino.home.insightbb.com> # # Usage: wemo IP_ADDRESS[:PORT] ON|OFF|TOGGLE|GETSTATE|GETSIGNALSTRENGTH|GETFRIENDLYNAME # or: wemo IP_ADDRESS[:PORT] LINK [LIST|NAME ON [0-255]|OFF] if [ "$1" = "" ]; then echo "Usage: wemo IP_ADDRESS[:PORT] ON|OFF|TOGGLE|GETSTATE|GETSIGNALSTRENGTH|GETFRIENDLYNAME" echo " or: wemo IP_ADDRESS[:PORT] LINK [LIST|NAME ON [0-255]|OFF]" exit 1 fi IP=$1 CMD=`echo $2 | tr '[a-z]' '[A-Z]'` PORT=0 IPHASPORT=$(echo $IP | grep :) if [ "$IPHASPORT" == "" ]; then for PTEST in 49154 49152 49153 49155 do PORTTEST=$(curl -s -m 3 $IP:$PTEST | grep "404") if [ "$PORTTEST" != "" ]; then PORT=$PTEST break fi done if [ $PORT = 0 ]; then echo "Cannot find a port" exit fi echo "INFO: Connected to" $1":"$PORT else PORT=$(echo $IP | awk -F : '{print $2}') IP=$(echo $IP | awk -F : '{print $1}') echo "Using provided port: $PORT" fi if [ "$CMD" = "GETSTATE" ]; then STATE=`curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#GetBinaryState\"" --data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>1</BinaryState></u:GetBinaryState></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/basicevent1 | grep "<BinaryState" | cut -d">" -f2 | cut -d "<" -f1 | sed 's/0/OFF/g' | sed 's/1/ON/g'` echo $STATE if [ "$STATE" = "OFF" ]; then exit 0 elif [ "$STATE" = "ON" ]; then exit 1 else exit 2 fi elif [ "$CMD" = "TOGGLE" ]; then STATE=`curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#GetBinaryState\"" --data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>1</BinaryState></u:GetBinaryState></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/basicevent1 | grep "<BinaryState" | cut -d">" -f2 | cut -d "<" -f1 | sed 's/0/OFF/g' | sed 's/1/ON/g'` echo $STATE if [ "$STATE" = "OFF" ]; then # echo "ITS OFF - TURNING ON" curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>1</BinaryState></u:SetBinaryState></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/basicevent1 | grep "<BinaryState" | cut -d">" -f2 | cut -d "<" -f1 exit elif [ "$STATE" = "ON" ]; then # echo "ITS ON - TURNING OFF" curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>0</BinaryState></u:SetBinaryState></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/basicevent1 | grep "<BinaryState" | cut -d">" -f2 | cut -d "<" -f1 exit else # echo "UNKNOWN" exit fi elif [ "$CMD" = "ON" ]; then curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>1</BinaryState></u:SetBinaryState></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/basicevent1 | grep "<BinaryState" | cut -d">" -f2 | cut -d "<" -f1 elif [ "$CMD" = "OFF" ]; then curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>0</BinaryState></u:SetBinaryState></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/basicevent1 | grep "<BinaryState" | cut -d">" -f2 | cut -d "<" -f1 elif [ "$CMD" = "GETSIGNALSTRENGTH" ]; then curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#GetSignalStrength\"" --data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetSignalStrength xmlns:u="urn:Belkin:service:basicevent:1"><GetSignalStrength>0</GetSignalStrength></u:GetSignalStrength></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/basicevent1 | grep "<SignalStrength" | cut -d">" -f2 | cut -d "<" -f1 elif [ "$CMD" = "GETFRIENDLYNAME" ]; then curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#GetFriendlyName\"" --data '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetFriendlyName xmlns:u="urn:Belkin:service:basicevent:1"><FriendlyName></FriendlyName></u:GetFriendlyName></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/basicevent1 | grep "<FriendlyName" | cut -d">" -f2 | cut -d "<" -f1 elif [ "$CMD" = "LINK" ]; then # Get Unique Device Number and List of Devices/IDs UDN=$(wget -qO- http://$IP:$PORT/setup.xml | grep UDN | awk -F'>|<' '{print $3}') DEVS=$(curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:bridge:1#GetEndDevices\"" --data '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetEndDevices xmlns:u="urn:Belkin:service:bridge:1"><ReqListType>SCAN_LIST</ReqListType><DevUDN>'$UDN'</DevUDN></u:GetEndDevices></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/bridge1 | awk '{ gsub(">", "\n"); print }') if [ "$3" == "LIST" ]; then echo "$DEVS" | grep "Name" | awk -F "&" '{ print $1 }' | grep -v -e "^$" else GROUPNAMES=$(echo "$DEVS" | grep -iE '(/GroupID|/GroupName)' | awk -F "&" '{print $1}') BULBNAMES=$(echo "$DEVS" | grep -iE '(/FriendlyName|/DeviceID)' | awk -F "&" '{print $1}') ID=$(echo "$DEVS" | grep -iE '(/GroupID|/GroupName|/FriendlyName|/DeviceID)' | awk -F "&" '{print $1}' | awk 'NR%2{a=$0;next}{print $0 "@"a;}' | grep "$3" | awk -F @ '{print $2}') if [ "$ID" == "" ]; then echo "$3 was not found." exit 254 fi ISGROUP=$(echo "$GROUPNAMES" | grep "$ID") if [ "$ISGROUP" != "" ]; then ISGROUP="YES" else ISGROUP="NO" fi if [ "$4" == "ON" ]; then LEVEL=255 if [ "$5" != "" ]; then LEVEL=$5 fi # Send ON command curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:bridge:1#SetDeviceStatus\"" --data '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetDeviceStatus xmlns:u="urn:Belkin:service:bridge:1"><DeviceStatusList><?xml version="1.0" encoding="UTF-8"?><DeviceStatus><DeviceID>'$ID'</DeviceID><CapabilityID>10008</CapabilityID><CapabilityValue>'$LEVEL':0</CapabilityValue><IsGroupAction>'$ISGROUP'</IsGroupAction></DeviceStatus></DeviceStatusList></u:SetDeviceStatus></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/bridge1 > /dev/null UPDATESTATUS=1 elif [ "$4" == "OFF" ]; then # Send OFF Command curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:bridge:1#SetDeviceStatus\"" --data '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetDeviceStatus xmlns:u="urn:Belkin:service:bridge:1"><DeviceStatusList><?xml version="1.0" encoding="UTF-8"?><DeviceStatus><DeviceID>'$ID'</DeviceID><CapabilityID>10008</CapabilityID><CapabilityValue>0:0</CapabilityValue><IsGroupAction>'$ISGROUP'</IsGroupAction></DeviceStatus></DeviceStatusList></u:SetDeviceStatus></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/bridge1 > /dev/null UPDATESTATUS=1 elif [ "$4" == "TOGGLE" ]; then # Determine if device IS ON ISON=$(echo "$DEVS" | grep -iE '(/GroupCapabilityValues|/GroupName|/CurrentState|/FriendlyName)' | awk -F "&" '{print $1}' | awk 'NR%2{a=$0;next}{print a","$0;}' | grep "$3" | awk -F "," '{print $2}') LEVEL=$(echo "$DEVS" | grep -iE '(/GroupCapabilityValues|/GroupName|/CurrentState|/FriendlyName)' | awk -F "&" '{print $1}' | awk 'NR%2{a=$0;next}{print a","$0;}' | grep "$3" | awk -F "," '{print $3}') # echo "ISON=$ISON LEVEL=$LEVEL" if [ "$ISON" == "1" ]; then LEVEL="0" fi # Send Command to TOGGLE curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:bridge:1#SetDeviceStatus\"" --data '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetDeviceStatus xmlns:u="urn:Belkin:service:bridge:1"><DeviceStatusList><?xml version="1.0" encoding="UTF-8"?><DeviceStatus><DeviceID>'$ID'</DeviceID><CapabilityID>10008</CapabilityID><CapabilityValue>'$LEVEL':0</CapabilityValue><IsGroupAction>'$ISGROUP'</IsGroupAction></DeviceStatus></DeviceStatusList></u:SetDeviceStatus></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/bridge1 > /dev/null UPDATESTATUS=1 elif [ "$4" == "GETSTATE" ]; then echo "$DEVS" | grep -iE '(/GroupCapabilityValues|/GroupName|/CurrentState|/FriendlyName)' | awk -F "&" '{print $1}' | awk 'NR%2{a=$0;next}{print a","$0;}' | grep "$3" | awk -F "," '{print "ON: "$2"\nLevel: "$3}' else SHOWUSAGE=1 fi fi else SHOWUSAGE=1 fi # When you switch LEDs ON/OFF you must request the device status so it will correctly report it later when you use GETSTATE if [ "$UPDATESTATUS" == "1" ]; then if [ "$ISGROUP" == "YES" ]; then GRPIDS=$(echo "$DEVS" | grep -iE '(/GroupID)' | awk -F "&" '{print $1}' | awk '{print}' ORS=',' | awk '{print substr($0, 0, length($0)-1)}') DEVIDS=$(echo "$DEVS" | grep -iE '(/DeviceID)' | awk -F "&" '{print $1}' | awk '{print}' ORS=',' | awk '{print substr($0, 0, length($0)-1)}') # echo "GRPIDS=$GRPIDS ** DEVIDS=$DEVIDS" curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:bridge:1#GetDeviceStatus\"" --data '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetDeviceStatus xmlns:u="urn:Belkin:service:bridge:1"><DeviceIDs>'$GRPIDS'</DeviceIDs></u:GetDeviceStatus></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/bridge1 > /dev/null curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:bridge:1#GetDeviceStatus\"" --data '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetDeviceStatus xmlns:u="urn:Belkin:service:bridge:1"><DeviceIDs>'$DEVIDS'</DeviceIDs></u:GetDeviceStatus></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/bridge1 > /dev/null else curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:bridge:1#GetDeviceStatus\"" --data '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetDeviceStatus xmlns:u="urn:Belkin:service:bridge:1"><DeviceIDs>'$ID'</DeviceIDs></u:GetDeviceStatus></s:Body></s:Envelope>' -s http://$IP:$PORT/upnp/control/bridge1 > /dev/null fi fi if [ "$SHOWUSAGE" == "1" ]; then echo "COMMAND NOT RECOGNIZED" echo "" echo "Usage: wemo IP_ADDRESS[:PORT] ON|OFF|TOGGLE|GETSTATE|GETSIGNALSTRENGTH|GETFRIENDLYNAME" echo " or: wemo IP_ADDRESS[:PORT] LINK [LIST|NAME ON [0-255]|OFF|TOGGLE|GETSTATE]" exit 255 fi``` -
The person who wrote the script on another forum replied earlier to someone else who had problems:
You should try to download it from this link: http://guino.home.insightbb.com/wemo_control.sh The command line format should be: ./wemo_control IP_ADDRESS[:PORT] LINK [LIST|NAME ON [0-255]|OFF] But even with your incorrect parameters the errors you're getting suggest some sort of file formatting issue. Here is what it should look like: root@DD-WRT:/jffs/cgi# ./wemo_control.sh 10.10.10.6 LINK LIST INFO: Connected to 10.10.10.6:49154 Master Lightbulb 1 Lightbulb 3 Lightbulb 4 Lightbulb 2 root@DD-WRT:/jffs/cgi# ./wemo_control.sh 10.10.10.6 LINK Master GETSTATE INFO: Connected to 10.10.10.6:49154 ON: 0 Level: 1:0 Other than that maybe some sort of difference in the OS -- I tested the script on Mageia 4 and on my DD-WRT router (3.10) without any issues. Be sure to make the script executable (chmod 777 wemo_control.sh) and execute it with ./wemo_control <params> Last resort would be trying to replacing any == in an "if" line (all lines you listed with an error) for just = (a quick search online reveals that some sh versions don't like the ==) Let me know if that works... -
If I run the script unmodified I get:
pi@raspberrypi ~ $ ./wemo_control.sh 192.168.0.200 LINK LIST ./wemo_control.sh: 35: [: unexpected operator Using provided port: ./wemo_control.sh: 106: [: LIST: unexpected operator ./wemo_control.sh: 112: [: unexpected operator ./wemo_control.sh: 122: [: unexpected operator ./wemo_control.sh: 130: [: unexpected operator ./wemo_control.sh: 134: [: unexpected operator ./wemo_control.sh: 145: [: unexpected operator ./wemo_control.sh: 156: [: unexpected operator ./wemo_control.sh: 168: [: 1: unexpected operator -
Hi,
From one Wemo switch user to another, the best luck I had to control them from shell was using Ouimeaux. I would try that and see if that works for you over the .sh scripts.
@drock1985
I have tried Ouimeaux but it was to slow for my liking. I have placed an arduino behind the a wallswitch that controls a wemo led that is alway powered. When I last tried Ouimeaux the reactiontime was around 5 seconds and my kids and wife would have flicked the switch 5-6 times before any reactions was seen.I then moved over to installing wemo manager + server on an android witch makes the reaction time go down to about 1-2 sec. But I must say that I would want the reaction time to be under 1 sec.
-
I'm not too sure you will get that reaction time from anything but the Wemo app itself, or the mechanical switch on the Wemo. The problem I found out with the Wemo is, it will randomize what port it connects to in a certain range. I can't remember the exact range (maybe 49152-49156?), but I think it's stated in the .sh script. Therefore, the script or whatever program that is doing the switching needs to first find the proper IP/Port, then actually run the command.
The one option you may have is setting a static IP to each Wemo switch, then sending it more direct.
To be all honest, this is why I switched from Wemo over to MySensors and the Relay sketch. Works much better than the Wemo's do, and haven't had a chance to buy and test any Zigbee wall switches yet.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login