PVOUtput.Org integration

Hi folks. Do you know how I could integrate my VeraLite with PVOutput.org?
I upload my house consumption and solar production measurements to PVOutput.org here:
Village High 13.287kW

I’d like my Vera to be able to read the last published result for power used and (solar) power generated. Then I could use those readings to make automated decisions about turning appliances on/off.
Any ideas?

I"m also interested in a working PVoutput plugin. I use pvoutput to log electricity (consumption and gerenated solar power) and water / gas consumption.

You are probably using a script to upload data to PVoutput? Here"s my solution for now.

I’ve created 4 power meter devices in Vera which I populate with data via a http command sent from the same script I use to upload data to PVoutput. It’s just some extra lines in the script.
I don’t use the powermeter values to trigger scenes but it’s possible if you want.
I started using datamine to get some statistics from the data i’ve sent to the Vera unit, but after a firmware update datamine was broken so I gave up on that.

See screenshot for my powermeters. Gas and water also shows Watts and KWH but I have to read it as LITERS.

Hi. Thanks for your reply Wekke,
I don’t use a script to upload actually. My Solar inverter has the functionality built into it somehow. I also use a Current Cost bridge to upload power consumption. I’m keen to understand how to create and populate the power meter devices you have made. Can you share more details?

I’m afraid you have to write a script to use my solution with the powermeters. First what you have to do in your script is reading your outputs from PVoutput and then send it to your Vera powermeters.

Here’s how you can create a powermeter in you Vera controller. I’m using UI7 so screenshots are based on UI7. I’m not familiar with other versions.

In your controller go to apps → develop apps → create device
device_type: urn:schemas-micasaverde-com:device:PowerMeter:1
device_file: D_PowerMeter1.xml
device_json: D_PowerMeter1.json

After you’ve created the device and go to the properties of the device it should look like my attached screenshot.

Once you have the device you can populate it with values. A powermeter device has 2 variables (Watts and KWH) which you can manually populate with values.

Use a http request like this to changes the values

http://VERAIP:3480/data_request?id=lu_action&DeviceNum=99&id=variableset&serviceId=urn:micasaverde-com:serviceId:EnergyMetering1&Variable=Watts&Value=1000

Change VERAIP to the ip of your controller. Change DeviceNum value in your powermeter device ID. Send 2 of these requests (Variable=Watts and Variable=KWH). Et voila, thats it.
In my case it was just some extra lines in my current pvupload script.

Thanks again Wekke for your helpful instructions.
I have created a Power Meter device OK now!

It’s the script I’m struggling with as I don’t have an existing upload script - or much of a clue about how to create one.
Do you know how I call the the data request from Vera to PVOutput to populate the new device with current values?

My scripts are running on a computer not on the vera controller. If you want to run this from your Vera controller you have to write some luup code but I’m not a luup specialist. I hope someone else can jump in to help you on that.

But I can point you in the right direction. What I think you have to do is the following.

  • create a scene which runs every X minutes.
  • write some luup code in the scene to get the PVoutput info needed. I think you have search on this forum for luup.inet.wget to find some example code. See help for pvoutput api (Help)
  • write the collected values in your powermeter(s).

I hope some luup specialists are reading this thread and can help with some example code.

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]

Hi a-lurker

I’ve just tested your code and it works like a charm. :slight_smile: :slight_smile:

Thanks for helping out here.

Thank you a-lurker. That is very kind of you to do this.

I have run the code with the correct variables and it gets the PVOutput content but doesn’t seem to write it to the PowerMeter device (#158).

50 12/03/15 18:54:23.023 luup_log:0: TestingPVOuputGetStatus debug: status code was 0 50 12/03/15 18:54:23.023 luup_log:0: TestingPVOuputGetStatus debug: content is 20151203,18:50,26660,0,28874,1854,NaN,33.4,245.4
With the power meter device, do I need to create variables in Advanced/New Service for ‘Watts’ and ‘KWH’? They are already showing on the control screen but I expected them to be in the device variables screen too.

Did you uncomment the lines that do the writes. I left them commented out to avoid scribbling over stuff, not of your choosing. So for example this lines need to be uncommented.

--luup.variable_set(ENERGY_METER_SID, 'KWH', tostring(tonumber(dataValue)/1000.0), ENERGY_METER_ID) --luup.variable_set(ENERGY_METER_SID, 'Watts', dataValue, ENERGY_METER_ID)

Ahh - That’s it!
Thank you again. Extremely helpful.

Here it is!
It’s night time so no solar generation right now.
Once again. Thank you so much.

Just found this thread - great info! I’ll try to implement this in the next few weeks.

Wekke, as a matter of interest, how are you tracking gas and water usage???

Hi Jamac,

I use a “Flukso” device for my electricity, gas and water consumption. I use a script to scrape the data from the Flukso API an I upload it to PVoutput together with my solar panels data.
The Flukso device is compatible with pvoutput so you don’t really need a script to upload. The development is done by one guy and the platform is not very alive, but it does the job.
For water readings I use the probe from the website. For gas readings I use an optical sensor for reading the reflection (1 rotation = 1 pulse) part of the last digit on the gasmeter.

More info on [url=https://www.flukso.net/]https://www.flukso.net/[/url]

But I guess there are better solutions…

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.

Hi a-lurker. I finally got around to obtaining the API for my (Fronius) inverter.

The URL to get the solar values is:

http://myInverterIP/solar_api/v1/GetPowerFlowRealtimeData.fcgi
Which returns the following (note it’s still early morning here, so not much sunlight yet):

{ "Body" : { "Data" : { "Inverters" : { "1" : { "DT" : 76, "E_Day" : 111.5, "E_Total" : 16871438, "E_Year" : 10209453, "P" : 510 } }, "Site" : { "E_Day" : 111.5, "E_Total" : 16871438, "E_Year" : 10209453, "Meter_Location" : "grid", "Mode" : "meter", "P_Akku" : null, "P_Grid" : 47.909998929128051, "P_Load" : -557.90999892912805, "P_PV" : 510, "rel_Autonomy" : 91.412593604508217, "rel_SelfConsumption" : 100 }, "Version" : "10" } }, "Head" : { "RequestArguments" : {}, "Status" : { "Code" : 0, "Reason" : "", "UserMessage" : "" }, "Timestamp" : "2017-12-16T05:39:55+10:00" } }
The variables needed for the solar meter are:
‘P_PV’ Watts
‘E_Day’ Wh

and for the house consumption meter:
‘P_Load’ Watts

I can’t work out what the accumulated daily energy usage is. I can use the PVOutput script you wrote to update that I guess.

Could I ask for your help once again to write the lua code for a scene to populate the Vera power meter device with this realtime inverter solar production and smart meter consumption data?

This might be easier.
Using the great SiteSensor plugin, I just managed to extract all the values I need into device properties. PLEG sees them. They update every 60 seconds.

[1] 10635 (Daily Solar Energy - kWh)
[2] 367.38999178819 (Current Grid Power - W)
[3] -5409.3899917882 (House Power Consumption - W)
[4] 5042 (Solar Production - W)

What’s the easiest way to get these values and labels displayed and updated on the Vera dashboard?
How would I remove all the extra decimal places when displaying?

I answered my own question.
Virtual Panel Plugin made it easy (although it doesn’t render properly on the Vera iOS app). Thanks to a-lurker and the authors of SiteSensor and Virtual Panel plugins!

I posted to 2 other strings in this forum but I think that collectively you guys are closest to doing what I want to do. I really liked the preceding post showing the type of data that I would like to display on my Vera dashboard from my inverter and soon to be installed power meters. In addition, I would like to add 2 more fields if possible, exported power and energy. I have to export limit my inverter to 6 kW in order to keep my NEM (long story). I need to query the exported power value and use it to trigger a program logical event.
Has anyone written an app to collect and display the data in the preceding post? Maybe it could be an enhancement to the Solar Meter app.
Else, I guess my only option is to try to copy the actions taken by other posters in this string but for me that would be very challenging.
Thanks for any comments or suggestions.