HomeGenie Forum
Automation Program Plugins and Wizard Scripting => APP Contributions => Topic started 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.
-
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?
-
No only switch on, off, and get the status.
-
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.
-
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
-
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 ?
-
Hi,
Perhaps a link with the next update in r500 :
- Disabled limit of max one opened http connection per program in NetHelper
https://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
-
Hi,
In r500, that crash again HomeGenie ...
-
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.
-
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 ...
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 :
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 ?
-
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?
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.
-
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.
-
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.
-
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
-
Hi,
It's weird because i have 2 similar codes :
- one to update the status of the plug (off or on ?)
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();
- One to change the status of the plug : on to off or off to on
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 ?
-
Hi,
After a lot of debugging, I found the problem !!!!
I just comment the following line (i use only for debugg) :
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
-
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?
-
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.
-
Can you outline the method to support multiple wemo switches?
-
Probably not the best way, but it should work ... Can you try ?
-
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.
-
Did anyone manage to get multiple Wemo's to work?
-
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.