Help with how to build a script

Basically I want to create a script that I can use in Homey to give me my live whole house energy usage.

I have a device called Voltaware which gives me live usage as per this screenshot

However I have no clue on how to build the script to give me this info.

They have a website here which appears to have the information required to go into the script. https://docs.voltaware.com

But I do not have a clue on where to start or how the code is built and then how to get the info to appear in Homey Pro in this area. The current info is from some Hue lights that are on and that’s it.

So any help is greatly appreciated.

Not what you asked, but it’s sort of built in?

That doesn’t work for me as in the UK we don’t have meters with P1/RJ12 ports.

I see. If I’m right, Athom wants a solution for UK meters. Those can be monitored via zigbee afaik.

You don’t need a (P1) dongle for the Energy tab to work.
You can use a meter which uses power clamps.
Or a 1- or 3 phase meter, inline for instance.

I took a look @ Voltaware API info, but it’s way too complicated to me to pour into a script.

Only with a zigbee current clamp. Or something that leverages the API from the likes of octopus (energy supplier)

There is also Glowmarkt from Hildebrand that have a IHD that is also supportive of home assistant. So not sure if that is something that Homey Pro could work with.

At the moment though you can only get it with something like this. But I believe Tuya doesn’t work anymore at the moment.

There is also Shelley but I’m not sure if it will give the whole home usage in the section I highlighted in my original post.

Wasn’t finished yet! Somehow the first sentence got posted whilst still writing :face_with_peeking_eye::rofl:

Oh, and stay away from Tuya with Homey.

Ahhh, I wrote lots of scripts for that. But somehow the person looking for it didn’t want to go that way anymore.

Would you like to try those scripts?

Yes please that would be very kind of you and appreciated.

I tried this one before. And all it gives me is my address and date I moved in. No energy data at all

I have an api key etc. I don’t have gas though so that’s not required

// 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();
})();

Okay, I’ve these scripts for you.
I can’t tell you what works or not, it’s been a while ago.

Octopus lives up to it’s name, that’s for sure :face_with_peeking_eye:

octopus energy get account info
const myAPIKey = 'sk_live_VFeOb0cTK3MyfiMEsNLOXqTq'; // change into personal API key here
const myAccountno = 'xxxxxxxx'; // Your Account number

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

//// To get account products and tariffs, use this url: ////
const URL = baseURL + `accounts/${myAccountno}/`;

const res = await fetch(URL, {
              headers : {
              'x-api-key': myAPIKey
              }
            });
            if (!res.ok) {
              throw new Error(res.status + '\n' + res.json); // 401 = unauthorised, 404 = not found
              return false;
            }

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

octopus energy api test
const myAPIKey = 'sk_live_VFeOb0cTK3MyfiMEsNLOXqTq'; // change into personal API key here
const myAccountno = 'xxxxxxxx'; // Your Account number
////////const myProductcodeImport = 'AGILE-24-04-03'; // the product code to use, like 'AGILE-24-04-03' (Octopus import), 'AGILE-BB-24-04-03' (Bulb import) and so forth
const myProductcodeExport = 'AGILE-OUTGOING-19-05-13'; // the product code to use, like 'AGILE-OUTGOING-19-05-13' (Octopus export), AGILE-OUTGOING-BB-23-02-28' (Bulb export) and so forth
const myProductcodeGas = 'xxxxxxxx'
const myTariffcode = 'xxxxx' // the tariffcode to use, like ..........
const myMpan = '1900091018842'; // Electricitymeter No.
const myMprn = 'xxxxxx'; // Gasmeter No.
const mySerialno = '19L3665047'; // Serialnumber of your meter

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

//
//

//// Some ways to get different kinds of data ////

//// To get all the product codes, use this url: ////
// const URL = baseURL + `products/`

//// To return a list of unit rates and standing charges, add one of these to baseURL:
// const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/${myTariffcode}/standing-charges/`
// const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/${myTariffcode}/standard-unit-rates/`
// const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/${myTariffcode}/day-unit-rates/`
// const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/${myTariffcode}/night-unit-rates/`
// const URL = baseURL + `${myProductcodeGas}/gas-tariffs/${myTariffcode}/standing-charges/`
// const URL = baseURL + `${myProductcodeGas}/gas-tariffs/${myTariffcode}/standard-unit-rates/`


//// uncomment 1 URL for import or export tariffs ////
///////////const URL = baseURL + `products/${myProductcodeImport}/`; //////////////////////////////////////////////
//const URL = baseURL + `products/${myProductcodeExport}/`;



//// uncomment 1 URL for electricity or gas tariffs ////
//// electricity-tariffs IMPORT////
/////const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/${myTariffcode}/day-unit-rates/`;
const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/`;


//// electricity-tariffs EXPORT////
//////////////////const URL = baseURL + `${myProductcodeExport}/electricity-tariffs/${myTariffcode}/day-unit-rates/`;


//// gas-tariffs ////
//const url = baseURL + `${myproductCodeGas}/gas-tariffs/${myTariffcode}/standard-unit-rates/`;

//// Get today's electricity / gas readings, add one of these to baseURL:
//const URL = baseURL + `/electricity-meter-points/${myMpan}/meters/${mySerialno}/consumption/`;
//const URL = baseURL + `/gas-meter-points/${myMprn}/meters/${mySerialno}/consumption/`;

const res = await fetch(URL, {
              headers : {
              'x-api-key': myAPIKey
              }
            });
            if (!res.ok) {
              throw new Error(res.status + '\n' + res.json); // 401 = unauthorised, 404 = not found
              return false;
            }

const json = await res.json();
//const value = json.value;
log (json);
return true;
octopus energy get all product codes
const myAPIKey = 'sk_live_VFeOb0cTK3MyfiMEsNLOXqTq'; // change into personal API key here

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

//// To get all the product codes, use this url: ////
const URL = baseURL + `products/`

const res = await fetch(URL, {
              headers : {
              'x-api-key': myAPIKey
              }
            });
            if (!res.ok) {
              throw new Error(res.status + '\n' + res.json); // 401 = unauthorised, 404 = not found
              return false;
            }

const json = await res.json();
//const value = json.value;
log (json);
return true;
octopus energy listing of all product codes
{
  count: 44,
  results: [
    {
      code: 'AGILE-24-04-03',
      direction: 'IMPORT',
      full_name: 'Agile Octopus April 2024 v1',
      display_name: 'Agile Octopus',
      description: 'With Agile Octopus, you get access to half-hourly energy prices, tied to wholesale prices and updated daily.  The unit rate is capped at 100p/kWh (including VAT).',
      is_variable: true,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2024-04-03T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'AGILE-BB-24-04-03',
      direction: 'IMPORT',
      full_name: 'Agile Octopus April 2024 v1',
      display_name: 'Agile Octopus',
      description: 'With Agile Octopus, you get access to half-hourly energy prices, tied to wholesale prices and updated daily.  The unit rate is capped at 100p/kWh (including VAT).',
      is_variable: true,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2024-04-03T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'AGILE-OUTGOING-19-05-13',
      direction: 'EXPORT',
      full_name: 'Agile Outgoing Octopus May 2019',
      display_name: 'Agile Outgoing Octopus',
      description: 'Outgoing Octopus Agile rate pays you for all your exported energy based on the day-ahead wholesale rate.',
      is_variable: true,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2018-01-01T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'AGILE-OUTGOING-BB-23-02-28',
      direction: 'EXPORT',
      full_name: 'Agile Outgoing Octopus February 2023 v1',
      display_name: 'Agile Outgoing Octopus',
      description: 'Outgoing Octopus Agile rate pays you for all your exported energy based on the day-ahead wholesale rate.',
      is_variable: true,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2023-02-27T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'COOP-FIX-12M-24-08-28',
      direction: 'IMPORT',
      full_name: 'Co-op 12M Fixed August 2024 v4',
      display_name: 'Co-op 12M Fixed',
      description: 'This fixed tariff locks in your unit rates and standing charges for 12 months with no exit fees.',
      is_variable: false,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2024-08-28T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'COOP_ENERGY'
    },
    {
      code: 'COOP-PP-VAR-20-04-01',
      direction: 'IMPORT',
      full_name: 'Co-op Key and Card',
      display_name: 'Co-op Key and Card',
      description: 'Non-smart prepayment tariff',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: true,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2020-03-03T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'COOP_ENERGY'
    },
    {
      code: 'COOP-SEG-EO-FIX-12M-24-04-05',
      direction: 'EXPORT',
      full_name: 'Co-op Smart Export Guarantee Export Only April 2024 v1',
      display_name: 'Co-op Smart Export Guarantee Export Only',
      description: 'This is our Smart Export Guarantee compliant export tariff for export only accounts',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2024-04-05T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'COOP_ENERGY'
    },
    {
      code: 'COOP-SEG-FIX-12M-20-11-11',
      direction: 'EXPORT',
      full_name: 'Co-op Smart Export Guarantee November 2020 v1',
      display_name: 'Co-op Smart Export Guarantee',
      description: 'This is our Smart Export Guarantee compliant export tariff',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2020-11-11T17:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'COOP_ENERGY'
    },
    {
      code: 'COOP-VAR-23-04-01',
      direction: 'IMPORT',
      full_name: 'Co-op Flexible',
      display_name: 'Co-op Flexible',
      description: 'Co-op Flexible prices follow wholesale costs and update every 3 months.\r\n' +
        '\r\n' +
        "Good to know: Ofgem has announced the energy price cap will rise from October 1. Co-op Flexible rates will also rise in October – we'll share details soon.",
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-04-01T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'COOP_ENERGY'
    },
    {
      code: 'COSY-22-12-08',
      direction: 'IMPORT',
      full_name: 'Cosy Octopus',
      display_name: 'Cosy Octopus',
      description: 'Cosy Octopus is a heat pump tariff with eight hours of super cheap electricity every day to warm your home.',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2022-12-13T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'COSY-BB-23-02-07',
      direction: 'IMPORT',
      full_name: 'Cosy Octopus',
      display_name: 'Cosy Octopus',
      description: 'Cosy Octopus is a heat pump tariff with eight hours of super cheap electricity every day to warm your home.',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-02-07T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'CP-12M-24-08-28',
      direction: 'IMPORT',
      full_name: 'Co-op Community Power 12M Fixed August 2024 v4',
      display_name: 'Co-op Community Power',
      description: 'This fixed tariff locks in your unit rates and standing charges for 12 months with no exit fees.',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2024-08-28T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'COOP_ENERGY'
    },
    {
      code: 'FLUX-EXPORT-23-02-14',
      direction: 'EXPORT',
      full_name: 'Octopus Flux Export',
      display_name: 'Octopus Flux Export',
      description: 'Octopus Flux Export February 2023 v1',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-02-14T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'FLUX-EXPORT-BB-23-02-14',
      direction: 'EXPORT',
      full_name: 'Octopus Flux Export',
      display_name: 'Octopus Flux Export',
      description: 'Octopus Flux Export February 2023 v2',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-02-14T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'FLUX-IMPORT-23-02-14',
      direction: 'IMPORT',
      full_name: 'Octopus Flux Import',
      display_name: 'Octopus Flux Import',
      description: 'Power your home with 100% renewable energy on this Octopus Energy electricity tariff designed exclusively for solar and battery owners.',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-02-14T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'FLUX-IMPORT-BB-23-02-14',
      direction: 'IMPORT',
      full_name: 'Octopus Flux Import',
      display_name: 'Octopus Flux Import',
      description: 'Power your home with 100% renewable energy on this Octopus Energy electricity tariff designed exclusively for solar and battery owners.',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-02-14T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'GO-VAR-22-10-14',
      direction: 'IMPORT',
      full_name: 'Octopus Go',
      display_name: 'Octopus Go',
      description: 'The smart EV tariff with super cheap electricity between 00:30 - 05:30 every night',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2022-10-14T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'GO-VAR-BB-23-02-07',
      direction: 'IMPORT',
      full_name: 'Octopus Go',
      display_name: 'Octopus Go',
      description: 'The smart EV tariff with super cheap electricity between 00:30 - 05:30 every night',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-02-07T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'INTELLI-BB-VAR-23-03-01',
      direction: 'IMPORT',
      full_name: 'Intelligent Octopus Go',
      display_name: 'Intelligent Octopus Go',
      description: 'With Intelligent Octopus Go EV tariff, you have access to a super low electricity rate between 23:30 - 05:30 every night, plus it smart-charges your car at the cheapest and greenest times overnight.',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-02-02T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'INTELLI-FLUX-EXPORT-23-07-14',
      direction: 'EXPORT',
      full_name: 'Intelligent Octopus Flux Export',
      display_name: 'Intelligent Octopus Flux Export',
      description: 'Intelligent Octopus Flux Export v1',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-07-13T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'INTELLI-FLUX-EXPORT-BB-23-07-14',
      direction: 'EXPORT',
      full_name: 'Intelligent Octopus Flux Export',
      display_name: 'Intelligent Octopus Flux Export',
      description: 'Intelligent Octopus Flux Export v1',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-07-13T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'INTELLI-FLUX-IMPORT-23-07-14',
      direction: 'IMPORT',
      full_name: 'Intelligent Octopus Flux Import',
      display_name: 'Intelligent Octopus Flux Import',
      description: 'Power your home with 100% renewable energy on this Octopus Energy electricity tariff designed exclusively for solar and battery owners.',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-07-13T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'INTELLI-FLUX-IMPORT-BB-23-07-14',
      direction: 'IMPORT',
      full_name: 'Intelligent Octopus Flux Import',
      display_name: 'Intelligent Octopus Flux Import',
      description: 'Power your home with 100% renewable energy on this Octopus Energy electricity tariff designed exclusively for solar and battery owners.',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-07-13T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'INTELLI-VAR-22-10-14',
      direction: 'IMPORT',
      full_name: 'Intelligent Octopus Go',
      display_name: 'Intelligent Octopus Go',
      description: 'With Intelligent Octopus Go EV tariff, you have access to a super low electricity rate between 23:30 - 05:30 every night, plus it smart-charges your car at the cheapest and greenest times overnight.',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2022-10-14T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'INTELLI-VAR-OEV-24-07-17',
      direction: 'IMPORT',
      full_name: 'Intelligent Octopus Go - EV Saver',
      display_name: 'Intelligent Octopus Go - EV Saver',
      description: 'An EV tariff exclusively for customers that lease through Octopus EV',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2024-07-17T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'INTELLI-VAR-OEV-BB-24-07-17',
      direction: 'IMPORT',
      full_name: 'Intelligent Octopus Go - EV Saver',
      display_name: 'Intelligent Octopus Go - EV Saver',
      description: 'An EV tariff exclusively for customers that lease through Octopus EV',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2024-07-17T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'LP-SEG-EO-FIX-12M-24-04-05',
      direction: 'EXPORT',
      full_name: 'my london smart export guarantee export only april 2024 v1',
      display_name: 'my london smart export only guarantee',
      description: 'This is our Smart Export Guarantee compliant export tariff for export only accounts',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2024-04-05T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'LONDON_POWER'
    },
    {
      code: 'LP-SEG-FIX-12M-20-11-11',
      direction: 'EXPORT',
      full_name: 'my london smart export guarantee november 2020 v1',
      display_name: 'my london smart export guarantee',
      description: 'This is our Smart Export Guarantee compliant export tariff',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2020-11-11T17:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'LONDON_POWER'
    },
    {
      code: 'LP-VAR-23-04-01',
      direction: 'IMPORT',
      full_name: 'my london flexible plan',
      display_name: 'my london flexible plan',
      description: 'my london flexible plan prices follow wholesale costs and update every 3 months.\r\n' +
        '\r\n' +
        "Good to know: Ofgem has announced the energy price cap will rise from October 1. my london flexible plan rates will also rise in October – we'll share details soon.",
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-04-01T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'LONDON_POWER'
    },
    {
      code: 'OE-FIX-12M-24-08-28',
      direction: 'IMPORT',
      full_name: 'Octopus 12M Fixed August 2024 v4',
      display_name: 'Octopus 12M Fixed',
      description: 'This fixed tariff locks in your unit rates and standing charges for 12 months with no exit fees.',
      is_variable: false,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2024-08-28T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'OE-FIX-12M-BB-24-08-28',
      direction: 'IMPORT',
      full_name: 'Octopus 12M Fixed August 2024 v4',
      display_name: 'Octopus 12M Fixed',
      description: 'This fixed tariff locks in your unit rates and standing charges for 12 months with no exit fees.',
      is_variable: false,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2024-08-28T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'OUTGOING-FIX-12M-19-05-13',
      direction: 'EXPORT',
      full_name: 'Outgoing Octopus 12M Fixed May 2019',
      display_name: 'Outgoing Octopus 12M Fixed',
      description: 'Outgoing Octopus flat rate pays you for all exported energy at a flat rate.',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2019-05-16T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'OUTGOING-FIX-12M-BB-23-02-09',
      direction: 'EXPORT',
      full_name: 'Outgoing Octopus 12M Fixed February 2023 v1',
      display_name: 'Outgoing Octopus 12M Fixed',
      description: 'Outgoing Octopus flat rate pays you for all exported energy at a flat rate.',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2023-02-09T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'OUTGOING-LITE-FIX-12M-23-09-12',
      direction: 'EXPORT',
      full_name: 'Outgoing Octopus 12M Fixed Lite',
      display_name: 'Outgoing Octopus Fixed Lite',
      description: 'Outgoing Octopus Lite flat rate pays you for all exported energy at a flat rate.',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2023-09-14T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'OUTGOING-LITE-FIX-12M-BB-23-09-12',
      direction: 'EXPORT',
      full_name: 'Outgoing Octopus 12M Fixed Lite',
      display_name: 'Outgoing Octopus Fixed Lite',
      description: 'Outgoing Octopus Lite flat rate pays you for all exported energy at a flat rate.',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2023-09-14T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'OUTGOING-SEG-EO-FIX-12M-24-04-05',
      direction: 'EXPORT',
      full_name: 'Octopus Outgoing Smart Export Guarantee Export Only April 2024 v1',
      display_name: 'Octopus Outgoing Smart Export Guarantee Export Only',
      description: 'Outgoing SEG is our Smart Export Guarantee compliant export tariff for our export only accounts',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2024-04-05T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'OUTGOING-SEG-EO-FIX-12M-BB-24-04-05',
      direction: 'EXPORT',
      full_name: 'Octopus Outgoing Smart Export Guarantee Export Only April 2024 v1',
      display_name: 'Octopus Outgoing Smart Export Guarantee Export Only',
      description: 'Outgoing SEG is our Smart Export Guarantee compliant export tariff for our export only accounts',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2024-04-05T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'OUTGOING-SEG-FIX-12M-20-07-07',
      direction: 'EXPORT',
      full_name: 'Octopus Outgoing Smart Export Guarantee July 2020 v1',
      display_name: 'Octopus Outgoing Smart Export Guarantee',
      description: 'Outgoing SEG is our Smart Export Guarantee compliant export tariff',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2020-07-14T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'OUTGOING-SEG-FIX-12M-BB-23-02-09',
      direction: 'EXPORT',
      full_name: 'Octopus Outgoing Smart Export Guarantee February 2023 v1',
      display_name: 'Octopus Outgoing Smart Export Guarantee',
      description: 'Outgoing SEG is our Smart Export Guarantee compliant export tariff',
      is_variable: false,
      is_green: true,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: 12,
      available_from: '2023-02-09T00:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'POWER-PACK-24-02-15',
      direction: 'EXPORT',
      full_name: 'Octopus Power Pack',
      display_name: 'Octopus Power Pack',
      description: 'Octopus Power Pack',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2024-02-15T11:00:00Z',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'PREPAY-VAR-18-09-21',
      direction: 'IMPORT',
      full_name: 'Octopus Key and Card',
      display_name: 'Octopus Key and Card',
      description: 'Non-smart prepayment tariff',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: true,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2018-10-10T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'PREPAY-VAR-BB-23-04-01',
      direction: 'IMPORT',
      full_name: 'Octopus Key and Card',
      display_name: 'Octopus Key and Card',
      description: 'Non-smart prepayment tariff',
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: true,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-04-01T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    },
    {
      code: 'VAR-22-11-01',
      direction: 'IMPORT',
      full_name: 'Flexible Octopus',
      display_name: 'Flexible Octopus',
      description: 'Flexible Octopus prices follow wholesale costs and update every 3 months.\r\n' +
        '\r\n' +
        "Good to know: Ofgem has announced the energy price cap will rise from October 1. Flexible Octopus rates will also rise in October – we'll share details soon.",
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-03-28T10:35:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'OCTOPUS_ENERGY'
    },
    {
      code: 'VAR-BB-23-04-01',
      direction: 'IMPORT',
      full_name: 'Flexible Octopus',
      display_name: 'Flexible Octopus',
      description: 'Flexible Octopus prices follow wholesale costs and update every 3 months.\r\n' +
        '\r\n' +
        "Good to know: Ofgem has announced the energy price cap will rise from October 1. Flexible Octopus rates will also rise in October – we'll share details soon.",
      is_variable: true,
      is_green: false,
      is_tracker: false,
      is_prepay: false,
      is_business: false,
      is_restricted: false,
      term: null,
      available_from: '2023-04-01T00:00:00+01:00',
      available_to: null,
      links: [Array],
      brand: 'BULB'
    }
  ]
}
octopus energy get unit rates list
const myAPIKey = 'sk_live_VFeOb0cTK3MyfiMEsNLOXqTq'; // change into personal API key here
const myAccountno = 'xxxxxxxx'; // Your Account number
const myProductcodeImport = 'AGILE-24-04-03'; // the product code to use, like 'AGILE-24-04-03' (Octopus import), 'AGILE-BB-24-04-03' (Bulb import) and so forth
const myProductcodeExport = 'AGILE-OUTGOING-19-05-13'; // the product code to use, like 'AGILE-OUTGOING-19-05-13' (Octopus export), AGILE-OUTGOING-BB-23-02-28' (Bulb export) and so forth
const myProductcodeGas = 'xxxxxxxx'
const myTariffcode = 'xxxxx' // the tariffcode to use, like ..........
const myMpan = '1900091018842'; // Electricitymeter No.
const myMprn = 'xxxxxx'; // Gasmeter No.
const mySerialno = '19L3665047'; // Serialnumber of your meter

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

//// To return a list of unit rates and standing charges, add one of these to baseURL:
// const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/${myTariffcode}/standing-charges/`
// const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/${myTariffcode}/standard-unit-rates/`
const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/${myTariffcode}/day-unit-rates/`
// const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/${myTariffcode}/night-unit-rates/`
// const URL = baseURL + `${myProductcodeGas}/gas-tariffs/${myTariffcode}/standing-charges/`
// const URL = baseURL + `${myProductcodeGas}/gas-tariffs/${myTariffcode}/standard-unit-rates/`


const res = await fetch(URL, {
              headers : {
              'x-api-key': myAPIKey
              }
            });
            if (!res.ok) {
              throw new Error(res.status + '\n' + res.json); // 401 = unauthorised, 404 = not found
              return false;
            }

const json = await res.json();
//const value = json.value;
log (json);
return true;
octopus energy im-export tariffs
const myAPIKey = 'sk_live_VFeOb0cTK3MyfiMEsNLOXqTq'; // change into personal API key here
const myAccountno = 'xxxxxxxx'; // Your Account number
////////const myProductcodeImport = 'AGILE-24-04-03'; // the product code to use, like 'AGILE-24-04-03' (Octopus import), 'AGILE-BB-24-04-03' (Bulb import) and so forth
const myProductcodeExport = 'AGILE-OUTGOING-19-05-13'; // the product code to use, like 'AGILE-OUTGOING-19-05-13' (Octopus export), AGILE-OUTGOING-BB-23-02-28' (Bulb export) and so forth
const myProductcodeGas = 'xxxxxxxx'
const myTariffcode = 'xxxxx' // the tariffcode to use, like ..........
const myMpan = '1900091018842'; // Electricitymeter No.
const myMprn = 'xxxxxx'; // Gasmeter No.
const mySerialno = '19L3665047'; // Serialnumber of your meter

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

//// Uncomment 1 URL for electricity or gas tariffs ////
//// Electricity: uncomment 1 URL for import or export tariffs ////
//// electricity-tariffs IMPORT ////
const URL = baseURL + `${myProductcodeImport}/electricity-tariffs/${myTariffcode}/day-unit-rates/`;

//// electricity-tariffs EXPORT ////
//const URL = baseURL + `${myProductcodeExport}/electricity-tariffs/${myTariffcode}/day-unit-rates/`;

//// gas-tariffs ////
//const url = baseURL + `${myproductCodeGas}/gas-tariffs/${myTariffcode}/standard-unit-rates/`;


const res = await fetch(URL, {
              headers : {
              'x-api-key': myAPIKey
              }
            });
            if (!res.ok) {
              throw new Error(res.status + '\n' + res.json); // 401 = unauthorised, 404 = not found
              return false;
            }

const json = await res.json();
//const value = json.value;
log (json);
return true;
octopus energy elect/gas readings today
const myAPIKey = 'sk_live_VFeOb0cTK3MyfiMEsNLOXqTq'; // change into personal API key here
const myAccountno = 'xxxxxxxx'; // Your Account number
////////const myProductcodeImport = 'AGILE-24-04-03'; // the product code to use, like 'AGILE-24-04-03' (Octopus import), 'AGILE-BB-24-04-03' (Bulb import) and so forth
const myProductcodeExport = 'AGILE-OUTGOING-19-05-13'; // the product code to use, like 'AGILE-OUTGOING-19-05-13' (Octopus export), AGILE-OUTGOING-BB-23-02-28' (Bulb export) and so forth
const myProductcodeGas = 'xxxxxxxx'
const myTariffcode = 'xxxxx' // the tariffcode to use, like ..........
const myMpan = '1900091018842'; // Electricitymeter No.
const myMprn = 'xxxxxx'; // Gasmeter No.
const mySerialno = '19L3665047'; // Serialnumber of your meter

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

//// Get today's electricity / gas readings, add one of these to baseURL:
const URL = baseURL + `/electricity-meter-points/${myMpan}/meters/${mySerialno}/consumption/`;
//const URL = baseURL + `/gas-meter-points/${myMprn}/meters/${mySerialno}/consumption/`;

const res = await fetch(URL, {
              headers : {
              'x-api-key': myAPIKey
              }
            });
            if (!res.ok) {
              throw new Error(res.status + '\n' + res.json); // 401 = unauthorised, 404 = not found
              return false;
            }

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

I know the execution of fetchElectricityMeterData, fetchGasMeterData and fetchBillingDetails is commented out, but if you ever want to re-enable them I think the following can make the whole code 4 times faster:

(async () => {
    await Promise.all([
      fetchAccountDetails,
      fetchElectricityMeterData,
      fetchGasMeterData,
      fetchBillingDetails
    ]);
})();

Thanks for all the help so far.

I used Chat GPT to build some scripts for me.

This script returns the unit rates I’m on based on the hours of the day:

// Replace with your actual API key
const apiKey = ‘YOUR API HERE’;

// Define the product code and tariff code for Octopus Go
const productCode = ‘GO-VAR-22-10-14’;
const tariffCode = ‘E-1R-GO-VAR-22-10-14-A’;

// Define the date range for fetching tariff data
const periodFrom = new Date().toISOString();
const periodTo = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(); // Next 24 hours

// Construct the API endpoint URL
const url = https://api.octopus.energy/v1/products/${productCode}/electricity-tariffs/${tariffCode}/standard-unit-rates/?period_from=${periodFrom}&period_to=${periodTo};

// Fetch the tariff data
fetch(url, {
headers: {
‘Authorization’: Basic ${Buffer.from(apiKey + ':').toString('base64')}
}
})
.then(response => {
if (!response.ok) {
throw new Error(Error fetching data: ${response.statusText});
}
return response.json();
})
.then(data => {
// Process and use the tariff data as needed
data.results.forEach(rate => {
console.log(Price: ${rate.value_inc_vat} p/kWh);
console.log(Valid From: ${new Date(rate.valid_from).toLocaleString()});
console.log(Valid To: ${new Date(rate.valid_to).toLocaleString()});
});
})
.catch(error => {
console.error(‘Error:’, error);
});

As you can see here:

Then this script is giving what appears to be live data, although I am not sure it is the actual data as it doesn’t match the live data I can see on Voltaware or Octopus Mini IHD

// Replace with your actual API key, MPAN, and Meter Serial Number
const apiKey = ‘YOUR API HERE’;
const mpan = ‘YOUR MPAN HERE’;
const meterSerial = ‘YOUR METER SERIAL HERE’;

// Define the date range (last 24 hours to capture recent readings)
const periodFrom = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString().split(‘.’)[0] + ‘Z’;
const periodTo = new Date().toISOString().split(‘.’)[0] + ‘Z’;

// Construct the Octopus API endpoint
const url = https://api.octopus.energy/v1/electricity-meter-points/${mpan}/meters/${meterSerial}/consumption/?period_from=${periodFrom}&period_to=${periodTo}&page_size=1;

console.log(🔍 Fetching live energy data from: ${url});

fetch(url, {
headers: {
‘Authorization’: Basic ${Buffer.from(apiKey + ':').toString('base64')}
}
})
.then(response => {
console.log(🔄 API Response Status: ${response.status} ${response.statusText});
if (!response.ok) {
return response.text().then(text => {
throw new Error(⚠️ API Error: ${response.statusText} (Code: ${response.status}) - ${text});
});
}
return response.json();
})
.then(async (data) => {
if (data.results && data.results.length > 0) {
const latestConsumption = data.results[0];

  console.log(`✅ Latest Consumption: ${latestConsumption.consumption} kWh`);
  console.log(`🕒 Interval Start: ${new Date(latestConsumption.interval_start).toLocaleString()}`);
  console.log(`🕒 Interval End: ${new Date(latestConsumption.interval_end).toLocaleString()}`);

  // ✅ Store the consumption in a Homey variable (Tag) using the new function
  await tag('LiveEnergyUsage', latestConsumption.consumption);
  console.log(`✅ Homey tag "LiveEnergyUsage" updated successfully`);
} else {
  console.log('ℹ️ No consumption data available.');
}

})
.catch(error => {
console.error(‘:rotating_light: Error:’, error.message);
});

This is the output of that script which is not correct as that 0.168kWh latest consumption never changes. So I need to find out why it’s doing that as it only seems to pull the data from that one 30 min interval

Did you get anywhere with this? Id like to get my octopus tracker info into homey if possible.

Have you managed to get the script output into the energy app?

Thanks