# 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:** 5\
**Page:** 2

<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:** [March 12, 2025, 6:00pm UTC](https://community.homey.app/t/octopus-energy-api/85594/21 "2025-03-12T18:00:26Z")

</div>

Carl, @Welshsmarthome , @Dd3 ,

Well, it should fetch this data:

> [@ItsJustPW](#):
>
> `console.log('Electricity Meter Data:', data);`

> [@ItsJustPW](#):
>
> `console.log('Gas Meter Data:', data);`

> [@ItsJustPW](#):
>
> `console.log('Billing Details:', data);`

Now, the script only shows account data, because the other three data types are “commented out”, meaning, it doesn’t act as executable code, it just shows as comment because of the leading `//`

So, remove the leading `//` to get the meterdata and billing details

To write the data to tags, which you can use in flows, you can add this, right below the respective console.log lines positions in the script:

```auto
console.log('Electricity Meter Data:', data);
await tag('Electricity Meter Data:', `"${data}"`);

console.log('Gas Meter Data:',data);
await tag('Gas Meter Data:', `"${data}"`);

console.log('Billing Details:', data);
await tag('Billing Details:', `"${data}"`);

```

(Maybe you’ll have to comment out the 'console.log… ’ lines)

---

<div class="post-metadata">

**Author:** ![Gareth\_Pitts](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gareth_pitts/32/122405_2.png) [@Gareth\_Pitts](https://community.homey.app/u/Gareth_Pitts)\
**Post date:** [March 16, 2025, 7:38am UTC](https://community.homey.app/t/octopus-energy-api/85594/22 "2025-03-16T07:38:04Z")

</div>

Here is my homeyscript which pulls electrical usage and works !! Which returns data in this format ! Now I need someone expert in Homey to show me how to get the data into homey and graph it up (NON HOMEY EXPERT)

📊 Electricity Consumption Data:

📅 Date: 2025-03-14

⏳ Interval: 2025-03-14T23:30:00Z ➝ 2025-03-15T00:00:00Z

⚡ Usage: 3.085 kWh

* * *

📅 Date: 2025-03-14

⏳ Interval: 2025-03-14T23:00:00Z ➝ 2025-03-14T23:30:00Z

⚡ Usage: 2.473 kWh

```auto
// Octopus Energy API credentials
const API_KEY = 'sk_live_XXXXX'; // Replace with your Octopus API Key
const MPAN = '20020119223456’; // Your Octopus MPAN
const SERIAL_NUMBER = '19LXXXXX’; // Your Meter Serial Number

// Encode API Key for Basic Authentication
const encodedAuth = Buffer.from(`${API_KEY}:`).toString('base64');

// Octopus Energy API Endpoint for Consumption Data
const CONSUMPTION_URL = `https://api.octopus.energy/v1/electricity-meter-points/${MPAN}/meters/${SERIAL_NUMBER}/consumption/`;

// Function to fetch consumption data from Octopus API
async function fetchConsumptionData() {
    try {
        let response = await fetch(CONSUMPTION_URL, {
            headers: { 'Authorization': `Basic ${encodedAuth}` }
        });

        if (!response.ok) throw new Error(`Error: ${response.status}`);

        let data = await response.json();
        return data;
    } catch (error) {
        console.error('❌ Failed to fetch data:', error);
        return null;
    }
}

// Function to process and display consumption data
async function processConsumptionData() {
    let consumptionData = await fetchConsumptionData();
    if (consumptionData && consumptionData.results) {
        console.log('📊 Electricity Consumption Data:');

        let totalConsumption = 0;
        let binaryConsumption = [];

        consumptionData.results.forEach(entry => {
            console.log(`📅 Date: ${entry.interval_start.substring(0, 10)}`);
            console.log(`⏳ Interval: ${entry.interval_start} ➝ ${entry.interval_end}`);
            console.log(`⚡ Usage: ${entry.consumption.toFixed(3)} kWh`);
            console.log("----------------------------");

            // Add to total consumption
            totalConsumption += entry.consumption;
        });

        console.log(`🔥 Total Daily Consumption: ${totalConsumption.toFixed(2)} kWh`);
    } else {
        console.log('❌ No consumption data available.');
    }
}

// Execute function
processConsumptionData();

```

---

<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:** [March 17, 2025, 12:34am UTC](https://community.homey.app/t/octopus-energy-api/85594/23 "2025-03-17T00:34:13Z")

</div>

You can write the numeric values (no emoticons!) to pre-created numeric variables; then they’ll pop up in Insights.

Example on how to find (by var ID) and update variables:

```auto
let testDay = new Date();
let dateNum = testDay.getDate();
let monthTxtShort = testDay.toLocaleString('fefault', { month: 'short'})

let TodaysDate = Object.values(await Homey.logic.getVariables()).find(({name}) => name === "TodaysDate");
let TodaysDateId = TodaysDate.id
let MonthTextShort = Object.values(await Homey.logic.getVariables()).find(({name}) => name === "MonthTextShort");
let MonthTextShortId = MonthTextShort.id

Homey.logic.updateVariable({id: TodaysDateId, variable: {'value' : dateNum}} )
Homey.logic.updateVariable({id: MonthTextShortId, variable: {'value' : monthTxtShort}} )

```

With this app, you can create graphs from Insights data if you like:  
[https://homey.app/a/nl.mennovanhout.insights-graphs/](https://homey.app/a/nl.mennovanhout.insights-graphs/)  
These graphs can be displayed in a virtual cam f.i.

---

<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:** [May 18, 2025, 8:37pm UTC](https://community.homey.app/t/octopus-energy-api/85594/24 "2025-05-18T20:37:16Z")

</div>

App is development:

> [@\[APP\] Octopus Energy Integration](https://community.homey.app/t/app-octopus-energy-integration/136685):
>
> Developing Octopus Integration App I have been a use of Homey for about 6 months now. My main focus is automating energy management in my house. My energy supplier is Octopus - currently it seems to be largely unsupported by the Homey ecosystem. I have been developing code to automate the collection of energy data for consolidation in Google Sheets for some time. I have taken that code and used it as the basis for implementing my very first Homey App code. I now have basic automation working fo…

---

<div class="post-metadata">

**Author:** ![Gareth\_Pitts](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gareth_pitts/32/122405_2.png) [@Gareth\_Pitts](https://community.homey.app/u/Gareth_Pitts)\
**Post date:** [February 22, 2026, 6:55pm UTC](https://community.homey.app/t/octopus-energy-api/85594/25 "2026-02-22T18:55:29Z")

</div>

THe Kraken app now does it all

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