AlertMe and Vera integration (first cut, alpha code)

Having looked around these forums and the wider web, I believe the AlertMe energy monitoring system meets my needs well.

I’ve been setting up a number of their “SmartPlugs” around the house which can be remote controlled to be on/off and will remotely report the energy usage,
as well as monitoring the local temperature (although this last doesn’t seem to work too well).

Their architecture is pretty well locked down and requires use of their server(s) to which the “Smart Hub” in the home reports information from all other wireless (Zigbee) devices.

That said, they have an API which allows clients to monitor and control devices in the home via their server(s)

I am interested in integrating this API with Vera to enable me to monitor power usage (although their UI is pretty decent) and also to control switches around the home.

To that end I have written a first cut of a plugin which will allow users to turn SmartPlugs on and off via Vera.

If you aren’t completely happy with installing and potentially backing out files under Linux I would suggest you don’t play with this just yet

Installation

(1) The Lua implementation provided with Vera doesn’t seem to support XML-RPC so this needs to be added

I’ve chosen to use the implementation here which seems ok.

It doesn’t seem to support SSL sockets out of the box (which is needed for AlertMe) and there are issues with the AlertMe API which have meant I’ve had to modify the files. The changes are minor and I don’t believe I have broken anything in the process of modifying the implementation but I may have, so be aware if you intend to use XML-RPC in the future.

To install the XMLRPC support take the xmlrpc-dd-0.0.1 zipfile which is attached, unzip and copy across to the Vera using WinSCP or your preferred tool into a /usr/lib/lua/xmlrpc folder. You should end up with the following files in there: init.lua, http.lua, https.lua and server.lua

I created https.lua based on http.lua as the original http.lua didn’t seem able to support SSL (I may have missed something here). The syntax for https is identical for http so the instructions/examples from the original project should still work if you just replace requires xmlrpc.http with requires xmlrpc.https

Also there are some assertions in the init.lua code which are triggered as the XMLRPC response is parsed as the element isn’t where the code expects it to be. I don’t know if this is a non-conformance on AlertMe’s part or not as I’m no expert on XMLRPC so I’ve worked around this, attempting to leave the original code functionality intact. If somebody wants to verify it still works against other XMLRPC servers I’d be interested to know.

(2) With the XMLRPC support added the plugin for the SmartPlug can then be added

The process pretty much as for other plugins. Use the Lua Developer support to upload the following files and restart Luup

D_SmartPlug1.xml, I_SmartPlug1.xml, D_SmartPlug1.json

Once these are uploaded you can use the Create Device support to create a new SmartPlug device.

In the Create Device options enter “D_SmartPlug1.xml” for the device file and “I_SmartPlug1.xml” for the impl_file.

The new device will be created.

For some reason you seem to need to restart the Luup server a couple of times - first for the implementation to be picked up and then second for the default variables to be set.

So click the server restart button in the top right of the Vera (4) UI to restart the server.

(3) Configuring the Device

If you then edit the newly created device you should see some variables in the Advanced tab - Uri, Login, Password and Device ID

There should be no need to change Uri.

Replace login and passsword values with your user name/login and password from AlertMe.

Then you will need to determine the device ID. This is the Zigbee hardware device ID of your SmartPlug rather than the friendly name you gave it for the AlertMe UI.

To determine this you can use their test script here

Login there and it’ll run some XMLRPC calls of its own displaying information about your devices. You’ll see a table with “zigbeeId” “name” and “type”. Grab the zigbeeId for the SmartPlug you want to control and enter it into the Vera “Device ID”. It will look something like “00-0D-6F-00-01-72-FA-F9”

(4) Control

You should now be able to use the on and off buttons to turn on and off the SmartPlug.

(5) Troubleshooting

The plugin logs to the standard /var/log/cmh/LuaUPnP.log file so if you have issues you may see what’s going wrong there.

Also sometimes I have seen the Luup server seems to restart when using this, which is something I need to look at. Perhaps it’s the delay whilst logging in over SSL.

Feedback appreciated,

Alex
Dynamic Devices Ltd