Skip to main content

Python client for the WattTime API

Project description

Description

This project encapsulates calling the WattTime API in order to get marginal operating emissions rate (MOER) for power use at a certain lattitude and longitude. It does this by mapping the coordinates to a balancing authority (or power grid), and tracking the emissions of each of those grids. WattTime's MOER is provided in pounds of of emissions per megawatt-hour (e.g. CO2 lbs/MWh). It represents the emissions rate of the electricity generators which are responding to changes in load on the local grid at a certain time. More information on how they produce marginal emissions rates can be found on their methodology page. While the actual CO2 lbs/MWh is provided only by paid API access, they do provide free access to an index value. From this users can infer the result of power use at this moment; if the MOER index value is 33%, for instance, the grid's emissions are cleaner than usual right now. A value of 100% means that the grid is emitting more than it has at any point in the previous 30 days. You can think of this as "using cleaner power", though it may be more correct to think of it in the terms of "if I use power right now, am I likely to move the grid towards higher emissions".

WattTime provides their own Python client, which this library is inspired by. One benefit of their client is that it provides a means for registration, and in fact may be the easiest way to register for the free use of WattTime's API (as they don't currently provide registration via the web). Their example code isn't available as a python package, however, and I wanted to add some niceties such as using environment variables for username, password, lattitude and longitude.

Using the client to obtain a MOER index

Usage is geared towards quickly obtaining the MOER index for a given lattitude and longitude. To use the client and provide these via environment variables, set up the environment variables, then run the code.

Setting environment variables

export WATTTIMEUSERNAME=<your watttime username>
export WATTTIMEPASSWORD=<your watttime password>
export LATT=<lattitude where you will be using power>
export LONG=<longitude where you will be using power>

Executing the client

from simplemoer import WattTime

wt=WattTime()
index=wt.get_index()
print(f"index: {index}")

Example results

Running the example code for my given lattitude and longitude, the WattTime client will acquire my balancing authority as IESO_NORTH. Results for this point in time indicate the grid's moer value is 49%. This index value is valid for 300 seconds from this point in time, as indicated by the freq and point_time values.

% python example.py
index: {'ba': 'IESO_NORTH', 'freq': '300', 'percent': '49', 'point_time': '2022-10-22T13:15:00Z'}

Use case

I often use this client building python scripts related to IoT and home automation. I'm often turning on or off a device, and it might be a device where it wouldn't hurt anything to wait 5 minutes. So I will often query the MOER index value and compare it against a maximum MOER value; often 50 in my case. So, instead of turning on an infrared heating panel, or a dehumidifier, as soon as conditions warrant it (for instance the room is reaching a temperature that's too cool), I might compare the current MOER index against the maximum MOER and choose to delay turning on the heating panel or dehumidifier. For example in the case of a thermostat turning on and off a heating source, if the MOER value is over 50 I might subtract 1 or 2 degrees celcius from the desired temperature. In that way as soon as energy is greener we can go back to warming up the room, and if we don't get such favorable power conditions we will eventually heat up the room, just perhaps not as quickly, and to a lower temperature. When power is cleaner again, we'll go ahead and warm the room to the desired temperature (or possibly even a degree higher).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplemoer-0.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplemoer-0.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file simplemoer-0.0.1.tar.gz.

File metadata

  • Download URL: simplemoer-0.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.15

File hashes

Hashes for simplemoer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f76db8126921781ee717187ea1f1fdfe17f416e34f083eab9aea128bfee086fd
MD5 079f612f042e1349df54cdb24e592ae4
BLAKE2b-256 83e86dd592cad590183b8dad7b1d9cc7ad95cd4010a072fe4def276006c7cb23

See more details on using hashes here.

File details

Details for the file simplemoer-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: simplemoer-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.15

File hashes

Hashes for simplemoer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a6f819fd1d49a25051ee6ef4a89001d9c15658465bff1b7a357839dfc03b5a9
MD5 1c8cf4b029672b4a544e81cd1b8819ae
BLAKE2b-256 3e26260e3e328553c844050218063c4e8a7aeeccaa9e84c26b32a3a9a1a4583b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page