I found a network controlled power strip that is pretty affordable (well compared to the others on the market). It is made by a company called Digital Loggers. Here is the link:
I just purchased one and would like to create a plugin for vera to control each outlet. I have started creating the plugin and been in discussion with guessed on how to proceed with development. A demo of the web interface for the switch can be found here:
I am new to lua and my first issue is to tackle getting authenticated to the web page to pull the status data. The state of the outlets are in the source of the html page in a comment at the top of the page that looks like this:
The state variable is what we need. It is in hex and to get the state of each port you will need to convert it into binary notation. So “ff” would be 11111111 in binary. To translate the outlet status starting from left to right, the first 1 is outlet 8 and is on, the next 1 is outlet 7 and is on, and so on.
Back to the authentication. The authentication via an http request would look like this: [b]http://admin:4321@lpc.digital-loggers.com/index.htm[/b]. Here is the dilemma, the authentication is not our basic http authentication. Guessed suggested that I use lua.socket to get the information. What I need to know is how to figure out how to authenticate and get the response. I believe the page uses md5 digest to authenticate. So what I need to figure out is what proper headers are needed or what else is need to get authenticated to the page. I found the following link at the girder forum where a user is having a similar issue: Help with socket.http when authentication is required
Does anyone have any suggestions? I apologize if my post sounds confusing.
Well I started to mess around with creating a basic lua script to grab the html content and I finally got it to authenticate and get the data. I had to mess with the headers to get it right. This is what I have come up with:
#!/usr/bin/lua
http = require("socket.http")
mime = require("mime")
local resultTable = {}
r, c = http.request {
url = "http://lpc.digital-loggers.com/index.htm",
sink = ltn12.sink.table(resultTable),
method = "GET /index.htm HTTP/1.1",
headers = { ["Authorization"] = "Basic " .. (mime.b64("admin:4321")),
["Host"] = "lpc.digital-loggers.com",
["Accept"] = "*/*" }
}
local data = ""
for i, v in ipairs(resultTable) do
data = data .. v
end
print(data);
Looks like I’ll be starting work on the plugin and hopefully have it ready when my switch comes in. I’ll keep people posted.
The second part, parsing the result string, can be done using [tt]string.match()[/tt] and the Lua patterns they expose, along with something called a “capture”… you’ll see this in a few example Lua files like the Sonos:
I finally had time to get the plugin setup and published into the app store. It needs approval from MCV. I know it has been some time since I posted about this topic. I have been running the plugin for the last 5 months with out any issues.
After seeing this forum post and checking out your great looking app, I promptly placed an order for one of the web power switches. I have been trying to find a z-wave equivalent for several months. Several come up in Google such as one by Aeon Labs, but I couldn’t find one actually for sale.
This one fits the bill and is priced about what I was expecting to pay for a z-wave one.
I wish I released the plugin much earlier. It is a really nice power switch. I will have to order a few more in the near future. I see the newer versions now have buttons for control on the switch itself. I have version 4 and the newer one is version 5. Let me know if you have any issues with the plugin. I will have a newer update uploaded in the near future to fix some cosmetic issues.
+1 for someone who thinks the app and the switch look really cool and helpful. I just ordered one myself. You should definitely request a commission from Digital Loggers! And thanks!
Just recieved my web power switch. They are so popular they have been sold out for a few weeks. Hooked to the network and integrated with Vera. Works great!
@garrettwp Is there any way to implement the cycle function for the outlets into Vera? Hitting off and then on works for most things, but I am going to have my Vera connected which wouldn’t work so well. If not, I will just run the switch through my DDNS but if there is one less thing on my network to expose to the Internet the better.
I also just got my power switch and got it online with Vera. It works great! Thanks so much for the work on this plug-in!
Just like Trotsky40, I would also love the ability to cycle outlets in the UI (rather than just toggle off and on). If I want to reboot the router I guess I could do it with a Vera scene. However, if I want to reboot the Vera itself, I don’t think a scene would work. Anyway - just a thought if you plan to configure any future improvements. If not, no worries - this is great work!
Thanks garrettwp for this plugin. I’ve been using the diggital loggers PDUs for about 4 years now in server racks and in most rooms in my house. I already thought they were the best IP enabled PDUs on the market, but this add-in really solidifies that for me.
Like the others have mentioned, it would be great if you would be able to implement the cycle option so that recycling the vera, and other network gear that would impact access to vera, can be done from the plugin.
I could be wrong about this, but in looking at the xml files, it appears that it would not be possible to add a button for the Cycle function because all the switch objects are using the binary light xml object (on/off being the only button options I think).
I’m not a much of a coder, so I’m just asking to see if this might be a feasible workaround: could a new object be added in the I_WPSwitch1.xml that populates with all pdu outlets (or creates an individual object for each outlet if a single one is not possible) with a button next to each pdu outlet which would send the required cycle command via http (eg. http://92.168.0.100/outlet?7=CCL)?
I will look at adding the cycle option. The only issue is adding it to the ui. I am using the binary light device to keep compatibility with 3rd party apps like my own, homebuddy, and other ios apps. If I create a new device type, it will break compatibility and would require the developer to add support. I can add it as a service variable to be used in scenes. Not sure how useful that would be for everyone. I do not use the cycle option, hence the reason I never added it.
Thanks Garrett. That’s what I figured was the reasoning for the design decision. Clearly it is better to try and maintain the broadest compatibility. I use Homebuddy also, and I agree that maintaining usability there is important.
Not sure what the best way to handle cycling is; hopefully it’s possible without a lot of grief. If it’s a lot of grief I’ll understand if you don’t pursue it.
Let me know if you’d like me to test anything. I have almost every PDU that those guys have made for the last four years, so I can validate against all of them it it’s useful to anyone.
One way I can add this is to add the toggle option which would call the cycle command. But it looks like Vera’s UI does not allow you to issue the toggle command for the light. You use to be able to click on the light icon and it would toggle the state of the device. I have this option added into my app “AutHomation”. You would click on the binary light icon or the dimmable light icon to toggle the state of the light. This also works for locks and so forth. Not sure if homebuddy allows this.
That would work for me. Has Vera completely removed that feature from the UI? If you add this to the code, I’ll test it with homebuddy. If it doesn’t work, I’ll ask Rakstar if he would add it.
Just looked at my code. Have not touched it in a while. I already have the toggle condition available. But right now it will toggle to the opposite state of what it currently is in. E.g. if the outlet is on, it will than toggle it off. I will change it to accommodate the cycle command if others agree. If you load up homebuddy, try hitting the icon of the outlet and see if it toggles the state.