Working PlotWatt integration script

Since I built my own IR-based pulse meter to monitor my whole-house power usage, I started looking around for a cloud-based solution for storing and analyzing the data. I specifically wanted something with disaggregation, so that it can identify my appliances and devices. A friend of mine uses Bidgely, but that looked like it was going to be difficult to integrate with Vera. Then I stumbled across PlotWatt. It’s free for residential users, is based around their disaggregation algorithms, and offers a straightforward API.

So, here’s the script that I’m using to upload to PlotWatt. I don’t know how to write plugins, so it isn’t one. Also, a lot of credit goes to guessed for his SEG code, on which this is very heavily based.

I haven’t tested this with multiple meters, but it should work.

[size=14pt]The Directions[/size]

[ul][li]Register for an account at PlotWatt[/li]
[li]After registering, it should ask you to add a meter. Select the “PlotWatt API” option[/li]
[li]Their next instructions will take you to the PlotWatt API documentation. The documentation will have your new API key listed at the top[/li]
[li]SSH into your Vera or another Linux box. Run the command from the API for adding meters, but change the number_of_new_meters to 1:[/li][/ul]

curl -X POST -d "number_of_new_meters=1" http://YOUR_API_KEY:@plotwatt.com/api/v2/new_meters

[ul][li]Record the generated Meter ID[/li]
[li]Download the attached PlotWatt.lua[/li]
[li]Edit the file, entering your PlotWatt API key, Meter ID, and the Vera Device ID for your whole-house meter device[/li]
[li]In the Vera UI, go to Apps → Develop Apps → Luup Files[/li]
[li]On the right, click “Choose File”. Browse to and select your edited PlotWatt.lua file, and click “Go”[/li]
[li]On the left, click “Edit Startup Lua”[/li]
[li]Add the following line:[/li][/ul]

require("PlotWatt.lua")

[ul][li]Click “Go”[/li]
[li]Click “Save”[/li]
[li]Enjoy your data flowing to PlotWatt[/li][/ul]

[size=14pt]The Details[/size]

PlotWatt can handle data resolution of up to one read per second. They can accept data in batches, and don’t want data to be uploaded any more frequently than once per minute. This script keeps track of each value from the Vera meter device every time it changes, and only uploads all of the values and times to PlotWatt if it’s been more than 60 seconds since the last upload.

Very interesting, nice work!! Please give a review about the analysis from PlotWatt when you have some thing :wink:

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.

I’ve just tried this and I’m not getting any numbers over at PlotWatt. I’m wondering if it’s a problem with the device ID. I have the Aeon Labs HEM. I used the device ID for the main unit (8), but not clamps 1 & 2, which are what is actually recording the watts.

OK, actually I just tried substituting 8 with e1 (device ID for clamp one) & that didn’t change anything.

When I ran the first code in the terminal it returned this:

[934315]root@MiOS_35017007:~#

I assumed the first number to be the generated meter ID.

I barely know what’s going on with code but I did notice that the device id does not have the single quotation marks around it like the other parameters do.

Sorry, my bad. I had renamed the lua file so of course it wasn’t started. I’m getting real-time readings right now on PlotWatt. I assume the other info. will start filling in later.

Great! Glad it’s working for you.

Yeah, not sure how long it’s supposed to take before it starts providing more data, but I think it can take a couple weeks.

Not very impressed with the UI so far. I thought the simplified Ergy reporting from within Vera was better. Of course I say “was” because it’s not working at all right now - “failed to authenticate with ergy”.

Here is what I’m seeing from Plotwatt for anyone who is interested:

Hi flaquito. I’ve had a quick look at PlotWatt, and I’m really looking forward to trying it out with my VERA energy meter.

Sorry to be a complete newbie, but can you explain what you mean about changing the number_of_new_meters text in the instructions?

Thank you!

Hi flaquito. I’ve had a quick look at PlotWatt, and I’m really looking forward to trying it out with my VERA energy meter.

Sorry to be a complete newbie, but can you explain what you mean about changing the number_of_new_meters text in the instructions?

Thank you![/quote]

The PlotWatt API documentation gives you the proper curl command to create new meters, with your API key already in the URL. However, their example creates 2 new meter objects. Most likely you only need one. So, in the documentation, where it says

"number_of_new_meters=2"

change that to

"number_of_new_meters=1"

Thanks flaquito… got that working nicely now. I just need to get my Home Energy Meter reporting properly now, but that’s a whole other thread!

Patersom, which meter do you have. I just set up one of the Aeon Labs HEM’s. I might be able to save you some frustration.

Thanks fullmoonguru! Very kind. At the moment, it doesn’t look too bad. Yup, I got the Aeon Labs HEM G2 (single clamp EU model). But then I thought it would be a good idea to install dataMine (so I could check on it properly), which then lead to good idea of sharing some NAS disk space back to Vera (because I couldn’t get my USB to mount directly). None of which is quite working properly! So I’ve posted about all of this in different threads. So, long way round, as is often the case with VERA. But hopefully in a few days I’ll be ready to test my Aeon Labs HEM G2 and PlotWatt.

[quote=“fullmoonguru, post:8, topic:181840”]Not very impressed with the UI so far. I thought the simplified Ergy reporting from within Vera was better. Of course I say “was” because it’s not working at all right now - “failed to authenticate with ergy”.

Here is what I’m seeing from Plotwatt for anyone who is interested:[/quote]

My dashboard looks pretty similar… I’ve been feeding data to PlotWatt for 3 weeks now, and can’t really see anything special or like the analytics in the demo video. It is telling me how much electricity I am currently using (which I already know) and how electricity much I have been using per week or per month (which I also already know).

Has anyone had better experiences? Does it get more insightful if it has 1, 2, 3, 6 months of data?

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

Just wanted to say thanks for this script. :slight_smile:

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.

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:

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.

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

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?