Skip to content
Snippets Groups Projects

!!! info "" 🚧 Section under Construction 🚧

This konnector fetches consumptions measures from Enedis API. This is an Oauth Konnector, meaning the authentification performed to access all data is made following an Oauth2 protocol. You can clone the project here.

You should also check Cozy's official documentations for konnectors : https://docs.cozy.io/en/tutorials/konnector/getting-started/ https://docs.cozy.io/en/tutorials/konnector/oauth/

Enedis Konnector

The Oauth protocol does not take place in the konnector code, therefore it is also important to take a look at the proxy to fully understand all the interactions that will be told below.

All the actions performed by the stack are targetted from pre-registered paramaters, here is the list of all parameters needed by the stack to perform the Oauth protocol and allow the konnector to fetch data. On its first launch, following the Oauth Client Connect authentification.

  • The cozy stack calls the authentification_endpoint and start the oauth protocol, see proxy doc.
  • The account has now an access_token and an id_token from the oauth call

!!! info "" idtoken is only given when requesting the token endpoint in _authorization_code grant_type. This token holds several meta datas, including the pce_id (id of user's meter) that will be needed further to fetch user's datas.

  • Konnector starts, fails to find a pce_id in database on first launch therefore decodes the id_token to store the pce_id in db (see addData).

  • Konnector restarts, this time knowing a pce_id, it fails to fetch datas because the access_token from oauth call has a reduced scope (only scoping for meta data requests).

  • Konnector launches a refresh call, the proxy knows to answer it with a client_credentials grant_type call to grdf /access_token.

  • Konnector restarts with everyting needed in database to fetch datas and store them in couchdb.

  • Further jobs will not need to change scope again and will only ask for refresh tokens.

Enedis API

API Url for Production : https://gw.prd.api.enedis.fr API url for Development : https://gw.hml.api.enedis.fr

Once you've finished the OAuth protocol and have a valid token, you can go fetch the data. Currently we use the two following endpoints in Ecolyo:

Method : GET

Route : /v4/metering_data/consumption_load_curve

Method : GET

Route : /v4/metering_data/daily_consumption

"params":
{
	"usage_point_id": <your-usage-point-id>,
    "start": "YYYY-MM-DD",
    "end": "YYYY-MM-DD",
}
"headers":
{
	"Accept": "application/json",
    "Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

For more information about Datahub-Enedis API, checkout the Datahub documentation.

Konnector Methods

Method Description
start Init Function
getDailyData Retrieve data from the API. Format: { value: "Wh", "date": "YYYY-MM-DD" }"
startLoadDataProcess Check if history is loaded. If not, call several time the api to retrieve 1 month of history for load data. If yes only call once the api
launchLoadDataProcess Launch process to handle load data
getLoadData Retrieve data from the API. Format: { value: "W", "date": "YYYY-MM-DD hh:mm:ss" }
processData Parse data. Remove existing data from DB using hydrateAndFilter, store filtered data and return the list of filtered data
agregateMonthAndYearData Agregate data from daily data to monthly and yearly data
agregateHourlyData Agregate data from load data (every 30 min) to Hourly data
storeData Save data in the right doctype db and prevent duplicated keys
formateData Format data for DB storage and remove bad data
buildAgregatedData Retrieve and remove old data for a specific doctype and return an array of agregated data
buildDataFromKey Format an entry for DB storage using key and value. For year doctype: key = "YYYY". For month doctype: key = "YYYY-MM"
isHistoryLoaded Function checking if the history is loaded
resetInProgressAggregatedData Function handling special case.The temporary aggregated data need to be remove in order for the most recent one te be saved. Ex for com.grandlyon.enedis.year : { load: 76.712, year: 2020, ... } need to be replace by { load: 82.212, year: 2020, ... } after enedis data reprocess