Skip to content

Instantly share code, notes, and snippets.

@aussieade
Created March 4, 2017 11:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aussieade/7647e2c892bf511510566a7d95f40d95 to your computer and use it in GitHub Desktop.
Save aussieade/7647e2c892bf511510566a7d95f40d95 to your computer and use it in GitHub Desktop.
command line wemo switch control
#!/bin/bash
#
# Filename: wemo
# Author: Ade
# Created: Tue Jun 16 22:40:58 2015 (+1000)
# Last-Updated: Sat Mar 4 22:52:51 2017 (+1100)
# Description: command line wemo switch control
# Version: 0.1
#
# Change Log:
#
help () {
echo "Usage: wemo <name|no.> [status|on|off]"
exit
}
HOST="${0##*/}"
WEMO1='172.16.0.91'
WEMO2='172.16.0.92'
case $HOST in
'wemo')
case $1 in
'1'|'lab')
IP="$WEMO1"
shift
;;
'2'|'ps4')
IP="$WEMO2"
shift
;;
*)
help
;;
esac
;;
'wemo1')
IP="$WEMO1"
;;
'wemo2')
IP="$WEMO2"
;;
*)
help
;;
esac
case $1 in
'status')
(curl -A '' -X POST \
-H 'Content-type: text/xml; charset="utf-8"' \
-H 'SOAPACTION: "urn:Belkin:service:basicevent:1#GetBinaryState"' \
-s http://$IP:49153/upnp/control/basicevent1 \
-d@- <<EOF
<?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"/>
</s:Body>
</s:Envelope>
EOF
) | sed -n 's/<BinaryState>\(.\)<\/BinaryState>/\1/p' | \
sed -e 's/1/On/' -e 's/0/Off/' | tr -cd [:alnum:];echo
;;
'on')
curl -A '' -X POST \
-H 'Content-type: text/xml; charset="utf-8"' \
-H 'SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"' \
-s http://$IP:49153/upnp/control/basicevent1 \
-o /dev/null \
-d@- <<EOF
<?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>
EOF
;;
'off')
curl -A '' -X POST \
-H 'Content-type: text/xml; charset="utf-8"' \
-H 'SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"' \
-s http://$IP:49153/upnp/control/basicevent1 \
-o /dev/null \
-d@- <<EOF
<?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>
EOF
;;
*)
help
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment