[!NOTE] >
Watt-time
is a community plugin and not a part of the IF standard library. As a result, the IF core team does not closely monitor these plugins for updates. It is recommended to conduct your own research before implementing them.
WattTime technology—based on real-time grid data, cutting-edge algorithms, and machine learning—provides first-of-its-kind insight into your local electricity grid’s marginal emissions rate. Read More...
The WattTimeGridEmissions
plugin is designed to compute the average carbon emissions of a power grid over a specified duration. It leverages data from the WattTime API to furnish carbon intensity information for precise locations and timeframes. This plugin proves beneficial for applications requiring carbon footprint monitoring or optimization, such as energy management systems or environmental impact assessments. The plugin supports only v3 version of the WattTime API. The API returns data in lbs/MWh
, which the plugin converts to Kg/MWh
(g/KWh) by dividing by 0.453592
.
WattTime API requires activation of subscription before usage. Please refer to the WattTime website for more information.
Before utilizing this plugin, ensure the following prerequisites are fulfilled:
- Environment Variables: The plugin requires environment variables
WATT_TIME_USERNAME
andWATT_TIME_PASSWORD
to be set. These credentials are utilized for authentication with the WattTime API.
Required Parameters:
WATT_TIME_USERNAME: <your-username>
WATT_TIME_PASSWORD: <your-password>
Optional Parameter:
WATT_TIME_TOKEN: <your-token>
- Dependencies: Confirm the installation of all required dependencies, including
luxon
andzod
. These dependencies are imperative for date-time manipulation and input validation, respectively.
To employ the WattTimeGridEmissions
plugin, adhere to these steps:
-
Initialize Plugin: Import the
WattTimeGridEmissions
function and initialize it with optional global configuration parameters. -
Execute Plugin: Invoke the
execute
method of the initialized plugin instance with an array of input parameters. Each input parameter should include atimestamp
,duration
, and eithergeolocation
,cloud/region-wt-id
, orcloud/region-geolocation
information. -
Result: The plugin will return an array of plugin parameters enriched with the calculated average carbon intensity (
grid/carbon-intensity
) for each input.
The plugin expects the following input parameters:
timestamp
: A string representing the start time of the query period.duration
: A number indicating the duration of the query period in seconds.geolocation
: A string representing the latitude and longitude of the location in the formatlatitude,longitude
. Alternatively, this information can be provided throughcloud/region-geolocation
orcloud/region-wt-id
parameters.cloud/region-geolocation
: Similar togeolocation
, with calculations performed by thecloud-metadata
plugin.cloud/region-wt-id
: A string representing the region abbreviation associated with the location (e.g., 'CAISO_NORTH').signal-type
: A string representing the signal type of the selected region (optional) (e.g., 'co2_moer').
The plugin enriches each input parameter with the average carbon intensity (grid/carbon-intensity
) calculated over the specified duration.
The plugin conducts input validation using the zod
library and may throw errors if the provided parameters are invalid or if there are authentication or data retrieval issues with the WattTime API.
-
Initialization: Authenticate with the WattTime API using the provided credentials. If the
token
is not provided in the environment variables, it usesusername
andpassword
, otherwise, it throws an error. To authenticate users, the plugin utilizes thehttps://api.watttime.org/login
URL. -
Execution:
-
Iterate through each input.
- If
cloud/region-wt-id is provided
, the plugin sets it toregion
, renamessignal-type
tosignal_type
, and sends a request tohttps://api.watttime.org/v3/forecast/historical
endpoint with calculatedstart
andend
time as well. If thesignal_type
is not provided, the plugin requestshttps://api.watttime.org/v3/my-access
to obtain access to the account and takes the first signal type from there. - If
geolocation
is provided, the plugin converts it to alatitude
andlongitude
pair, renamessignal-type
tosignal_type
, and sends a request tohttps://api.watttime.org/v3/region-from-loc
to retrieve theregion
. Then thehttps://api.watttime.org/v3/forecast/historical
endpoint is called withregion
,signal_type
, calculatedstart
andend
time fromtimestamp
andduration
.
- If
-
Validate input parameters. If
cloud/region-geolocation
is provided, thegeolocation
is overridden. Ifcloud/region-wt-id
is provided, it takes precedence over thegeolocation
. -
Retrieve WattTime data for the specified duration. The WattTime API adds aggregated emissions for every 5 minutes. To address this limitation, the plugin sets the previous emission's value if the specified
duration
is less than 5 minutes. -
Calculate average emissions based on retrieved data. The WattTime API returns full data for the entire duration; the plugin checks if the data's period time is within the specified input range and collects data in
kgMWh
.
-
-
Output: Return results with the average grid emissions for each input.
// Initialize the plugin
const plugin = WattTimeGridEmissions();
// Execute the plugin with input parameters
const inputs = [
{
timestamp: '2024-03-26T12:00:000Z',
duration: 3600, // 1 hour
geolocation: '36.7783,-119.417931', // San Francisco, CA
},
// Add more input parameters as needed
];
const result = await plugin.execute(inputs);
console.log(result);
name: watt-time
description: simple demo invoking watt-time
tags:
initialize:
plugins:
watt-time:
method: WattTimeGridEmissions
path: '@grnsft/if-unofficial-plugins'
outputs:
- yaml
tree:
children:
child:
pipeline:
- watt-time
inputs:
- timestamp: '2024-03-05T00:00:00.000Z'
duration: 3600
geolocation: 36.7783,-119.417931
name: watt-time
description: simple demo invoking watt-time
tags: null
initialize:
plugins:
watt-time:
path: '@grnsft/if-unofficial-plugins'
method: WattTimeGridEmissions
outputs:
- yaml
tree:
children:
child:
pipeline:
- watt-time
inputs:
- timestamp: '2024-03-05T00:00:00.000Z'
duration: 3600
geolocation: 36.7783,-119.417931
outputs:
- timestamp: '2024-03-05T00:00:00.000Z'
duration: 3600
geolocation: 36.7783,-119.417931
grid/carbon-intensity: 287.7032521512652
You can execute this by passing it to ie
. Run the impact using the following command from the project root:
npm i -g @grnsft/if
npm i -g @grnsft/if-unofficial-plugins
ie --manifest ./examples/manifests/test/watt-time.yml --output ./examples/outputs/watt-time.yml