[quote=“worldburger, post:35, topic:190754”]EDIT: Added complete EnergyMonitor.lua code
///////////////////////////////////////////////////
I’m having some trouble getting this to work.
My objective is to:
Measure/log energy consumption on my house. (Do I need two CT clamps or just one for this? Am in the USA)
Measure/log energy consumption on my 240v kiln. (Do I need two CT clamps or just one for this? Am in the USA)
I have TWO - Aeon Home Energy Monitor (v1)'s (one for the breaker box and one for the kiln). Presently only one is setup as I am trying to get the house consumption data working first…which is troublesome
Here’s where I’m at…
I’ve successfully got the Aeon Home Energy Monitor (v1) to talk to my VeraPlus. I can see the actual Watts and KWH on the Vera Dashboard. I’ve also go the VeraPlus talking to Emoncms (it sends my INPUTs to Emoncms with the keys I’ve entered). I’ve also created a FEED in Emoncms.
Unfortunately, on Emoncms I am only seeing ZEROS (“0”) as my inputs. What could be the problem? Any ideas?
Setup:
VeraPlus. UI7 (latest update). Aeon Home Energy Monitor (v1) with two current clamps powered by USB (1s update interval to VeraPlus).
Questions:
Is “device name” in the VeraPlus UI the “key” needed in the VARIABLES section of the EnergyMonitor.lua file?
Where do you find the specific “serviceVar” for the devices?
Which of the following do I need (or can I) to publish to Emoncms?
My Aeon Home Energy Monitor shows up as 3 devices…
1st is the total Watts & KWH (in Vera UI, I named this “totalwkwh”)
2nd is Watt & KWH from 1st CT Clamp reading (in Vera UI, I named this “hema”)
3nd is Watt & KWH from 2nd CT Clamp reading (in Vera UI, I named this “hemb”)
Screenshots are attached.
Normally, I’m pretty capable with mild programming and setup, but this is stumping me!
Thanks in advance
My code is below:
—Startup Lua—
[code]module(“EnergyMonitor”, package.seeall)
– Setup your account at http://emoncms.org/
– See API documentation at Emoncms - input api
– API Key
local API_KEY = “REMOVED FOR POST”
– Setup your devices here. You can use a function to calculate the power as illustrated in the sample.
– For device logging, use: key, deviceId, serviceId, serviceVar
– For function based logging, use: key, calculate, serviceVar
local VARIABLES = {
{ key=“totalwkwh”, deviceId = 065, serviceId=‘urn:schemas-micasaverde-com:device:PowerMeter:1’, serviceVar=“Watts” }, – Send Joined Device data
{ key=“hema”, deviceId = 67, serviceId=‘urn:schemas-micasaverde-com:device:PowerMeter:1’, serviceVar=“Watts” }, – Send CT 1 device data
{ key=“hema”, deviceId = 67, serviceId=‘urn:schemas-micasaverde-com:device:PowerMeter:1’, serviceVar=“CurrentLevel” }, – Send CT 1 device data
{ key=“hemb”, deviceId = 66, serviceId=‘urn:schemas-micasaverde-com:device:PowerMeter:1’, serviceVar=“Watts” }, – Send CT 2 device data
{ key=“hemb”, deviceId = 66, serviceId=‘urn:schemas-micasaverde-com:device:PowerMeter:1’, serviceVar=“CurrentLevel” }, – Send CT 2 device data
}
– Add the following to your Vera’s Startup Lua (without the preceding dashes) to run the logging on every Vera restart
– emoncode = require(“EnergyMonitor”)
– emoncode.EnergyMonitorOnTimer()
local NODE_ID = 10
local TOTAL_KEY = ‘Total’
– Upload Frequency in seconds ORIGINALLY 60
local updateInterval = 10
– Log debug messages
local DEBUG = true
– You shouldn’t need to change anything below this line –
local http = require(‘socket.http’)
http.TIMEOUT = 3
local BASE_URL = “http://emoncms.org/input/post.json?apikey=” … API_KEY
local Log = function (text) luup.log('EnergyMonitor Logger: ’ … (text or “empty”)) end
local lastFullUpload = 0
local items = {} – contains items: { time, deviceId, value }
local function StartCallbackTimer(interval)
luup.call_delay(“EnergyMonitorOnTimer”, interval or updateInterval, nil)
end
local function InitWatch()
StartCallbackTimer(1)
end
local function AddKeyValuePair(key, value)
local item = string.format(“%s:%s”, key, tostring(value))
items[#items + 1] = item
end
local function SerializeData()
local dataText = “{” … table.concat(items, “,”) … “}”
return dataText
end
local function ResetData()
items = {}
end
local function SendData()
local data = SerializeData()
ResetData()
local parameters = "&node=" .. tostring(NODE_ID) .. "&json=" .. data
local url = BASE_URL .. parameters
if (DEBUG) then Log("Updating with: " .. parameters) end
http.request(url)
end
local function AddAllVariablesAndTotal()
local total = 0
for i, v in ipairs(VARIABLES) do
local value
if v.deviceId then
value = luup.variable_get(v.serviceId, v.serviceVar, v.deviceId)
elseif v.calculate then
value = v.calculate()
end
value = tonumber(value) or 0
if v.serviceVar == “Watts” then
total = total + value
end
AddKeyValuePair(v.key, value)
end
AddKeyValuePair(TOTAL_KEY, total)
end
function EnergyMonitorOnTimer()
StartCallbackTimer()
AddAllVariablesAndTotal()
SendData()
end
_G.EnergyMonitorOnTimer = EnergyMonitorOnTimer
InitWatch()
[/code][/quote]
Any ideas, people?