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.)

anonymous2
  • 4,902
  • 3
  • 22
  • 49
bob
  • 183
  • 1
  • 7

2 Answers2

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);
  }
}
user3772748
  • 76
  • 1
  • 1
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.

Helmar
  • 8,450
  • 6
  • 36
  • 84