Octopus Energy - Rule based on cost of electricity

No idea if I am posting this in the right place, or whether it has been discussed before but I am new to the Hubitat world, and my searching found nothing useful.

I was hoping to find a way of automating certain functions based on the cost of electricity. I am on Agile Octopus, a variable energy tariff which changes cost every 30 mins, but the cost for each 30 min time period is published in advance (normally about 4pm day before). This information is available from a relatively simple API published by Octopus (API Details).

I have not been able to find a driver or app which someone else has created, and I am not a developer so not sure I would be able to create my own, but wondered if anyone has considered something like this or done something similar which I could base work on?

Thanks in advance

They're IFTTT compatible and so is HE. Maybe that will get you what you need in the meantime.

I've been looking for the exact same thing recently; I'm not on Octopus energy yet but am considering doing so and would like to know i can automate things intelligently based upon electricity price. IFTTT might do what i want, but i'd like to do it natively.

I've not seen any smartthings integrations that I can have a crack at porting, nor have i found any similar APIs that i can try to adapt to the specific requirements of Octopus.
I am an absolute beginner when it comes to writing drivers, so it'd be a long term project!

I wonder if between us (I am IT competent but no software developer) we can make something work if we can find a driver template which accesses an API.

I will have a search through the forums this weekend.

Took a quick look at this just to see what it was (I'm across the pond and we don't have this here).... Looks like you could use the REST API and then process the httpResponse object to get the data without too much issue. Biggest hurdle, if you haven't developed a driver yet will be get the structure in place to make/receive the calls - I'll see if there are a couple examples of this that you could use as a starting point.

Thank you @thebearmay any pointers would be much appreciated.

I have been looking for two examples;

  1. a simple driver (or the base code for a driver which I can build on)
  2. anything which does a web call to get data from an endpoint to refer to (or plagiarise)

I just threw this one out there for some other uses, but feel free all or part to use as a starting point:


It's using an httpGet, but other versions are documented at:



Thank you.

Reading and seeing how badly I can mess this up now :slight_smile:


I'm working my way through this, and think i have the basic structure sorted, but as I have now got to the point of trying my first API call to Octopus have realised that the httpGet does not appear to support sending HTTP Basic Auth (unless I am missing something).


From the Octopus API documentation:


Authentication is required for some API end-points. This is performed via HTTP Basic Auth.

Provide your API key as the Basic Auth username value.

curl -u "$API_KEY:" https://api.octopus.energy/v1/accounts/

Any suggestions?

Just started looking at that myself. In the params, you should be able to add an entry for headers with something like
[Authorization: Basic API-key]
as its value.

I've opted for the following, will be testing sometime this weekend...

Authorization: Basic "'${apiSecret}':"

Still plenty of bits to write / delete before I am prepared to stick this code into my Hub and see what happens :smiley:

Hopefully that should work with my configurable input bit:

preferences {
    input "apiSecret", "text", title: "Agile Octopus API Secret Key", description: "in form of sk_live_acbDEF123ACBdef321", required: true, displayDuringSetup: true

Bear in mind the cost varies based on which region you are in too so you have to provide that info as well.

I applied for Agile 12 months ago and they did get a Smart meter installed in April but they have , thus far, failed to get me connected.

From another platform... just for ideas


Headers is expecting a map entry so it will need to be inside of [..]

Yeh, so the initial bit of coding I am trying to get sorted is

on install

  • confirm API key defined
  • confirm account ID defined
  • connect API to retrieve ProductCode and TariffCode (and hope I can identify the useful one if there are more than one)
  • store values

When that is sorted I will move on to getting the actual costs starting with cost of current period.

1 Like

Full block is:

def params = [
    uri: "https://api.octopus.energy/",
    timeout: 20
		Authorization: Basic "'${apiSecret}':"

Although I am yet to work out the necessary URI for what i am hoping to achieve

Thinking it may be more like:

def params = [
    uri: "https://api.octopus.energy/",
    timeout: 20,
    headers: [Authorization: β€œBasic ${apiSecret}”]
1 Like

Got it, thanks.

1 Like

So I now have one answer:

[dev:234]( 15:39:15.294 [error]( Unauthorized on line 95 (initialize)

I'm now reading about httpGet to see what magic I can do. This is really good because when I put in a different uri I get different reponse success :slight_smile:
Does that make it a successful failure?

So I've been doing some reading about this, and I think because Hubitat do not directly expose the http capabilities to use (hidden behind httpGet) I cannot do what I need to. I think it is the abstraction they do which is going to kill me here.

My next approach is to look at what I can do with the Octopus public API endpoints (no auth).

Download the Hubitat app