Eco Plugs

I recently picked up some wifi-controlled outlets called KAB “Eco Plugs” manufactured by a chinese company KAB a few weeks back at Home Depot. They were crazy cheap (2 for $5) and work through use of an app on your home wifi network. You can also buy them on other sites like walmart:

I’ve been trying to figure out what protocol they use so I could try to integrate them into Vera. I did some basic packet captures and I believe they are sending udp traffic on port 80. FYI, someone has figured out how they communicate, and has written a plugin for homebridge (a HomeKit emulation server). The plugin info is here:

https://www.npmjs.com/package/homebridge-ecoplug4
https://github.com/Danimal4326/homebridge-ecoplug4

I can confirm that it works, as I have homebridge running, and am able to control my Eco Plugs using the homebridge-ecoplug plugin (very cool plugin BTW). However, I am not good enough at reading code to actually see what is being sent/received. If you look at the github page, there is an index.js file that contains all the code. If there is anyone that is versed enough to look javascript and figure out what is being sent/received, I would love to know what the actual http commands being sent are too. Thanks in advance for any help that can be provided!

So… I needed a change of pace… and recently implemented a similar device (SengLED Boost bulb)…

and came up with an implementation for these devices…

  1. On your Vera, go to Apps/Develop Apps/Luup Files, and upload the attached implementation file.
  2. On your Vera, go to Apps/Develop Apps/Create Device.
  3. Fille in the parameters as follows:
    Device Type: urn:schemas-upnp-org:device:BinaryLight:1
    Internal ID: (enter the name of your switch ie: ECO-XXXXXXXX)
    Description: (enter the name you want for the plug - if left blank, it will be names “_Binary Light”)
    Upnp Device Filename: D_BinaryLight1.xml
    Upnp Implementation Filename: I_ECO_Switch.xml
    IP address: (enter the IP Address of your ECO plug)
  4. Click on “Create Device”
  5. Allow the LuaUPnP engine to reload and refresh your browser.

You should then be able to control the switch directly from your Vera.

** Faulty attachment removed **

Thanks so much for putting this together!! I’m traveling at the moment, but I will give it a shot as soon as I’m able and report back how it works. Thanks again!

So I finally had some time to try this today, doesn’t work :-\ I get “Lua Engine Failed to Load” error at the top of the screen. I’m running latest UI7, and have debug logging enabled. I ssh’ed into my Vera and looked at the LuaUPnP log. I don’t see anything jumping out, but I’m not sure I’m looking for the right things either. I don’t see anything in there related to the XML file you put together. Any advice on what I should be looking for?

You’ll need to post the log… I don’t have these devices… so i’m working blind…

see attached, is this what youre looking for? Thanks again!

I checked over the code… I made a small error in the translation nodejs to lua…

The fixed file is attached…

** Faulty attachment removed **

Removed old XML file and readded, still getting an error but now it says " Startup Lua Failed". Attached is the part of the log I think is relevant…

Your log should that the code loaded without error.

The “Startup Lua failed” error message means that you have add/changed/removed something from the startup code, and is not related to the device implementation.

Thanks for continuing to help with this. I deleted the device and recreated from scratch, this time I called it “Kitchen2” When I reload, I still see the same error, here is what it looks like in the logs:

XXX-UpdateSystemMessagesTasks now 2=Kitchen2[114]: Startup Lua Failed timeout 0 (-1454167578) count: 21pend:(null)/err:Startup Lua Failed/done:(null) <0x2b3e0680>

I’v also attached a screenshot showing my config (you can also see the error at the top). When I click the switch, nothing happens although sometimes I think it flashes “command field” very quickly. I’ve also confirmed the IP address in the config is correct. You can’t see the full “device type” in the screenshot, but it is definitely set to “urn:schemas-upnp-org:device:BinaryLight:1”

Below are some more log entries that I think are relevant:

untitled text:4149: 10 01/30/16 8:43:53.126 XXX-UpdateSystemMessagesTasks now 2=Kitchen2[114]: Startup Lua Failed timeout 0 (-1454168633) count: 22pend:(null)/err:Startup Lua Failed/done:(null) <0x2bb5c680>
untitled text:5007: 12 01/30/16 8:44:06.200 luvd_get_info_data_request starting /data_request?id=lu_action&output_format=json&DeviceNum=114&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&rand=0.4739158684387803 pMem 0x14d6000/21848064 diff: 13930496 <0x312a5680>
untitled text:5010: 08 01/30/16 8:44:06.202 JobHandler_LuaUPnP::HandleActionRequest device: 114 service: urn:upnp-org:serviceId:SwitchPower1 action: SetTarget <0x312a5680>
untitled text:5011: 08 01/30/16 8:44:06.203 JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=114 <0x312a5680>
untitled text:5016: 02 01/30/16 8:44:06.206 Device_LuaUPnP::HandleActionRequest 114 not ready 0x969de0 <0x312a5680>
untitled text:5017: 02 01/30/16 8:44:06.206 JobHandler_LuaUPnP::RunAction device 114 action urn:upnp-org:serviceId:SwitchPower1/SetTarget failed with -911/Device not ready <0x312a5680>

And more log entries, this may be the most telling:

01 01/30/16 10:10:07.316 LuaInterface::CallFunction_Startup-1 device 114 function init failed [string “…”]:151: attempt to concatenate global ‘ipaddr’ (a nil value) <0x2bfe4680>
01 01/30/16 10:10:07.317 LuImplementation::StartLua running startup code for 114 I_ECO_Switch.xml failed <0x2bfe4680>

Typos are the bane of my existence 8-}

Try this…

** Faulty attachment removed **

;D

Getting closer, still getting “startup Lua failed”. I deleted the old XML, readdded, and created a new device from scratch called “Kitchen3” Here are the logs:

50 01/30/16 12:48:56.493 luup_log:115: SengLED: Port not specified, assumed. <0x2b556680>
01 01/30/16 12:48:56.502 LuaInterface::CallFunction_Startup-1 device 115 function init failed [string “…”]:94: bad argument #2 to ‘sendto’ (string expected, got table) <0x2b556680>
01 01/30/16 12:48:56.503 LuImplementation::StartLua running startup code for 115 I_ECO_Switch.xml failed <0x2b556680>

Try this…

** REMOVED NON-FUNCTIONAL VERSION **

Still Broken :frowning:

Latest Logs:

untitled text 6:22144: 50 01/30/16 15:37:07.358 luup_log:116: SengLED: Port not specified, 80 assumed. <0x2c314680>
untitled text 6:22148: 01 01/30/16 15:37:07.369 LuaInterface::CallFunction_Startup-1 device 116 function init failed [string “…”]:94: bad argument #1 to ‘sendto’ (string expected, got nil) <0x2c314680>
untitled text 6:22149: 01 01/30/16 15:37:07.369 LuImplementation::StartLua running startup code for 116 I_ECO_Switch.xml failed <0x2c314680>

Here is another try…

I’ve added some extra debug logging so we can get this resolved.

** REMOVED NON-FUNCTIONAL VERSION **

Ok some progress. Looks like the code is compiling correctly now (no errors) but the switch still doesn’t work. Looking at the log, it looks like it is sending the commands, here is what I am looking at:

08 01/30/16 20:00:47.533 JobHandler_LuaUPnP::HandleActionRequest device: 116 service: urn:upnp-org:serviceId:SwitchPower1 action: SetTarget <0x2f42b680>
08 01/30/16 20:00:47.533 JobHandler_LuaUPnP::HandleActionRequest argument newTargetValue=1 <0x2f42b680>
50 01/30/16 20:00:47.557 luup_log:116: (I_ECO_Switch::ACTION::SetTarget) Setting switch state to [1] <0x2ae9a000>
06 01/30/16 20:00:47.557 Device_Variable::m_szValue_set device: 116 service: urn:upnp-org:serviceId:SwitchPower1 variable: Target was: 1 now: 1 #hooks: 0 upnp: 0 skip: 0 v:0x10659f0/NONE duplicate:1 <0x2ae9a000>
50 01/30/16 20:00:47.559 luup_log:116: (I_ECO_Switch::Ecoswitch::sendMessage) Sending command to ip [172.16.0.243:80] <0x2ae9a000>
01 01/30/16 20:00:50.564 luup_log:116: (I_ECO_Switch::EcoSwitch::sendMessage) Sent command. <0x2ae9a000>
01 01/30/16 20:00:50.565 luup_log:116: (I_ECO_Switch::EcoSwitch::setStatus) ERROR setting State of switch with ID 116. <0x2ae9a000>
06 01/30/16 20:00:50.565 Device_Variable::m_szValue_set device: 116 service: urn:upnp-org:serviceId:SwitchPower1 variable: Status was: 0 now: 0 #hooks: 1 upnp: 0 skip: 0 v:0x1065a68/NONE duplicate:1 <0x2ae9a000>
50 01/30/16 20:00:50.566 luup_log:116: (I_ECO_Switch::ACTION::SetTarget) Switch state to 0] <0x2ae9a000>
04 01/30/16 20:00:50.567 <0x2ae9a000>
08 01/30/16 20:00:52.865 JobHandler_LuaUPnP::HandleActionRequest device: 116 service: urn:upnp-org:serviceId:SwitchPower1 action: SetTarget <0x3002b680>
08 01/30/16 20:00:52.866 JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=116 <0x3002b680>
08 01/30/16 20:00:52.866 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:upnp-org:serviceId:SwitchPower1 <0x3002b680>
08 01/30/16 20:00:52.867 JobHandler_LuaUPnP::HandleActionRequest argument action=SetTarget <0x3002b680>
08 01/30/16 20:00:52.867 JobHandler_LuaUPnP::HandleActionRequest argument newTargetValue=1 <0x3002b680>
08 01/30/16 20:00:52.868 JobHandler_LuaUPnP::HandleActionRequest argument rand=0.9898078248370439 <0x3002b680>
50 01/30/16 20:00:52.871 luup_log:116: (I_ECO_Switch::ACTION::SetTarget) Setting switch state to [1] <0x2ae9a000>
06 01/30/16 20:00:52.871 Device_Variable::m_szValue_set device: 116 service: urn:upnp-org:serviceId:SwitchPower1 variable: Target was: 1 now: 1 #hooks: 0 upnp: 0 skip: 0 v:0x10659f0/NONE duplicate:1 <0x2ae9a000>
50 01/30/16 20:00:52.872 luup_log:116: (I_ECO_Switch::Ecoswitch::sendMessage) Sending command to ip [172.16.0.243:80] <0x2ae9a000>

Here is another version… with even more debugging (so we can see what data is being sent and any response data received)…

Also, please verify that you have the correct IP address for your device…

** REMOVED NON-FUNCTIONAL VERSION **

Very cool, thanks for adding the debug info. I triple checked the IP address. I confirmed in my arp table and the homebridge app is still working, with 172.16.0.243 as the IP hard coded in that homebridge config file. Here are the latest logs, and you’re right, there is a lot more there, including packet capture. I think I still have the packet capture I took before, If I can find it, I will post it too. Logs:

08 01/31/16 12:31:48.885 JobHandler_LuaUPnP::HandleActionRequest device: 116 service: urn:upnp-org:serviceId:SwitchPower1 action: SetTarget <0x31387680>
08 01/31/16 12:31:48.886 JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=116 <0x31387680>
08 01/31/16 12:31:48.886 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:upnp-org:serviceId:SwitchPower1 <0x31387680>
08 01/31/16 12:31:48.887 JobHandler_LuaUPnP::HandleActionRequest argument action=SetTarget <0x31387680>
08 01/31/16 12:31:48.887 JobHandler_LuaUPnP::HandleActionRequest argument newTargetValue=1 <0x31387680>
08 01/31/16 12:31:48.888 JobHandler_LuaUPnP::HandleActionRequest argument rand=0.8577514525968581 <0x31387680>
50 01/31/16 12:31:48.890 luup_log:116: (I_ECO_Switch::ACTION::SetTarget) Setting switch state to [1] <0x2b6ee000>
06 01/31/16 12:31:48.890 Device_Variable::m_szValue_set device: 116 service: urn:upnp-org:serviceId:SwitchPower1 variable: Target was: 1 now: 1 #hooks: 0 upnp: 0 skip: 0 v:0xc26ad0/NONE duplicate:1 <0x2b6ee000>
50 01/31/16 12:31:48.891 luup_log:116: (I_ECO_Switch::EcoSwitch::setStatus) Called setStatus(172.16.0.243,116,true). <0x2b6ee000>
50 01/31/16 12:31:48.891 luup_log:116: (I_ECO_Switch::EcoSwitch::createMessage) Called createMessage(set,116,true). <0x2b6ee000>
50 01/31/16 12:31:48.909 luup_log:116: (I_ECO_Switch::EcoSwitch::createMessage) Created command data - time [1454268708] [
00000000 16 00 05 00 00 00 DF 6F 02 00 00 00 00 00 00 00 …?o…
00000010 31 31 36 20 20 20 20 20 20 20 20 20 20 20 20 20 116
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …
00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …
00000070 00 00 00 00 56 AE 61 24 00 00 00 00 CB B8 42 2A …V?a$…˸B*
00000080 01 01 …
] <0x2b6ee000>
50 01/31/16 12:31:48.910 luup_log:116: (I_ECO_Switch::EcoSwitch::sendMessage) Called sendMessage(172.16.0.243,116, <0x2b6ee000>
50 01/31/16 12:31:48.911 luup_log:116: (I_ECO_Switch::EcoSwitch::sendMessage) Sending command… <0x2b6ee000>
01 01/31/16 12:31:49.027 IOPort::Connect connect -1 172.16.0.12:60128 <0x3027f680>
50 01/31/16 12:31:49.913 luup_log:116: (I_ECO_Switch::EcoSwitch::sendMessage) Sending command… <0x2b6ee000>
50 01/31/16 12:31:50.915 luup_log:116: (I_ECO_Switch::EcoSwitch::sendMessage) Sending command… <0x2b6ee000>
50 01/31/16 12:31:51.917 luup_log:116: (I_ECO_Switch::EcoSwitch::sendMessage) received response [NIL] <0x2b6ee000>
01 01/31/16 12:31:51.918 luup_log:116: (I_ECO_Switch::EcoSwitch::sendMessage) Send command failed. <0x2b6ee000>
01 01/31/16 12:31:51.918 luup_log:116: (I_ECO_Switch::EcoSwitch::setStatus) ERROR setting State of switch with ID 116. <0x2b6ee000>
06 01/31/16 12:31:51.919 Device_Variable::m_szValue_set device: 116 service: urn:upnp-org:serviceId:SwitchPower1 variable: Status was: 0 now: 0 #hooks: 1 upnp: 0 skip: 0 v:0xc26b48/NONE duplicate:1 <0x2b6ee000>
50 01/31/16 12:31:51.919 luup_log:116: (I_ECO_Switch::ACTION::SetTarget) Switch state to 0] <0x2b6ee000>
04 01/31/16 12:31:51.921 <0x2b6ee000>

Thanks again!