Author Topic: Working PlotWatt integration script  (Read 12863 times)

Offline patersom82

  • Sr. Newbie
  • *
  • Posts: 42
  • Karma: +1/-1
Re: Working PlotWatt integration script
« Reply #15 on: August 11, 2014, 04:35:38 pm »
I did contact them & they said it took a few weeks to show up.  I'm at about 5 weeks now though & it's still the same.  I'll hit them again & see what they say.

Awesome.  I dropped them a note and didn't hear anything back... so would be interested to find out what they say

Offline bigmaxy

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: Working PlotWatt integration script
« Reply #16 on: August 22, 2014, 02:46:46 am »
Just wanted to say thanks for this script.  :)

Edit....Few days later after using it for a month.

Has anyone had problems with getting the data to upload to plotwatt. I've not had anything new appear since 21st August.
Have recreated everything except for getting a new API key.

Cheers.
« Last Edit: August 24, 2014, 01:43:40 am by bigmaxy »

Offline fullmoonguru

  • Full Member
  • ***
  • Posts: 166
  • Karma: +0/-1
Re: Working PlotWatt integration script
« Reply #17 on: September 17, 2014, 04:45:36 pm »
They let me know they'd look into it, then did & let me know it was up.  I think the reporting could use improvements as far as different options, colors, & stuff, but it's pretty cool.  The next step is to check the accuracy, both of my meter and the disaggregation.

Here are some screen shots:


Offline winebob

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: Working PlotWatt integration script
« Reply #18 on: October 23, 2014, 10:41:24 am »
Thanks for this flaquito, it's working great for me.  Any way you could share the Bidgely code yet?  I'd like to compare the two services.

Offline NAC

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Working PlotWatt integration script
« Reply #19 on: November 03, 2014, 06:04:32 am »
I also decided that sleep wasn't all that important last night, and tackled the Bidgely API. I have functional -- but nasty -- code. I need to rework and clean it before I post it, but I'm now sending my data to both services, and will be able to compare the two.

Hi flaquito. Thanks a lot for you work !!!!
I also did a little script to upload the data into Bidgely web.

Code: [Select]
timeNow = os.time()
meterValueICP = luup.variable_get(serviceId_Energy, serviceVar_Watts, deviceId_ICP)

XML_DATA = [[
<upload version="1.0">
   <meters>
      <meter id="11:22:33:44:55:66" model="API" type="0" description="NAC API">
         <streams>
            <stream id="InstantaneousDemand" unit="W" description="Real-Time Demand">
               <data time="]] .. timeNow .. [[" value="]] .. meterValueICP .. [["></data>
            </stream>
         </streams>
      </meter>
   </meters>
</upload>]]

local response, status, header  = http.request{
   method = "POST",
   url = BG_URL,
   headers = {["Content-Type"] = "application/xml"},

   headers = {
      ["Content-Type"] = "application/xml",
      ["Content-Length"] = string.len(XML_DATA)
   },
   source = ltn12.source.string(XML_DATA),
   sink = ltn12.sink.table(response_body)
}

BTW anyone know how to create a virtual energy meter device?

Offline victorb17

  • Jr. Member
  • **
  • Posts: 63
  • Karma: +0/-0
Re: Working PlotWatt integration script
« Reply #20 on: November 26, 2014, 10:47:57 am »
Is it possible to send individual lighting loads to plotwatt?  I didn't see a way on their site.   

The idea is that we could look back and say:  well the outside lighting is costing this much, and the bar lights cost this much, etc.

Offline NAC

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Working PlotWatt integration script
« Reply #21 on: December 01, 2014, 07:52:29 am »
Is it possible to send individual lighting loads to plotwatt?  I didn't see a way on their site.   

The idea is that we could look back and say:  well the outside lighting is costing this much, and the bar lights cost this much, etc.

Yes.
You have to add a new meter
https://plotwatt.com/docs/api

So you can use 2,3,4 ... meters and send the watt info using the needed meter id.
The only problem is that I do not know how get separated money info for each meter.

Offline Atman

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: Working PlotWatt integration script
« Reply #22 on: December 19, 2014, 04:54:17 am »
Very interesting, nice work!! Please give a review about the analysis from PlotWatt when you have some thing ;)

Thanks! I'll definitely do that.

I also decided that sleep wasn't all that important last night, and tackled the Bidgely API. I have functional -- but nasty -- code. I need to rework and clean it up before I post it, but I'm now sending my data to both services, and will be able to compare the two.

How did it go with your code? Did it work and how was the difference between bidgely and plotwatt? Is it possible to get your script?
Thanks!

Offline pdenbigh

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: Working PlotWatt integration script
« Reply #23 on: December 30, 2014, 04:33:02 pm »
Anyone know if this works with UI7?  I've followed the steps to a T, but PlotWatt isn't showing "no_connection" under "Current Status".  When I go to "View" the luup file in Vera, I get the error "error on line 1 at column 1: Document is empty"

Can you confirm that the device ID does not need the ' ' around it?  Also, does the API code need the quotes? 

Thank you!

Peter

Offline flaquito

  • Jr. Member
  • **
  • Posts: 65
  • Karma: +3/-0
Re: Working PlotWatt integration script
« Reply #24 on: January 10, 2015, 01:45:32 pm »
Hey all, sorry I've completely disappeared -- my energy meter stopped reading properly, and I haven't had time to work on that. At any rate, several of you have asked about the Bidgely script I put together. Since it's been several months, I don't really remember exactly what state it was in, but I'm pretty sure this version of the script was working. Here it is, presented as-is, with no guarantee of functionality. Have fun!
« Last Edit: January 10, 2015, 02:31:08 pm by flaquito »

Offline FireBird

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +2/-0
Re: Working PlotWatt integration script
« Reply #25 on: January 11, 2015, 08:38:36 am »
flaquito,

Thank you for posting your Bidgely API code, it's working great for me. I did have to make a few minor changes, shown below.


Your code:  local B_URL = "http://api.bidgely.com/v1/users/" .. B_KEY .. "/homes/1/gateways/1/upload"

My change: local B_URL = "http://api.bidgely.com/v1/users/" .. B_KEY .. "/homes/1/gateways/5/upload"

I also decided to use Watts instead of kWh.

{node='vera', deviceId=105, serviceId='urn:micasaverde-com:serviceId:EnergyMetering1', serviceVar="Watts"},

<stream id="InstantaneousDemand" description="Power Usage" unit="W">]]

Offline dannieboiz

  • Sr. Member
  • ****
  • Posts: 381
  • Karma: +1/-2
Re: Working PlotWatt integration script
« Reply #26 on: January 12, 2015, 09:46:20 pm »
Anyone know if this works with UI7?  I've followed the steps to a T, but PlotWatt isn't showing "no_connection" under "Current Status".  When I go to "View" the luup file in Vera, I get the error "error on line 1 at column 1: Document is empty"

Can you confirm that the device ID does not need the ' ' around it?  Also, does the API code need the quotes? 

Thank you!

Peter

+1 on this,

Offline FireBird

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +2/-0
Re: Working PlotWatt integration script
« Reply #27 on: January 12, 2015, 09:54:16 pm »
Here is a snippet of the code I'm using and it is uploading to PlotWatt. But I do see a "no connection" on the current status on the Plotwatt webpage.

-- For each meter, specify the PlotWatt meter ID and Vera Device ID
PW_DEVICES = {
    {node='vera', meterId='xxxxxxx',   deviceId=105, serviceId='urn:micasaverde-com:serviceId:EnergyMetering1', serviceVar="Watts"},
  }



Offline fullmoonguru

  • Full Member
  • ***
  • Posts: 166
  • Karma: +0/-1
Re: Working PlotWatt integration script
« Reply #28 on: January 13, 2015, 09:23:20 am »
I'm not very experienced with this but I do have it working so I'll tell you what I know.

Danni, I do have this working with UI7, but I actually set it up in UI6 & then upgraded.  The device ID does not need ' ' around it.  The API key does need quotes.

FireBird, your code looks good assuming the x's you show for your meter ID are actually the numbers of you meter ID?

The thing that comes to my mind is that you might be using the wrong device ID.  Seems like there are two ID's for devices in Vera...

Here's my lua code exactly how it is except for x's in place of the numbers I'm using:

Code: [Select]
-- v1.1
-- Script for uploading data to PlotWatt
-- Visit PlotWatt.com for more information
--
-- See API documentation at https://plotwatt.com/docs/api
-- (Select Low-level details with Curl examples)


-- PlotWatt API Key
local PW_KEY = "XXXXXXXXXXXXXXXX"

-- For each meter, specify the PlotWatt meter ID and Vera Device ID
PW_DEVICES = {
    {node='vera', meterId='XXXXXX',   deviceId=XX, serviceId='urn:micasaverde-com:serviceId:EnergyMetering1', serviceVar="Watts"},
  }

-- Upload Frequency in seconds
-- The PlotWatt API specifies an upload interval of no more frequent than 60 seconds
local uploadFreq = 60

-- Extra debug messages
local DEBUG = false



-- Shouldn't need to change anything below this line
local http = require('socket.http')
http.TIMEOUT = 5

local PW_URL = "http://" .. PW_KEY .. ":@plotwatt.com/api/v2/push_readings"
local pwLog = function (text) luup.log('PlotWatt Logger: ' .. (text or "empty")) end
local lastUpload = os.time()

local powerArray = {}

local function findMeter(deviceId, serviceId, serviceVar)
  for k, v in pairs(PW_DEVICES) do
    if (v.deviceId == deviceId and
        v.serviceId == serviceId and
        v.serviceVar == serviceVar) then
      return v.node, v.meterId
    end
  end

  return nil, nil
end

local function initWatch()
  for k, v in pairs(PW_DEVICES) do
    luup.variable_watch('powerWatch', v.serviceId, v.serviceVar, v.deviceId)
  end
end

function powerWatch(deviceId, serviceId, serviceVar, oldValue, newValue)
  local nodeName, meterID = findMeter(deviceId, serviceId, serviceVar)

  if (nodeName == nil or meterID == nil) then
    pwLog(string.format("Node not found for %s,%s,%s", deviceId, serviceId, serviceVar))
    return
  end

  timeNow = os.time()

  powerArray[#powerArray + 1] = meterID
  powerArray[#powerArray + 1] = newValue/1000
  powerArray[#powerArray + 1] = timeNow

  if (DEBUG) then pwLog("Got update of " .. newValue .. " at " .. timeNow) end

  if (timeNow - lastUpload >= uploadFreq) then
    if (DEBUG) then pwLog("Updating with: " .. table.concat(powerArray,",")) end
http.request(PW_URL,table.concat(powerArray,","))
    lastUpload = timeNow
    powerArray = {}
  end
end

initWatch()

Offline dannieboiz

  • Sr. Member
  • ****
  • Posts: 381
  • Karma: +1/-2
Re: Working PlotWatt integration script
« Reply #29 on: January 18, 2015, 04:22:34 pm »
I ran the script from a linux box as shown below and I'm not getting anything. I replaced my API code with the x's. Did I do something wrong?

curl -X POST -d "number_of_new_meters=1" http://YXXXXXXXX@plotwatt.com.com/api/v2/new_meters
* Domain Sponsor Redirect<br /><br />