[powershop-developers] Google Power Meter

208 views
Skip to first unread message

ziglionz

unread,
May 24, 2010, 7:32:56 PM5/24/10
to Powershop Developers
Hello everyone,

I've spent a few evenings to see if I could build a gadget displaying
meter data from Powershop.
This gadget could be embedded into Gmail (a Gmail Contextual Gadget)
and triggered by alerts from Powershop.
Alternatively one could add it to the iGoogle page.
I've also started looking at the Google Power project to see if I
could reuse some of their stuff.
I stumbled upon this interesting project: http://www.ladyada.net/make/tweetawatt/powermeter.html
(the rest is full of other stuff by made a very clever and very
ingenuous engineer).

So I've added Google Powermeter to my iGoogle via Tweet-a-watt and
downloaded python scripts from their and Google's site:
http://www.ladyada.net/make/tweetawatt/download.html

Now my goal is to get some data from Powershop and feed it into Google
Powermeter. The Python scripts are easy to read and I could convert
some to Java but I'd rather wait for Google to provide their
powermeter Api in Java.

That's all for now, I just wanted to share a few resources.

See also
http://code.google.com/apis/powermeter/docs/getting_started.html

Emanuele

--
You received this message because you are subscribed to the Google Groups "Powershop Developers" group.
To post to this group, send email to powershop-...@googlegroups.com.
To unsubscribe from this group, send email to powershop-develo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/powershop-developers?hl=en.

Ari Sargent

unread,
May 24, 2010, 8:10:20 PM5/24/10
to Powershop Developers
Funnily enough I have also been tinkering with PowerMeter. A bout 10
days ago I built a real quick and dirty "hack" that takes data from
the Powershop API and feeds it to the Google PowerMeter API (I have
essentially set up my Powershop account as a "device").

I tried a few things, and it seems PowerMeter likes to receive regular
data, so what I do is regularly send the Powershop "Estimated
Reading" (as I don't have a smart meter). I originally set this up to
send these readings every hour, but the charts looked really odd. So I
now send the data at 8am, 8pm and noon and midnight. This allows me to
enter meter readings in the morning and evening so that the Powershop
estimates are pretty close the actual read. This works better, but
PowerMeter has some sort of smarts in it to derive the "always on"
consumption that still looks a bit odd. The daily values that are
plotted as part of the weekly and monthly data look fine though.

Like I said, a quick and dirty hack, but it works and I will be
interested to see whether the PowerMeter data settles down as I build
up a history. I'd love to see what you come up with.

Ari.

On May 25, 11:32 am, ziglionz <zigli...@gmail.com> wrote:
> Hello everyone,
>
> I've spent a few evenings to see if I could build a gadget displaying
> meter data from Powershop.
> This gadget could be embedded into Gmail (a Gmail Contextual Gadget)
> and triggered by alerts from Powershop.
> Alternatively one could add it to the iGoogle page.
> I've also started looking at the Google Power project to see if I
> could reuse some of their stuff.
> I stumbled upon this interesting project:http://www.ladyada.net/make/tweetawatt/powermeter.html
> (the rest is full of other stuff by made a very clever and very
> ingenuous engineer).
>
> So I've added Google Powermeter to my iGoogle via Tweet-a-watt and
> downloaded python scripts from their and Google's site:http://www.ladyada.net/make/tweetawatt/download.html
>
> Now my goal is to get some data from Powershop and feed it into Google
> Powermeter. The Python scripts are easy to read and I could convert
> some to Java but I'd rather wait for Google to provide their
> powermeter Api in Java.
>
> That's all for now, I just wanted to share a few resources.
>
> See alsohttp://code.google.com/apis/powermeter/docs/getting_started.html

ziglionz

unread,
May 24, 2010, 8:28:10 PM5/24/10
to Powershop Developers
well done!

as far as I understand Powermeter interpolates your data and maybe
that doesn't work very well.
Also there are some other factors that may affect the measurement,
such as unit and uncertainty. From tweet-a-watt code:

powerMeterVariable = powerMeterPath + ".d1"
powerMeterLog_level = 1
powerMeterUnit = units.KILOWATT_HOUR
#powerMeterUnit = units.JOULE #Use the Joule (W*sec) as the unit
powerMeterUncertainty = 0.001
powerMeterTime_uncertainty = 1
powerMeterDurational = True
powerMeterLast_time = time.time()

#Create a google_meter object
powerMeter = google_meter.Meter(
powerMeterService,
powerMeterVariable,
powerMeterUncertainty * powerMeterUnit,
powerMeterTime_uncertainty,
powerMeterDurational,
powerMeterLast_time)



On May 25, 12:10 pm, Ari Sargent <ari.sarg...@powershop.co.nz> wrote:
> Funnily enough I have also been tinkering with PowerMeter. A bout 10

Ari Sargent

unread,
May 24, 2010, 11:09:37 PM5/24/10
to Powershop Developers
Yeah, it could be an interpolation thing. There was also definitely
some resolution issues. The Powershop API only provides integer values
for meter reading data - one of the issues I had (particularly
overnight) was that my consumption sits between 1 and 2 units per
hour, when I was supplying hourly data I got a zig-zag effect with
every second hour being 1 unit and every other hour being 2 units.
Reducing the frequency of update obviously eliminated this effect. The
other issue I noticed was that if my estimated consumption was wrong
(which it invariably is over a short timeframe) when I entered a meter
reading PowerMeter took the full effect of the "correction" in the
hour the data was supplied - sometimes the correction is negative too.
Again, over a longer timeframe this effect is damped.

I really didn't intend spending too much time on it at this stage, I
was really just testing the feasibility of linking Powershop to
PowerMeter. I think for Powershop customers without smart meters
Powermeter will only really be useful down to the daily consumption
level, but for customers with smart meters (or even day/night meters)
it should be possible to feed time-of-use data ultimately.

ziglionz

unread,
May 25, 2010, 1:44:01 AM5/25/10
to Powershop Developers

Felix

unread,
May 25, 2010, 2:10:46 AM5/25/10
to Powershop Developers
Cool, definitely looking forward to this.
Felix

On May 25, 11:32 am, ziglionz <zigli...@gmail.com> wrote:
> Hello everyone,
>
> I've spent a few evenings to see if I could build a gadget displaying
> meter data from Powershop.
> This gadget could be embedded into Gmail (a Gmail Contextual Gadget)
> and triggered by alerts from Powershop.
> Alternatively one could add it to the iGoogle page.
> I've also started looking at the Google Power project to see if I
> could reuse some of their stuff.
> I stumbled upon this interesting project:http://www.ladyada.net/make/tweetawatt/powermeter.html
> (the rest is full of other stuff by made a very clever and very
> ingenuous engineer).
>
> So I've added Google Powermeter to my iGoogle via Tweet-a-watt and
> downloaded python scripts from their and Google's site:http://www.ladyada.net/make/tweetawatt/download.html
>
> Now my goal is to get some data from Powershop and feed it into Google
> Powermeter. The Python scripts are easy to read and I could convert
> some to Java but I'd rather wait for Google to provide their
> powermeter Api in Java.
>
> That's all for now, I just wanted to share a few resources.
>
> See alsohttp://code.google.com/apis/powermeter/docs/getting_started.html

Ari Sargent

unread,
May 25, 2010, 3:44:02 PM5/25/10
to Powershop Developers

ziglionz

unread,
May 25, 2010, 6:10:01 PM5/25/10
to Powershop Developers
I can see on the 24th you turned the espresso machine on! :-)

On May 26, 7:44 am, Ari Sargent <ari.sarg...@powershop.co.nz> wrote:
> indeed -http://groups.google.com/group/powershop-developers/web/PowerMeter.png
>

Ari Sargent

unread,
May 25, 2010, 8:29:04 PM5/25/10
to Powershop Developers
yeah, and anything else that would keep us warm :)

ziglionz

unread,
May 30, 2010, 11:43:06 AM5/30/10
to Powershop Developers
Hi everyone,

finally I've managed to get something going in Python, this time. It's
probably not different from what Ari has written.
Once our smart meter starts sending data (or rather powershop starts
processing it) I'm planning to update the usage as often as possible.

Anyway, here's my 0.1 version, based on tweet-a-watt and other random
code


#!/usr/bin/env python
import time, datetime, sys
import socket
import google_meter
import rfc3339
import units
import httplib
import oauth2
import json

QUIET = False
DEBUG = True

#Obtain your Google PowerMeter token: http://www.ladyada.net/make/tweetawatt/powermeter.html
powerMeterToken = "TOKEN HERE"
powerMeterPath = "PATH HERE"
powerMeterVariable = powerMeterPath + ".d1"
powerMeterLog_level = 1
powerMeterUnit = units.KILOWATT_HOUR
powerMeterUncertainty = 0.001
powerMeterTime_uncertainty = 1
powerMeterDurational = True
powerMeterLast_time = time.time()

powerMeterLog = google_meter.Log(powerMeterLog_level)
powerMeterService = google_meter.Service(powerMeterToken, "https://
www.google.com/powermeter/feeds", log=powerMeterLog)
#powerShopService = google_meter.Service(powerShopToken,
powerShopApi )

#Create a google_meter object
powerMeter = google_meter.Meter(
powerMeterService,
powerMeterVariable,
powerMeterUncertainty * powerMeterUnit,
powerMeterTime_uncertainty,
powerMeterDurational,
powerMeterLast_time)

#Powershop details
psApiSecret = "POWER SHOP API SECRET HERE"

#you can get consumer token and secret from my other app
http://powershop.emanueleziglioli.it
psConsumerToken = ""
psTokenSecret = ""

psAccessToken = oauth2.Token( psConsumerToken, psTokenSecret )
psConsumer = oauth2.Consumer( psConsumerToken, psApiSecret )

signature_method = oauth2.SignatureMethod_HMAC_SHA1()
connection = httplib.HTTPSConnection("secure.powershop.co.nz")

psApiUrl = "https://secure.powershop.co.nz/external_api/v1/"
psCustomerUrl = "customer.js"


def fetch_response(oauth_request, connection, debug=False):
url = oauth_request.to_url()
connection.request( oauth_request.method, url )
response = connection.getresponse()
s = response.read()
if DEBUG:
print 'requested URL: %s' % url
print 'server response: %s' % s
return s

def get_location( locUrl ):
oauth_request = oauth2.Request.from_consumer_and_token(
psConsumer, token=psAccessToken, http_url=psApiUrl+locUrl
)
oauth_request.sign_request(signature_method, psConsumer,
psAccessToken)
jsres = fetch_response(oauth_request, connection)
return json.loads(jsres)

# the 'main loop' runs once a second or so... TODO change to a set
interval
def update(idleevent):
global avgwattdataidx, sensorhistories, twittertimer, DEBUG

# Determine the minute of the hour (ie 6:42 -> '42')
currminute = (int(time.time())/60) % 10
# Figure out if its been five minutes since our last save
if (currminute % 1 == 0):
currPowerMeter_Update_Time = time.time()

# Print out debug data, Wh used in last 5 minutes
customerjs = get_location( psCustomerUrl );
last_reading_value = customerjs['result']['properties'][0]
['registers'][0]['last_reading_value']

#Send it to GooglePowerMeter (TODO if different, also get time
from reading):
try:
powerMeter.PostIntervalReading(
last_reading_value * powerMeterUnit )
#powerMeterUncertainty * powerMeterUnit,
#powerMeter.last_read_time,
#currPowerMeter_Update_Time )

except (IOError, socket.error), e:
print '-- %s: %s' % (e.__class__.__name__, e)

while True:
update(None)

ziglionz

unread,
Jun 7, 2010, 10:15:12 PM6/7/10
to Powershop Developers
Google Power Meter presentation from Google IO:
http://code.google.com/events/io/2010/sessions/google-powermeter-api.html
> powerMeterService = google_meter.Service(powerMeterToken, "https://www.google.com/powermeter/feeds", log=powerMeterLog)
> #powerShopService = google_meter.Service(powerShopToken,
> powerShopApi )
>
> #Create a google_meter object
> powerMeter = google_meter.Meter(
>     powerMeterService,
>     powerMeterVariable,
>     powerMeterUncertainty * powerMeterUnit,
>     powerMeterTime_uncertainty,
>     powerMeterDurational,
>     powerMeterLast_time)
>
> #Powershop details
> psApiSecret = "POWER SHOP API SECRET HERE"
>
> #you can get consumer token and secret from my other apphttp://powershop.emanueleziglioli.it
Reply all
Reply to author
Forward
0 new messages