For those interested in pushing data to SEG for analysis, here’s a snippet of Lua that can be used in your Vera Startup.
It’s not a plugin, and it’s not resilient (if SEG goes down, the data isn’t accumulated at Vera) but it works reasonably well (I use it for supplementary data like Room & Outdoor temperatures)
The code will work for any Energy Data in Vera, not just from Brultech units, as well as for Temperature data.
[code]local http = require(‘socket.http’)
http.TIMEOUT = 5
local SEG_SITE = “”
local SEG_URL = “http://api.smartenergygroups.com/api_sites/stream”
local segLog = function (text) luup.log('SEG Logger: ’ … (text or “empty”)) end
SEG_DEVICES = {
{node=‘vera’, stream=‘t_upstairs’, deviceId=335, serviceId=‘urn:upnp-org:serviceId:TemperatureSensor1’, serviceVar=“CurrentTemperature”},
{node=‘vera’, stream=‘t_downstairs’, deviceId=384, serviceId=‘urn:upnp-org:serviceId:TemperatureSensor1’, serviceVar=“CurrentTemperature”},
{node=‘vera’, stream=‘t_outside’, deviceId=318, serviceId=‘urn:upnp-org:serviceId:TemperatureSensor1’, serviceVar=“CurrentTemperature”}
}
local function findStream(deviceId, serviceId, serviceVar)
– TODO: Change from a simple scan to something that’ll support more entries efficiently.
for k, v in pairs(SEG_DEVICES) do
if (v.deviceId == deviceId and
v.serviceId == serviceId and
v.serviceVar == serviceVar) then
return v.node, v.stream
end
end
return nil, nil
end
local function initWatch()
for k, v in pairs(SEG_DEVICES) do
luup.variable_watch(‘segWatch’, v.serviceId, v.serviceVar, v.deviceId)
end
end
function segWatch(deviceId, serviceId, serviceVar, oldValue, newValue)
local nodeName, streamName = findStream(deviceId, serviceId, serviceVar)
if (nodeName == nil or streamName == nil) then
segLog(string.format(“Node not found for %s,%s,%s”, deviceId, serviceId, serviceVar))
return
end
– TODO: Encoding
segData = string.format(“(site %s (node %s ? (%s %s)))”, SEG_SITE, nodeName, streamName, newValue)
segLog(segData)
result, status = http.request(SEG_URL, segData)
end
initWatch()
[/code]
You need only substitute in your SEG Site Id, and the “table” (SEG_DEVICES) of Device/ServiceId/StateVariable that you want to track, and the script will watch them for changes and push the values across to SEG.
In my case, I have a SEG Device registered with the label “[tt]vera[/tt]”, and beneath that I have SEG Streams for “[tt]t_upstairs[/tt]”, “[tt]t_downstairs[/tt]” and “[tt]t_outside[/tt]”. In my Vera, these are devices 335, 384 & 318 and they all support the standard Temperature data ([tt]urn:upnp-org:serviceId:TemperatureSensor1[/tt], [tt]CurrentTemperature[/tt])
Since the data is only pushed when a value changes, you may have to wait a little while before you see the data in SEG (after loading the code into Vera’s Startup method, and restarting Vera)
NOTE: When naming your streams for SEG, use prefixes of
[ul][li]t_ - temperature data[/li]
[li]e_ - energy data (Wh, kWh, etc)[/li]
[li]p_ - power data (W, kW, etc)[/li][/ul]
When using SEG’s “Discoveries” feature, it automatically decodes the Stream names, and applies the correct typing information if the streams are named using these prefixes.
This tool is on http://smartenergygroups.com/tools
MyThings → tools → Discoveries
When using the Discovery feature, you may need to leave SEG on that page for some time, as I’m only sending data over as it changes.