7

I am using an ESP8266 to emulate a WeMo device with wemos and fauxmoESP arduino code found on the internet. Now that I understand the basic interaction of on and off commands, I'd like to add a status response for the state of some pins on the device. It appears that "turn on" and "turn off" are basic Alexa skills and those work. But there is no "status" or "state" verbal command.

I've found places in the code that handle the eventservice XML for example:<binarystate>1</binarystate> to turn it on, but I cannot find any documentation on getting status or <getdevicestate>. Example of use: If I can't see a light on somewhere, I'd like to query the device to see if it is on or off.

Since the device emulates a belkin on/off switch, the setup.xml packet only has:

<service>
    <serviceType>urn:Belkin:service:basicevent:1</serviceType>
    <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>
    <controlURL>/upnp/control/basicevent1</controlURL>
    <eventSubURL>/upnp/event/basicevent1</eventSubURL>
    <SCPDURL>/eventservice.xml</SCPDURL>
</service>

and the basic event is not enough to get status or further capability.

This is all done without writing an AWS skill and is handled with direct dialog on the local LAN between the ESP8266 webserver and fauxmoESP to and from the Echo Dot. I can see the packets by sniffing the LAN (wireless)and believe it would be straightforward to add more capabilities if I could find the documentation on the control messaging XML packets.

Where can I find these control XML dialog templates and hopefully examples of how to use them? I am getting the sense that this can only be accomplished by using an AWS skill but it seems so unnecessary. Can someone give me some guidance here?

Also, what is the utterance for Alexa to check status of a device? It could be that there is no built in utterance for this and I will need to write an AWS skill (which I don't want to do if possible.)

1
  • Did you intend to have the speech marks in the XML? I initially edited them out, but you put them back—am I missing something?
    – Aurora0001
    Commented Jun 6, 2017 at 19:58

2 Answers 2

6

Perhaps the software featureset has changed but I've found that the following works. This is from my DIY code for nodemcu/D1 mini ESP8266 module using esp8266 webserver listening for local UDP broadcasts. I noticed in the Alexa calls to /upnp.control/basicevent1 that the requests were changing subtly. It all boils down to the same event, but the xml of the request has either <SetBinaryState> or <GetBinaryState>

So long as you're holding state in your sketch, something like this will work...

 void Switch::handleUpnpControl(){

  Serial.println("########## Responding to  /upnp/control/basicevent1 ... ##########");      

  String request = server->arg(0);      
  Serial.print("request:");
  Serial.println(request);

  if (request.indexOf("<u:SetBinaryState") > 0) {
    Serial.print("Got setState update...");
    if(request.indexOf("<BinaryState>1</BinaryState>") > 0) {
        Serial.println("Got Turn on request");
    state = 1;
    onCallback();
    }
    if(request.indexOf("<BinaryState>0</BinaryState>") > 0) {
        Serial.println("Got Turn off request");
        state = 0;
        offCallback();
    }
    server->send(200, "text/plain", "");
  }

  if (request.indexOf("<u:GetBinaryState") > 0) {
    Serial.println("Got inquiry for current state:");
     String statusResponse = 
     "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"     s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
        "<s:Body>"
          "<u:GetBinaryStateResponse xmlns:u=\"urn:Belkin:service:basicevent:1\">"
            "<BinaryState>" + String(state) + "</BinaryState>"
          "</u:GetBinaryStateResponse>"
        "</s:Body>"
      "</s:Envelope>\r\n"
      "\r\n";
      Serial.print("Sending status response: ");
      Serial.println(statusResponse);
      server->send(200, "text/plain", statusResponse);
  }
}
1
  • This indeed worked - Thank you! I had originally used Belkin XML for getBinaryState but failed to check if the request was a get or set. I didn't try my original code after testing for getBinaryState after finding that this code worked. Now I just need to figure out how to speak the command instead of using the Alexa App. Thanks again.
    – bob
    Commented Oct 25, 2018 at 0:53
4

Currently the state of a light is not part of the Smart Home Skill API that Wemo uses for the smart home devices. There are discovery, control and query directives according to their reference.

Query connected devices for their current state Alexa.ConnectedHome.Query

  • GetLockStateRequest
  • GetLockStateResponse
  • GetTargetTemperatureRequest
  • GetTargetTemperatureResponse
  • GetTemperatureReadingRequest
  • GetTemperatureReadingResponse

Unfortunately none of those helps you with your light. Maybe you can fake being a door lock. But it's very unlikely that will work with the Wemo skill.

Thus, currently, it looks like you'll need to write your own skill to get the state of the light.

1
  • 1
    Thanks Helmar. Since the ESP8266 essentially controls pins to relays, it would be nice to get the state of the pins so I can use them as inputs. So it would be nice to see what the actual request to the "lock" looks like as it comes over the local LAN/WiFi so I could respond with the XML packet containing the state. I'm actually looking for that low-level XML packet contents. Obviously Alexa won't know that it has the "lock" skill so I'm trying to spoof it without AWS Skill from the cloud.
    – bob
    Commented Jun 6, 2017 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.