I recently switched to an Octopus energy account as they provide a device to allow you to access your real-time electricity consumption from your smart meter. On request Octopus will provide a free Home Mini device which connects to your smart meter with ZigBee and to your home Wi-Fi to upload your electricity consumption every 10 seconds.
If you'd like to switch to Octopus you can use my referral code for a £50 discount https://share.octopus.energy/playful-engine-680
To access the real-time data you query the Octopus API using GraphQL format HTTPS Posts.
To start you need the following: your Octopus account number (A-AAAA1111 format) and your Octopus API Key which you can create here. The API key is like a password so don't reveal it to anyone. If necessary, you can regenerate the key using the same link.
There are 3 steps:
Step 1
Get a Kraken bearer token using the following query. The token lasts for 1 hour before a new, or refreshed, one is required.
|
URL |
|
|
Query |
mutation ObtainKrakenToken { obtainKrakenToken(input: { APIKey: "sk_live_Your developer API key" }) { token payload refreshToken refreshExpiresIn } } |
|
Authentication |
None |
The result will be as shown below. You only need the text of the long token string.
{
"data": {
"obtainKrakenToken": {
"token": "eyJhbGciOiJSUzI1NiIsImlzcyI6Imh0dHBzOi8vYXBpLm9jdG9wdXMuZW5lcmd5L3YxL2dyYXBocWwvIiwiamt1IjoiaHR0cHM6Ly9hdXRoLm9jdG9wdXMuZW5lcmd5Ly53ZWxsLWtub3duL2p3a3MuanNvbiIsImtpZCI6InFRb3hIbzhiTF91Wi1NdE9kQ2labDZacjFaMWsyM1l2Y0taZnU5QldHNkEiLCJ0eXAiOiJKV1QifQ.eyJzdWIiOiJrcmFrZW58YWNjb3VudC11c2VyOjEzMjMyODc3IiwiZ3R5IjoiQVBJLUtFWSIsImVtYWlsIjoiYW5kcmV3LmpvbmVzQGFscXVpc3QuY28udWsiLCJ0b2tlblVzZSI6ImFjY09090909sd09sd09s0d9pLm9jdG9wdXMuZW5lcmd5L3YxL2dyYXBocWwvIiwiaWF0IjoxNzc4ODczMjA1LCJleHAiOjE3Nzg4NzY4MDUsIm9yaWdJYXQiOjE3Nzg4NzMyMDV9.ABJbgP0gvh68SqNx-GGXGVq4_WSbZ6vqfWb9veWYV0mHojyMkW-EqMUMhVrtvIFYhyom4qbWodfnAGrNIh0akpauzCJG-6qFa8Noynuibqlu4RmoVThYbIOUGbqO6p-VQmKPACKuhimfCzntU2m_Gh2uNr8Tbsx5pqXPnGp6S10LQm1eJvrKmJ4ca1PDh53lx75zgDo-JjARKXm4M4JHbjN5D4TlfJ7fPGlrZktafYad9XwvN1DraAutB4Ur-8ogCpVo7IoBWnnN7gaJCFSEALfi03_wb6ydx-Kb0qnbpKyi-DkJYCn-8EFowQEfA2SKgHMz8nPAN0e58Cb385bS1Q",
"payload": {
"sub": "kraken|account-user:000000",
"gty": "API-KEY",
"email": "andrew@000000",
"tokenUse": "access",
"iss": "https://api.octopus.energy/v1/graphql/",
"iat": 1778873205,
"exp": 1778876805,
"origIat": 1778873205
},
"refreshToken": "faff3b0d2700cc9cd6c2fc8d000000e31466dd0daea2149d4c2c68f1",
"refreshExpiresIn": 1779478005
}
}
}
Step 2
You need to establish the deviceId for your electricity meter. Using your Account Number and the bearer token from step 1. I think you only need to do this once as I don't think the deviceId changes.
|
URL |
|
|
Query |
query MyQuery { account(accountNumber: "A-YourAccountNumber") { electricityAgreements(active: true) { meterPoint { meters(includeInactive: false) { smartDevices { deviceId } } } } } } |
|
Authentication |
The bearer token from the step 1 above |
Step 3
To read the real-time electricity consumption you need the bearer token from step 1 and the 8 byte deviceID from step 2
|
URL |
|
|
Query |
query SmartMeterTelemetry { smartMeterTelemetry(deviceId: "Your deviceId from step 2") { readAt consumption demand } } |
|
Authentication |
The bearer token from step 1 |
Your current consumption, in Watts, is in the demand field shown below. I've been making this request every 30 seconds and the API seems happy with that.

No comments:
Post a Comment