The following code extracts the most recent data from PVOutput.org .org using the service described here:
http://www.pvoutput.org/help.html#api-getstatus
In the code you need to enter your API key and your Solar Sytem ID. There are clear instructions on the PVOutput.org site on getting hold of these. You also need to enter the device ID of your Vera Energy Meter. In @Wekke’s example this would be the number 59. You can test the code by cut & pasting into the Vera 'Test Luup code" box and running it. Results are shown in the Vera log. You can use the infoviewer plugin or AltUi plugin to see the logs easily. You can turn off the debugging by setting DEBUG_MODE = false.
I’ve set the code to write the generated energy & power to the Energy Meter. You can change it to consumed energy & power by moving the variable writes to the i=5 and i=6 clauses. The sign of the data may need changing depending on interpretation.
You can put all this into a scene under the Lua code section and run it on a timed interval or ultimately use it in a plugin of it’s own.
Regardless - it’s all a bit roundabout - you’re probably better off getting your solar inverter and/or power meter to send the info directly to Vera rather than via PVOutput.org but acknowledging this may not be easily done in some cases. So if you lose your connection to PVOutput.org or the site itself goes down it will likely cause problems.
[code]local PLUGIN_NAME = ‘TestingPVOuputGetStatus’
local ENERGY_METER_ID = 0 – number/ID of your energy metering device
local ENERGY_METER_SID = ‘urn:micasaverde-com:serviceId:EnergyMetering1’
local m_PVOutputApiKey = ‘a…9’ – your API key
local m_PVOutputSystemID = ‘12345’ – your solar system ID
local DEBUG_MODE = true
local function debug(textParm, logLevel)
if DEBUG_MODE then
local text = ‘’
local theType = type(textParm)
if (theType == ‘string’) then
text = textParm
else
text = 'type = ‘…theType…’, value = ‘…tostring(textParm)
end
luup.log(PLUGIN_NAME…’ debug: '…text,50)
elseif (logLevel) then
local text = ''
if (type(textParm) == 'string') then text = textParm end
luup.log(PLUGIN_NAME..' debug: '..text, logLevel)
end
end
local function getStatusService()
local url = ‘http://pvoutput.org/service/r2/getstatus.jsp?key=‘..m_PVOutputApiKey..’&sid=’…m_PVOutputSystemID
debug (url)
-- call the 'Get Status Service' at PVOutput.org
local httpStatusCode, content = luup.inet.wget(url)
debug('status code was '..tostring(httpStatusCode))
debug ('content is '..content)
if (httpStatusCode ~= 0) then return false end
-- an example of returned data: 20151202,08:45,2143,3161,NaN,NaN,0.405,NaN,NaN
local i = 1
for dataValue in string.gmatch(content, '([^,]+)') do
if (i == 1) then -- Date
elseif (i == 2) then -- Time
elseif (i == 3) then -- Energy Generation
if (dataValue ~= 'NaN') then
--luup.variable_set(ENERGY_METER_SID, 'KWH', tostring(tonumber(dataValue)/1000.0), ENERGY_METER_ID)
end
elseif (i == 4) then -- Power Generation
if (dataValue ~= 'NaN') then
--luup.variable_set(ENERGY_METER_SID, 'Watts', dataValue, ENERGY_METER_ID)
end
elseif (i == 5) then -- Energy Consumption
elseif (i == 6) then -- Power Consumption
elseif (i == 7) then -- Efficiency
elseif (i == 8) then -- Temperature
elseif (i == 9) then -- Voltage
else
debug('got more parms than expected')
end
i = i +1
end
end
getStatusService()
return true
[/code]