HomeGenie Forum

Automation Program Plugins and Wizard Scripting => APP Contributions => Topic started by: nolio on April 13, 2015, 10:53:55 PM

Title: WeMo
Post by: nolio on April 13, 2015, 10:53:55 PM
Hi,
I create a script to manage the WeMo Plug. It permit to switch on/off with the add of a virtual switch. And this virtual switch status is updated when the plug is switch on/off by another way than HomeGenie.
Bye

########
A little update for a correction and an add of a try/catch.
Title: Re: WeMo
Post by: boblablah on September 30, 2015, 05:07:53 PM
The wemo switches have a number of status features now such as usage.  Does this plugin also support querying the meter portion of the device to get stats back as far as power usage through the switch?
Title: Re: WeMo
Post by: nolio on September 30, 2015, 10:16:57 PM
No only switch on, off, and get the status.
Title: Re: WeMo
Post by: roger.wills on October 27, 2015, 03:07:47 PM
Hello again nolio!

I installed and configured your WEMO script on my recently updated HG r498.

Unfortunately it works briefly and then doesn't work and corrupts HG which when restarted seems to have lost all of its configuration.

Furthermore, my HG for android app won't load on the mobile once this has happened.

A simple restore from a previous backup resolves the lost configuration and mobile app issues quickly enough but I am at a loss to know what I am doing wrong regarding the script.

I imported the script. Enabled it and added it as a module to its own group. I configured it with the IP address of the WEMO and that was about it.

Any ideas?

Thanks.
Title: Re: WeMo
Post by: nolio on October 27, 2015, 08:41:25 PM
Hi,
I didn't have the problem (not switch very often).
But i have just try on my side, and HomeGenie seen to crash partially. In my case, a reboot permit HomeGenie to work fine again.
I will try to investigate (when my test environment is ok again).
Bye
Title: Re: WeMo
Post by: nolio on October 29, 2015, 10:21:35 PM
Ok i did some test and it's pretty weird ...
I activate the script and use HomeGenie + switch on/off + do other stuff on HomeGenie => So all work fine.
But when you want to reconnect to HomeGenie nothing appear in the group visualization (but no more too in group and program configuration).

So probably this script break something in HomeGenie, but (for now) i don't know what ...
Gene, perhaps an idea ?
Title: Re: WeMo
Post by: nolio on November 05, 2015, 09:11:27 PM
Hi,
Perhaps a link with the next update in r500 :
Code: [Select]
- Disabled limit of max one opened http connection per program in NetHelperhttps://github.com/genielabs/HomeGenie/blob/master/HISTORY.TXT

I can't really test for now, my test platform doesn't work fine :|
I will try again in r500.
Bye
Title: Re: WeMo
Post by: nolio on November 07, 2015, 09:22:50 PM
Hi,
In r500, that crash again HomeGenie ...
Title: Re: WeMo
Post by: Gene on November 07, 2015, 11:51:30 PM
Hi nolio, what do you mean by "crash"? :)
Is there any log that could help understand? How many http requests are going out through NetHelper?
Log files are stored in the homegenie/logs folder.

Cheers,
g.
Title: Re: WeMo
Post by: nolio on November 08, 2015, 03:34:25 PM
After some request view in log like the following, the reload of the HomeGenie UI don't load the contents of the groups, only the Top bar and the configuration menu.
But the switch off and on work fine ...
Code: [Select]
2015-11-08 15:13:04.6634 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /api/HomeAutomation.WeMo/1/Control.Off/null/ [OPEN]
2015-11-08 15:13:04.6878 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /api/Media.IpCamera/1/Camera.GetPicture/?1446991981921 [OPEN]
2015-11-08 15:13:04.6705 Info HomeAutomation.WeMo       1       Virtual Module  Status.Level    0
2015-11-08 15:13:05.2237 Info HomeAutomation.HomeGenie.Automation       1038    Automation Program      Program.Notification    {"Title":"WeMo","Message":"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=
\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body>\n<u:SetBinaryStateResponse xmlns:u=\"urn:Belkin:service:basicevent:1\">\r\n<BinaryState>0</BinaryState>\r\n</u:SetBinaryStateResponse>\r\n</s:Body> </s:Envelope>"}
2015-11-08 15:13:05.2278 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /api/HomeAutomation.WeMo/1/Control.Off/null/ [CLOSED AFTER 0,564 seconds]
2015-11-08 15:13:05.3029 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /api/Media.IpCamera/1/Camera.GetPicture/?1446991981921 [CLOSED AFTER 0,615 seconds]
2015-11-08 15:13:05.3794 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.HomeGenie.Automation/1038/ [CLOSED AFTER 0,003 seconds]
2015-11-08 15:13:05.3767 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.HomeGenie.Automation/1038/ [OPEN]
...............
2015-11-08 15:14:41.4146 Info HomeAutomation.WeMo       1       Virtual Module  Status.Level    0
2015-11-08 15:14:41.4529 Info HomeAutomation.HomeGenie.Automation       1038    Automation Program      Program.Notification    {"Title":"WeMo","Message":"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=
\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body>\n<u:SetBinaryStateResponse xmlns:u=\"urn:Belkin:service:basicevent:1\">\r\n<BinaryState>0</BinaryState>\r\n</u:SetBinaryStateResponse>\r\n</s:Body> </s:Envelope>"}
2015-11-08 15:14:41.4550 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /api/HomeAutomation.WeMo/1/Control.Off/null/ [CLOSED AFTER 0,046 seconds]
2015-11-08 15:14:41.6987 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.HomeGenie.Automation/1038/ [OPEN]
2015-11-08 15:14:41.7029 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.HomeGenie.Automation/1038/ [CLOSED AFTER 0,004 seconds]
......

But all the HTTP request are open/close normally, except one like this :
Code: [Select]
015-11-08 15:15:11.3716 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /events [ERROR: Write failure]
2015-11-08 15:15:11.3751 Info WebServiceGateway x.x.x.x      HTTP    GET     200 /events [ERROR: Write failure]

Is it normal that the log file isn't write in real time ?
Title: Re: WeMo
Post by: Gene on November 08, 2015, 04:57:45 PM
Yes it's normal that the log file it is not written in real time.
Can you try this command when the write error occurs?

Code: [Select]
sudo netstat -tupn --all | grep mono | grep tcp

sounds like there are too many opened tcp connections (because the request to wemo are not closing/disposing).

g.
Title: Re: WeMo
Post by: nolio on November 08, 2015, 09:31:42 PM

I didn't reproduce this problem again, but i take a look at netstat, so no more than one or 2 connexion at the same time (to the @IP of the plug)  ...

It's a little bit hard to debug, because the script run well but crash partially the HG UI. A restore of backup or a re-install is needed (a reboot doesn't solved the problem).

I have reproduce the problem just by using one time the on (or off) switch function of my script.

I am trying an update of my WeMo plug, but i don't think it will solve the problem.
Title: Re: WeMo
Post by: Gene on November 08, 2015, 10:05:39 PM
try also recompiling the script after restoring it from the backup, because there were changes in the HG API, so the program might need to be aligned/recompiled for using the new API in a correct way.

g.
Title: Re: WeMo
Post by: nolio on November 09, 2015, 09:40:42 PM
Hi Gene,
No more chance ...  :-\

A capture of the web page after a typical bug, only MIG seems to bug but popup still appear (zwave seems to work fine).
Bye
Title: Re: WeMo
Post by: nolio on November 11, 2015, 09:36:59 PM
Hi,
It's weird because i have 2 similar codes :
Code: [Select]
  var request2 = Net.WebService("http://"+WeMo_IPAddress1+":49153/upnp/control/basicevent1")
    .AddHeader("Accept", "")
    .AddHeader("Content-type", "text/xml; charset=\"utf-8\"")
    .AddHeader("SOAPACTION", "\"urn:Belkin:service:basicevent:1#GetBinaryState\"")
    .Post("<?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>");
  var result2 = request2.GetData();
  var virtualMod = Modules.InDomain("HomeAutomation.WeMo").WithAddress("1").Get();
Code: [Select]
Action<string,string>
Switchhhh = (string AddressIP, string ONOFF) => {
if ( ONOFF == "on") {
  ONOFF = "1";
}
if ( ONOFF == "off") {
  ONOFF = "0";
}
  try {
  var request = Net.WebService("http://"+AddressIP+":49153/upnp/control/basicevent1")
      .AddHeader("Accept", "")
      .AddHeader("Content-type", "text/xml; charset=\"utf-8\"")
      .AddHeader("SOAPACTION", "\"urn:Belkin:service:basicevent:1#SetBinaryState\"")
      .Post("<?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>"+ONOFF+"</BinaryState></u:SetBinaryState></s:Body></s:Envelope>");
  var result = request.GetData();

The first one doesn't crash but the second one (very similar to first one) crash HomeGenie ....

Any idea ?
Title: Re: WeMo
Post by: nolio on November 12, 2015, 09:24:55 PM
Hi,
After a lot of debugging, I found the problem !!!!
I just comment the following line (i use only for debugg) :
Code: [Select]
Program.Notify("WeMo", result);And now, it work ! I don't know why but i suppose the data return by the function "GetData()" has change ...

So the new script (only with a line commented ;)).
Bye
Title: Re: WeMo
Post by: roger.wills on November 13, 2015, 11:57:24 AM
Great job nolio, from my limited testing so far this is working!

Strangely though the on or off status seems to be working in reverse. Not a great show stopper but odd non the less. Is that handled in the code?
Title: Re: WeMo
Post by: nolio on November 13, 2015, 09:30:38 PM
Strangely though the on or off status seems to be working in reverse. Not a great show stopper but odd non the less. Is that handled in the code?
Pretty weird because the difference between on and off is only a "1" for "on", and "0" for "off".
So the code send a request with 1 for on and 0 for off (line 17) and variable ONOFF....
And on my side it work fine.
Title: Re: WeMo
Post by: boblablah on June 08, 2016, 12:35:04 AM
Can you outline the method to support multiple wemo switches?
Title: Re: WeMo
Post by: nolio on June 09, 2016, 12:21:14 AM
Probably not the best way, but it should work ... Can you try ?
Title: Re: WeMo
Post by: boblablah on July 27, 2016, 10:55:54 PM
will do tonight!  i have a few switches, so I will replace one or two and see if they work as I expect them to... Now that I see your code and where you added things, it makes sense to me a little more.   If it works, i can make the necessary modifications to enable a few switches and see how well it works.
Title: Re: WeMo
Post by: batman on February 12, 2017, 10:46:47 AM
Did anyone manage to get multiple Wemo's to work?
Title: Re: WeMo
Post by: nolio on February 12, 2017, 11:00:02 PM
Probably not the best way, but it should work ... Can you try ?
Did you try my latest script ? I can't test it because, I only have one wemo switch.