Author Topic: PVOUtput.Org integration  (Read 4523 times)

Offline delbz

  • Sr. Newbie
  • *
  • Posts: 32
  • Karma: +0/-0
PVOUtput.Org integration
« on: November 21, 2015, 06:28:24 pm »
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:
https://pvoutput.org/list.jsp?id=28907&sid=45948

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?
« Last Edit: December 15, 2017, 01:28:31 pm by delbz »

Offline Wekke

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #1 on: November 22, 2015, 04:53:44 am »
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.
« Last Edit: November 22, 2015, 05:02:19 am by Wekke »

Offline delbz

  • Sr. Newbie
  • *
  • Posts: 32
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #2 on: November 27, 2015, 01:48:56 am »
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?

Offline Wekke

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #3 on: November 30, 2015, 05:03:02 am »
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.
« Last Edit: November 30, 2015, 05:08:35 am by Wekke »

Offline delbz

  • Sr. Newbie
  • *
  • Posts: 32
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #4 on: November 30, 2015, 02:04:32 pm »
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?


Offline Wekke

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #5 on: December 01, 2015, 01:14:23 pm »
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 (http://www.pvoutput.org/help.html#api-getstatus)
- write the collected values in your powermeter(s).

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

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 831
  • Karma: +57/-8
Re: PVOUtput.Org integration
« Reply #6 on: December 01, 2015, 05:46:50 pm »
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: [Select]
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
« Last Edit: December 02, 2015, 03:44:55 pm by a-lurker »

Offline Wekke

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #7 on: December 02, 2015, 12:50:57 pm »
Hi a-lurker

I've just tested your code and it works like a charm.  :) :)

Thanks for helping out here.

Offline delbz

  • Sr. Newbie
  • *
  • Posts: 32
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #8 on: December 03, 2015, 04:10:11 am »
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).

Code: [Select]
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.

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 831
  • Karma: +57/-8
Re: PVOUtput.Org integration
« Reply #9 on: December 03, 2015, 04:16:18 am »
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.

Code: [Select]
--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)
« Last Edit: December 03, 2015, 05:26:16 am by a-lurker »

Offline delbz

  • Sr. Newbie
  • *
  • Posts: 32
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #10 on: December 03, 2015, 04:34:32 am »
Ahh - That's it!
Thank you again. Extremely helpful.

Offline delbz

  • Sr. Newbie
  • *
  • Posts: 32
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #11 on: December 03, 2015, 04:55:05 am »
Here it is!
It's night time so no solar generation right now.
Once again. Thank you so much.

Offline jamac

  • Jr. Member
  • **
  • Posts: 73
  • Karma: +0/-1
Re: PVOUtput.Org integration
« Reply #12 on: November 28, 2016, 02:22:35 pm »
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???

Offline Wekke

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #13 on: November 29, 2016, 12:18:30 pm »
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 https://www.flukso.net/

But I guess there are better solutions...

Offline delbz

  • Sr. Newbie
  • *
  • Posts: 32
  • Karma: +0/-0
Re: PVOUtput.Org integration
« Reply #14 on: December 15, 2017, 01:27:15 pm »
Quote
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):
Code: [Select]
{
   "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?
« Last Edit: December 15, 2017, 02:52:24 pm by delbz »