Skip to content

Instantly share code, notes, and snippets.

@saluber
Last active March 20, 2021 20:49
Show Gist options
  • Save saluber/b4c152fe3a66ac15234d993f64420b54 to your computer and use it in GitHub Desktop.
Save saluber/b4c152fe3a66ac15234d993f64420b54 to your computer and use it in GitHub Desktop.
WeMo Smart Plug Get/Set State
{
"info": {
"_postman_id": "1ac1a28c-ebb9-41a7-a19e-d2d51c1c8bc9",
"name": "wemo",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "get_smartplug_state",
"protocolProfileBehavior": {
"disabledSystemHeaders": {
"content-type": true,
"host": true,
"user-agent": true,
"accept-encoding": true,
"connection": true,
"accept": true
}
},
"request": {
"method": "POST",
"header": [
{
"key": "CONTENT-TYPE",
"value": "text/xml; charset=\"utf-8\"",
"type": "text"
},
{
"key": "SOAPACTION",
"value": "\"urn:Belkin:service:basicevent:1#GetBinaryState\"",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n <s:Body>\n <u:GetBinaryState xmlns:u=\"urn:Belkin:service:basicevent:1\">\n </u:GetBinaryState>\n </s:Body>\n</s:Envelope>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "http://{{wemoIPAddr}}:49153/upnp/control/basicevent1",
"protocol": "http",
"host": [
"{{wemoIPAddr}}"
],
"port": "49153",
"path": [
"upnp",
"control",
"basicevent1"
]
},
"description": "Note that BinaryState in the response body indicates whether the wemo smart plug is on (`1`) or off (`0`)."
},
"response": []
},
{
"name": "set_smartplug_onoff_state",
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "text/xml",
"type": "text"
},
{
"key": "SOAPACTION",
"value": "\"urn:Belkin:service:basicevent:1#SetBinaryState\"",
"type": "text"
},
{
"key": "Content-Length",
"value": "302",
"type": "text",
"disabled": true
}
],
"body": {
"mode": "raw",
"raw": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n <s:Body>\n <u:SetBinaryState xmlns:u=\"urn:Belkin:service:basicevent:1\">\n <BinaryState>1</BinaryState>\n </u:SetBinaryState>\n </s:Body>\n</s:Envelope>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "http://{{wemoIPAddr}}:49153/upnp/control/basicevent1",
"protocol": "http",
"host": [
"{{wemoIPAddr}}"
],
"port": "49153",
"path": [
"upnp",
"control",
"basicevent1"
]
},
"description": "Change BinaryState in Body of request to turn on/off by setting BinaryState value to either `1` (on) or `0` (off)."
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "wemoIPAddr",
"value": "192.168.0.190"
}
]
}

WeMo Smart Plug Commanding

Overview/Setup

When trying to make a "dumb" light not only remote controllable smart, but also custom controllable without being tethered to some commerical app (e.g., WeMo, Google Home Assistant, etc.), I determine some scripts for pinging, querying the on/off state, and setting the on/off state of a WeMo smart plug on the same local network. Note that the IP address of the WeMo plug can be found by logging into your router and ideally should be configured to have a dedicated static IP address.

Pre-reqs

  • Wemo device setup through WeMo and connected to same wireless network the script will be run from
  • IP address of the device ** In my case (and in case of script below) IP address is: 192.168.0.190
  • Device connected to the same wireless network that can run the get_onoff_status and set_on_status / set_off_status scripts:
  • curl if you're going to be using option 1
  • postman if you're going to be using option 2

Using

Option 1: Curl

Run commands from terminal

get_onoff_status

Note: BinaryState = 0 means off and BinaryState = 1 means on

curl -H 'Content-type:text/xml; charset=utf-8' -H 'SOAPACTION:"urn:Belkin:service:basicevent:1#GetBinaryState"' -d '<?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"></u:GetBinaryState></s:Body></s:Envelope>' 'http://192.168.0.190:49153/upnp/control/basicevent1'

set_onoff_state

Note: BinaryState = 0 means turn off and BinaryState = 1 means turn on

Turn on: curl -H 'Content-type:text/xml; charset=utf-8' -H 'SOAPACTION:"urn:Belkin:service:basicevent:1#SetBinaryState"' -d '<?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>' 'http://192.168.0.190:49153/upnp/control/basicevent1'

Turn off: curl -H 'Content-type:text/xml; charset=utf-8' -H 'SOAPACTION:"urn:Belkin:service:basicevent:1#SetBinaryState"' -d '<?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>' 'http://192.168.0.190:49153/upnp/control/basicevent1'

Option 2: Postman

See attached exported postman collection. Remember to set wemo ip address in variables section of postman collection.

See wemo.postman_collection.json

Extending

See wsdl file of wemo smart plug web service for other valid operations that can be performed on this smart plug device (similar to what is done above for getting/setting the binarystate).

See WeMoWsdlBasicService.wsdl or wsdl link in references section.

Chrome Browser Plugin

See cute chrome browser plugin we made based on this work: Wemo SmartPlug Controller Chromecast Plugin

References

WeMo client example repo

WeMo wsdl

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:u="urn:Belkin:service:basicevent:1">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Belkin:service:basicevent:1">
<xsd:element name="SetBinaryState">
<xsd:complexType>
<xsd:all>
<xsd:element name="BinaryState" type="xsd:string" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="SetBinaryStateResponse">
<xsd:complexType>
<xsd:all>
<xsd:element name="BinaryState" type="xsd:string" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetBinaryState">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetBinaryStateResponse">
<xsd:complexType>
<xsd:all>
<xsd:element name="BinaryState" type="xsd:string" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetFriendlyName">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetFriendlyNameResponse">
<xsd:complexType>
<xsd:all>
<xsd:element name="FriendlyName" type="xsd:string" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetHomeId">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetHomeIdResponse">
<xsd:complexType>
<xsd:all>
<xsd:element name="HomeId" type="xsd:string" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetSignalStrength">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetSignalStrengthResponse">
<xsd:complexType>
<xsd:all>
<xsd:element name="SignalStrength" type="xsd:string" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetLogFileURL">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetLogFileURLResponse">
<xsd:complexType>
<xsd:all>
<xsd:element name="LOGURL" type="xsd:string" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetIconURL">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetIconURLResponse">
<xsd:complexType>
<xsd:all>
<xsd:element name="URL" type="xsd:string" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="ChangeFriendlyName">
<xsd:complexType>
<xsd:all>
<xsd:element name="FriendlyName" type="xsd:string" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="ChangeFriendlyNameResponse">
<xsd:complexType>
<xsd:sequence />
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="SetBinaryStateInputMessage">
<wsdl:part name="SetBinaryStateInputPart" element="u:SetBinaryState"/>
</wsdl:message>
<wsdl:message name="SetBinaryStateOutputMessage">
<wsdl:part name="SetBinaryStateOutputPart" element="u:SetBinaryStateResponse"/>
</wsdl:message>
<wsdl:message name="GetBinaryStateInputMessage">
<wsdl:part name="GetBinaryStateInputPart" element="u:GetBinaryState"/>
</wsdl:message>
<wsdl:message name="GetBinaryStateOutputMessage">
<wsdl:part name="GetBinaryStateOutputPart" element="u:GetBinaryStateResponse"/>
</wsdl:message>
<wsdl:message name="GetFriendlyNameInputMessage">
<wsdl:part name="GetFriendlyNameInputPart" element="u:GetFriendlyName"/>
</wsdl:message>
<wsdl:message name="GetFriendlyNameOutputMessage">
<wsdl:part name="GetFriendlyNameOutputPart" element="u:GetFriendlyNameResponse"/>
</wsdl:message>
<wsdl:message name="GetHomeIdInputMessage">
<wsdl:part name="GetHomeIdInputPart" element="u:GetHomeId"/>
</wsdl:message>
<wsdl:message name="GetHomeIdOutputMessage">
<wsdl:part name="GetHomeIdOutputPart" element="u:GetHomeIdResponse"/>
</wsdl:message>
<wsdl:message name="GetSignalStrengthInputMessage">
<wsdl:part name="GetSignalStrengthInputPart" element="u:GetSignalStrength"/>
</wsdl:message>
<wsdl:message name="GetSignalStrengthOutputMessage">
<wsdl:part name="GetSignalStrengthOutputPart" element="u:GetSignalStrengthResponse"/>
</wsdl:message>
<wsdl:message name="GetLogFileURLInputMessage">
<wsdl:part name="GetLogFileURLInputPart" element="u:GetLogFileURL"/>
</wsdl:message>
<wsdl:message name="GetLogFileURLOutputMessage">
<wsdl:part name="GetLogFileURLOutputPart" element="u:GetLogFileURLResponse"/>
</wsdl:message>
<wsdl:message name="GetIconURLInputMessage">
<wsdl:part name="GetIconURLInputPart" element="u:GetIconURL"/>
</wsdl:message>
<wsdl:message name="GetIconURLOutputMessage">
<wsdl:part name="GetIconURLOutputPart" element="u:GetIconURLResponse"/>
</wsdl:message>
<wsdl:message name="ChangeFriendlyNameInputMessage">
<wsdl:part name="ChangeFriendlyNameInputPart" element="u:ChangeFriendlyName"/>
</wsdl:message>
<wsdl:message name="ChangeFriendlyNameOutputMessage">
<wsdl:part name="ChangeFriendlyNameOutputPart" element="u:ChangeFriendlyNameResponse"/>
</wsdl:message>
<wsdl:portType name="BasicServicePortType">
<wsdl:operation name="SetBinaryState">
<wsdl:input message="SetBinaryStateInputMessage"/>
<wsdl:output message="SetBinaryStateOutputMessage"/>
</wsdl:operation>
<wsdl:operation name="GetBinaryState">
<wsdl:input message="GetBinaryStateInputMessage"/>
<wsdl:output message="GetBinaryStateOutputMessage"/>
</wsdl:operation>
<wsdl:operation name="GetFriendlyName">
<wsdl:input message="GetFriendlyNameInputMessage"/>
<wsdl:output message="GetFriendlyNameOutputMessage"/>
</wsdl:operation>
<wsdl:operation name="GetHomeId">
<wsdl:input message="GetHomeIdInputMessage"/>
<wsdl:output message="GetHomeIdOutputMessage"/>
</wsdl:operation>
<wsdl:operation name="GetSignalStrength">
<wsdl:input message="GetSignalStrengthInputMessage"/>
<wsdl:output message="GetSignalStrengthOutputMessage"/>
</wsdl:operation>
<wsdl:operation name="GetLogFileURL">
<wsdl:input message="GetLogFileURLInputMessage"/>
<wsdl:output message="GetLogFileURLOutputMessage"/>
</wsdl:operation>
<wsdl:operation name="GetIconURL">
<wsdl:input message="GetIconURLInputMessage"/>
<wsdl:output message="GetIconURLOutputMessage"/>
</wsdl:operation>
<wsdl:operation name="ChangeFriendlyName">
<wsdl:input message="ChangeFriendlyNameInputMessage"/>
<wsdl:output message="ChangeFriendlyNameOutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicServiceBinding" type="BasicServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="SetBinaryState">
<soap:operation soapAction="urn:Belkin:service:basicevent:1#SetBinaryState"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetBinaryState">
<soap:operation soapAction="urn:Belkin:service:basicevent:1#GetBinaryState"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetFriendlyName">
<soap:operation soapAction="urn:Belkin:service:basicevent:1#GetFriendlyName"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetHomeId">
<soap:operation soapAction="urn:Belkin:service:basicevent:1#GetHomeId"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetSignalStrength">
<soap:operation soapAction="urn:Belkin:service:basicevent:1#GetSignalStrength"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetLogFileURL">
<soap:operation soapAction="urn:Belkin:service:basicevent:1#GetLogFileURL"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetIconURL">
<soap:operation soapAction="urn:Belkin:service:basicevent:1#GetIconURL"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="ChangeFriendlyName">
<soap:operation soapAction="urn:Belkin:service:basicevent:1#ChangeFriendlyName"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BasicService">
<wsdl:port name="BasicServicePort" binding="BasicServiceBinding">
<soap:address location="http://localhost:49153/upnp/control/basicevent1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
@saluber
Copy link
Author

saluber commented Mar 20, 2021

Screen Shot 2021-03-20 at 14 18 38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment