# Octopus Energy API

**URL:** <https://community.homey.app/t/octopus-energy-api/85594>\
**Category:** Apps\
**Created:** [July 31, 2023, 12:46pm UTC](https://community.homey.app/t/octopus-energy-api/85594 "2023-07-31T12:46:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![WhyAydan](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/whyaydan/32/122884_2.png) [@WhyAydan](https://community.homey.app/u/WhyAydan)\
**Post date:** [July 31, 2023, 12:46pm UTC](https://community.homey.app/t/octopus-energy-api/85594/1 "2023-07-31T12:46:30Z")

</div>

Hey!

Has anyone managed to integrate with the octopus energy API?

Aydan

---

<div class="post-metadata">

**Author:** ![Comgen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/comgen/32/102270_2.png) [@Comgen](https://community.homey.app/u/Comgen)\
**Post date:** [March 4, 2024, 11:28am UTC](https://community.homey.app/t/octopus-energy-api/85594/2 "2024-03-04T11:28:33Z")

</div>

WhyAyden, did you get any progress on this? I too would love to be able to receive my cheap rates

---

<div class="post-metadata">

**Author:** ![WhyAydan](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/whyaydan/32/122884_2.png) [@WhyAydan](https://community.homey.app/u/WhyAydan)\
**Post date:** [March 4, 2024, 11:41am UTC](https://community.homey.app/t/octopus-energy-api/85594/3 "2024-03-04T11:41:19Z")

</div>

Hello, no I did not ☹  
I ended up going back to HomeAssistant as it was more what i wanted.

---

<div class="post-metadata">

**Author:** ![Comgen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/comgen/32/102270_2.png) [@Comgen](https://community.homey.app/u/Comgen)\
**Post date:** [March 4, 2024, 12:43pm UTC](https://community.homey.app/t/octopus-energy-api/85594/4 "2024-03-04T12:43:49Z")

</div>

Thanks for replying, if I get anywhere i will let you know.

---

<div class="post-metadata">

**Author:** ![M\_W](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/m_w/32/81907_2.png) [@M\_W](https://community.homey.app/u/M_W)\
**Post date:** [August 22, 2024, 3:59pm UTC](https://community.homey.app/t/octopus-energy-api/85594/5 "2024-08-22T15:59:16Z")

</div>

Hello, did you manage to make any progress?

---

<div class="post-metadata">

**Author:** ![Comgen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/comgen/32/102270_2.png) [@Comgen](https://community.homey.app/u/Comgen)\
**Post date:** [August 22, 2024, 4:21pm UTC](https://community.homey.app/t/octopus-energy-api/85594/6 "2024-08-22T16:21:07Z")

</div>

Ok so I have made progress sort of. It is a long winded way but I have a solution. I got chat gPT to write me an application that I have running on a raspberry pi that sends an update every minute to mqtt stating the charge time slots and also wether the current minute is in cheap rate mode or not. I then use the MQTT client in homey.

---

<div class="post-metadata">

**Author:** ![M\_W](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/m_w/32/81907_2.png) [@M\_W](https://community.homey.app/u/M_W)\
**Post date:** [August 22, 2024, 4:40pm UTC](https://community.homey.app/t/octopus-energy-api/85594/7 "2024-08-22T16:40:08Z")

</div>

Wow, impressive lateral thinking!

I got a Homey Pro to avoid having to fiddle with workarounds, Raspberry Pi, etc… but first impressions is it’s still far from plug 'n play.

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [August 22, 2024, 6:27pm UTC](https://community.homey.app/t/octopus-energy-api/85594/8 "2024-08-22T18:27:37Z")

</div>

Maybe it’s possible to retreive data with homeyscript.  
Can someone try this, or explain how I get a temporary API key (not a customer here)?

```auto
const myAPIKey = 'abc123' // change into personal API key here

const url = 'https://api.octopus.energy/v1/accounts/';
const res = await fetch(url, {
              headers : {
              'x-api-key': myAPIKey
              }
            });
            if (!res.ok) {
              throw new Error(res.status);
              return false;
            }

const json = await res.json();
//const value = json.value;
log (json);
return true;

```

---

<div class="post-metadata">

**Author:** ![Comgen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/comgen/32/102270_2.png) [@Comgen](https://community.homey.app/u/Comgen)\
**Post date:** [August 22, 2024, 7:40pm UTC](https://community.homey.app/t/octopus-energy-api/85594/9 "2024-08-22T19:40:18Z")

</div>

I am currently out of the country until 1st September. I will be able to help then as I got chat GPT to do that but for me too. lol I have a copy of the code

---

<div class="post-metadata">

**Author:** ![M\_W](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/m_w/32/81907_2.png) [@M\_W](https://community.homey.app/u/M_W)\
**Post date:** [August 22, 2024, 9:49pm UTC](https://community.homey.app/t/octopus-energy-api/85594/10 "2024-08-22T21:49:54Z")

</div>

Hi, I’m an Octopus customer, and have an API key, but I’m not a coder and am completely new to Homey Pro. I’ve installed the Homeyscript app, but not sure what to do next.

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [August 22, 2024, 10:32pm UTC](https://community.homey.app/t/octopus-energy-api/85594/11 "2024-08-22T22:32:58Z")

</div>

Hi,

You can copy the code 1:1 by hitting the copy symbol:

> ![1000033279](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/f/df8a702305166f96fddc75d9de2027b74ec70ed4.jpeg)

Goto Homeyscript ([https://my.homey.app/scripts](https://my.homey.app/scripts))

> ![1000033282](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/c/8c5f7fb363902d0b298a67db2882374716175433.jpeg)

Hit “New Homeyscript”, and paste the code in the top right screen, it should look similar to this:

> ![1000033285](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/f/5fb262b834d8b0af806c0863ad6c2c700f982165.jpeg)

Change the example API key in line 1 to your personal key;

Hit the blue Save button, and then the green “Run” button next to it;

Now the results should show at the bottom screen, below “Console”

> ![1000033287](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/8/e8436ebc869b5b52e62320ae632cf8d96c2e9297.jpeg)

As you can see, I got error 401 returned, which means ‘unauthorised’ (invalid API key)

I hope this gets you going.

---

<div class="post-metadata">

**Author:** ![M\_W](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/m_w/32/81907_2.png) [@M\_W](https://community.homey.app/u/M_W)\
**Post date:** [August 28, 2024, 7:11am UTC](https://community.homey.app/t/octopus-energy-api/85594/12 "2024-08-28T07:11:25Z")

</div>

Thanks for your very detailed instructions… but unfortunately, I get exactly the same 401 error.

The URL [https://api.octopus.energy/v1/accounts/](https://api.octopus.energy/v1/accounts/) requires login credentials. So, do these need to be added to the script? (Sorry, I don’t really understand .json)

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [August 28, 2024, 10:40am UTC](https://community.homey.app/t/octopus-energy-api/85594/13 "2024-08-28T10:40:58Z")

</div>

Yes, you’ll have to change the example API key `abc123` in Line 1, into the API key you received:

> ![1000033524](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/a/0ae54573b49e6245530fd9f9ebb7f0bb5b330fe3.jpeg)

Does that make any sense?  
You can obtain your API key from your online dashboard ([https://octopus.energy/dashboard/new/accounts/personal-details/api-access](https://octopus.energy/dashboard/new/accounts/personal-details/api-access))

> ![1000033526](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/8/f8f7eb7fd7077a1cf00ce38ac480d07d75610074.jpeg)

And, you’re welcome!

---

<div class="post-metadata">

**Author:** ![M\_W](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/m_w/32/81907_2.png) [@M\_W](https://community.homey.app/u/M_W)\
**Post date:** [August 28, 2024, 10:50am UTC](https://community.homey.app/t/octopus-energy-api/85594/14 "2024-08-28T10:50:25Z")

</div>

I am the same person that told you I have an API key.

> [@Octopus Energy API](https://community.homey.app/t/octopus-energy-api/85594/10):
>
> Hi, I’m an Octopus customer, and have an API key, but I’m not a coder and am completely new to Homey Pro. I’ve installed the Homeyscript app, but not sure what to do next.

I _did_ use my own key, and when I got an error, I regenerated the key and tried again.

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [August 28, 2024, 11:00am UTC](https://community.homey.app/t/octopus-energy-api/85594/15 "2024-08-28T11:00:30Z")

</div>

Sorry about that, forgot / did not read back the topic.  
If you are sure your API key is valid, I don’t know what to test next.

One thing what might error: the single quotes `' '` are needed around your API key in line 1, don’t leave them out.  
Make sure they’re not _fancy quotes_ (cursive). Only straight quotes are valid.

---

<div class="post-metadata">

**Author:** ![M\_W](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/m_w/32/81907_2.png) [@M\_W](https://community.homey.app/u/M_W)\
**Post date:** [August 28, 2024, 11:32am UTC](https://community.homey.app/t/octopus-energy-api/85594/16 "2024-08-28T11:32:00Z")

</div>

Yes I double-checked, the syntax is correct. I’ve sent you a message.

---

<div class="post-metadata">

**Author:** ![ItsJustPW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/itsjustpw/32/120133_2.png) [@ItsJustPW](https://community.homey.app/u/ItsJustPW)\
**Post date:** [November 28, 2024, 4:25pm UTC](https://community.homey.app/t/octopus-energy-api/85594/17 "2024-11-28T16:25:59Z")

</div>

Feel free to use this… just add the info at the top. I’ve still got some things I’m working on but might help get you started.

```auto

// Make sure you update below within the ' ' quotes.
const apiKey = ''; // Your API key
const accountNumber = ''; // Your account number, something like A-1234567
const electricityMPAN = ''; // You can get this from developers section
const electricitySerialNumber = ''; // You can get this from developers section
const gasMPRN = ''; // // You can get this from developers section
const gasSerialNumber = ''; // You can get this from developers section

const baseUrl = 'https://api.octopus.energy/v1';

function createAuthHeader(apiKey) {
    const authString = `${apiKey}:`;
    const authBase64 = Buffer.from(authString).toString('base64');
    return `Basic ${authBase64}`;
}

async function fetchAccountDetails() {
    const url = `${baseUrl}/accounts/${accountNumber}/`;

    try {
        const response = await fetch(url, {
            headers: {
                Authorization: createAuthHeader(apiKey)
            }
        });

        if (!response.ok) {
            throw new Error(`Error fetching account details: ${response.statusText}`);
        }

        const data = await response.json();
        console.log('Account Details:', data);
        return data;
    } catch (error) {
        console.error('Error:', error);
    }
}

async function fetchElectricityMeterData() {
    const url = `${baseUrl}/electricity-meter-points/${electricityMPAN}/meters/${electricitySerialNumber}/consumption/`;

    try {
        const response = await fetch(url, {
            headers: {
                Authorization: createAuthHeader(apiKey)
            }
        });

        if (!response.ok) {
            throw new Error(`Error fetching electricity meter data: ${response.statusText}`);
        }

        const data = await response.json();
        console.log('Electricity Meter Data:', data);
        return data;
    } catch (error) {
        console.error('Error:', error);
    }
}

async function fetchGasMeterData() {
    const url = `${baseUrl}/gas-meter-points/${gasMPRN}/meters/${gasSerialNumber}/consumption/`;

    try {
        const response = await fetch(url, {
            headers: {
                Authorization: createAuthHeader(apiKey)
            }
        });

        if (!response.ok) {
            throw new Error(`Error fetching gas meter data: ${response.statusText}`);
        }

        const data = await response.json();
        console.log('Gas Meter Data:', data);
        return data;
    } catch (error) {
        console.error('Error:', error);
    }
}

async function fetchBillingDetails() {
    const url = `${baseUrl}/billing/charges/`;

    try {
        const response = await fetch(url, {
            headers: {
                Authorization: createAuthHeader(apiKey)
            }
        });

        if (!response.ok) {
            throw new Error(`Error fetching billing details: ${response.statusText}`);
        }

        const data = await response.json();
        console.log('Billing Details:', data);
        return data;
    } catch (error) {
        console.error('Error:', error);
    }
}

(async () => {
    await fetchAccountDetails();
// await fetchElectricityMeterData();
// await fetchGasMeterData();
// await fetchBillingDetails();
})();

```

---

<div class="post-metadata">

**Author:** ![Dd3](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@Dd3](https://community.homey.app/u/Dd3)\
**Post date:** [December 9, 2024, 1:48pm UTC](https://community.homey.app/t/octopus-energy-api/85594/18 "2024-12-09T13:48:54Z")

</div>

What will this do exactly ?

Just had solar and battery installed and just started using octopus

Haven’t yet connected the inverter to homey but depending on what this does my next step is to find a way to adjust behaviour of the system and house to tariff info.

Would try homey if I can find a system that’s simple enough otherwise it’ll have to go on the HA

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Welshsmarthome](https://avatars.discourse-cdn.com/v4/letter/w/df705f/32.png) [@Welshsmarthome](https://community.homey.app/u/Welshsmarthome)\
**Post date:** [January 10, 2025, 10:50pm UTC](https://community.homey.app/t/octopus-energy-api/85594/19 "2025-01-10T22:50:22Z")

</div>

Also like to know whst this does.

Would love to know if Giv Energy or Octopus R&D can be linked to Homey so that I can use solar automations without the hassle of Home Assistant.  
There is an an app on Home Assistant called GivTCP which shows solar production and all sorts, be great to get that here and schedule my battery to charge depending on the time / unit price.

No clue where to start with designing such a thing for Homey but would be great if some clever minds come together to make this happen.  
Thanks

---

<div class="post-metadata">

**Author:** ![Carl](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/carl/32/124386_2.png) [@Carl](https://community.homey.app/u/Carl)\
**Post date:** [February 15, 2025, 8:48am UTC](https://community.homey.app/t/octopus-energy-api/85594/20 "2025-02-15T08:48:17Z")

</div>

Any update on what any of this is supposed to do?

All I can get it to give me is my address and the date I moved in. No other information so it’s pointless.

It doesn’t produce any energy data at all.

[Next page](https://community.homey.app/t/octopus-energy-api/85594.md?page=2)
