Uploading Assets and Data end to end example
This example will walk you through logging in, creating an asset, and uploading savings values. In order to register assets to the WattCarbon platform, you must first go through the process of registering as a WattCarbon project developer. Contact us at support@wattcarbon.com if you are interested in registering projects.
Prerequisites
Section titled “Prerequisites”You will need credentials to access the WattCarbon API. We’ll call these EMAIL_ADDRESS and API_KEY in this example.
This example is implemented using Python’s HTTPX library but any HTTP client will work.
0. Grab the API Key
Section titled “0. Grab the API Key”Before starting with the API, you need to grab an API key from the platform. There is a unique API key for each account that your user is associated with. Each individual user has a personal account by default. We typically also create an Organizational account for companies that all users of that company are a part of. It is important to use the API key from the correct account, as this determines where the assets are loaded on the platform and what other users are able to see them.
On the upper left-side of the screen there is a WattCarbon logo and the name for the account that you are currently viewing. Upon first logging in, this will typically say ‘Personal’. If you click that, you are able to select other accounts that your user has access to.
Once you have selected the correct account, go to ‘Account Settings’ on the left-side of the screen. At the bottom, there is a place that says API Key, and under it a box that says ‘hidden’. If you click on that box, it will reveal the API key.
1. Get an access token
Section titled “1. Get an access token”Start out by converting your long-lived API token into a temporary access token. The access token is used for authenticating requests to the rest of the API and lasts only 24 hours. This process must be repeated to get a new token whenever the old one expires.
# Create a client objectimport httpxclient = httpx.Client(base_url="https://api.wattcarbon.com")client.headers["User-Agent"] = "a unique name for your app"
# Make the authentication request to the APItoken_response = client.post( "/auth/token", data={ "grant_type": "password", "username": EMAIL_ADDRESS, "password": API_KEY, })token_response.raise_for_status()
# Extract the token from the responsetoken_payload = token_response.json()token = token_payload["access_token"]
# Add the token to the client's default headers# to authenticate future requestsclient.headers["Authorization"] = "Bearer " + tokenSee the documentation for POST /auth/token for more information.
2. Create a Meter
Section titled “2. Create a Meter”Here is where you can create the objects that will hold the energy timeseries. For this endpoint, you must use manual as the apiProvider. meterType can either be gas or electricity.
The location is also required here, and this is where you can put a street address. There are a few different ways to format this field, here is an example:
"location": { "street": "606 Ellis St", "city": "San Francisco", "state": "CA", "country": "US", "postalCode": "94109"}The
locationfield can also take an object with individual fields for Street/City/State etc. or even the Latitude and Longitude of the site.
3. Upload Meter Timeseries
Section titled “3. Upload Meter Timeseries”Once you have a meter you can upload a timeseries. Depending on the granularity of the data, you will use one of the following methods to upload the CSV:
4. Create an Asset
Section titled “4. Create an Asset”Once you have meters with timeseries in them, you will create an asset using the CreateAsset endpoint. When looking at this endpoint, use the dropdown in the “kind” field and select the correct methodology - this will show the extra required fields for a certain type of asset.
Here are a few of the most commonly used entries for the kind field:
solar: Directly Measured Solarstorage_direct: Storageelectrification_eemetered: Building Electrification (meter data based).energy_efficiency_eemetered: Building Energy Efficiency (meter data based).demand_response_eemetered: Demand Response with weather-normalized baseline meter data and event data.tracking_building: Building Tracking — tracks historical consumption and compares to a reference building using an EEMeter model.vehicle_charging: Vehicle Charging.
If you have any questions about which methodology to select for your assets, reach out to support@wattcarbon.com.
The location is required again in this endpoint. This is a little redundant with the “meter” location, but the location in the asset is what is actually used to map to weather data, so its also important here.
The “meterIds” field is where you’ll want to provide the ids for any meter(s) you created earlier to attach to this asset.
If you have a unique ID for the site that you use for your own tracking, you can pass it in the
customIdfield. The API will enforce that the same custom ID is never used on multiple sites in your account.
Solar Example
Section titled “Solar Example”create_asset_response = client.post( f"/accounts/{account_id}/assets", json={ "name": "My asset", "customId": "SP123", "location": "60 Greene St Riverside IA", "utility": "ABC Utility", "meterIds": [999], "commencedOperationDate": "2022-08-01", "kind": "solar", "nameplateCapacityKw": 123, "inverterDataId": "1234", "inverterDataSource": "enphase", "externalRegistryName": "GATS", "externalRegistryAssetId": "45678" })create_asset_response.raise_for_status()Electrification Example
Section titled “Electrification Example”create_asset_response = client.post( f"/accounts/{account_id}/assets", json={ "name": "My asset", "customId": "HP123", "location": "60 Greene St Riverside IA", "utility": "ABC Utility", "meterIds": [999], "commencedOperationDate": "2022-08-01", "kind": "electrification_eemetered", "areaSqft": 1500, "previousFuel": "gas", "buildingType": "single_family_attached", "replacementType": "furnace_only", "yearBuilt": 1990, "numberOfStories": 2 })create_asset_response.raise_for_status()Demand Response Example
Section titled “Demand Response Example”create_asset_response = client.post( f"/accounts/{account_id}/assets", json={ "name": "My asset", "customId": "DR123", "location": "60 Greene St Riverside IA", "utility": "ABC Utility", "meterIds": [999], "kind": "demand_response_eemetered", })create_asset_response.raise_for_status()
asset_id = create_asset_response.json()["id"]For demand response, in addition to the meter data we also need a list of when the events took place.
For this, you can use the UploadAssetDocument endpoint with the asset_id from the response of the previous request to upload the file of DR events.
Make sure you use "type": "demand_response_events" in the request POST data.
The format of the DR event file should be as follows:
| Event Start Time | Event End Time |
|---|---|
| 2021-01-01 17:00:00-05:00 | 2021-01-01 20:00:00-05:00 |
| 2021-01-05 16:00:00-05:00 | 2021-01-05 18:00:00-05:00 |
| 2021-01-08 17:00:00-05:00 | 2021-01-08 20:00:00-05:00 |