Octopus Agile api use with Hubitat

I would like to use the api that Octopus energy provide for their Agile tariff (which is a time of use rate) to control smart plugs with Hubitat to operate a device during lowest cost periods at night. The api gives a look ahead to the price for each half hour over the next 24 hours, which is published at 16:00 UTC every day.

I plan to use this to charge any household battery devices (typically, personal handheld devices, laptop PCs, vacuum cleaners, and my ebike) when the cost of electricity is at its lowest.

Since it won't be possible to measure the charge state of the batteries to set a charging duration, I plan to use the api to identify the cheapest of a given number of night time half hours to switch the smart plug on for.

With smaller household devices this might only be a coupe of hours. For the ebike battery this is likely to be nearer to six hours (and therefore would target the cheapest twelve half hours). A separate smart plug could be used for each overall charge duration, to ensure a tight focus on the cheapest periods.

In each case the devices own BMS (battery management system) should stop drawing charge when the battery reaches the target charge level, which will usually be 100%, but in the case of my ebike charger can be set to 80, 90, or 100%.

I have read about the use of api's with Hubitat, but so far have not come across any mention of their use for home energy management (which in this particular case is termed "load shifting").

Can anyone help?

PS I'm a comparative newbie with Hubitat, so please don't assume a high degree of experience with home automation, or api's.

If you have a link to any details on the API that would be helpful.... Or any existing examples of others having utilised the API in other home automation systems.

Thanks so much for stepping forward to discuss the sburke781.

Here is a link to the developer's guide for the Octopus Energy api Octopus Energy APIs — Octopus Energy API 1.0 documentation

And here are examples of its use, which you will see includes at least one other home automation system Works with Octopus API - Energy Stats UK

I suspect that the list of examples is not entirely complete or up to date, since I know that the cloud services for the management of my home battery stoarge use the Octopus api as well (I have the 10kWh AC model) Battery Storage For Solar Panels | Puredrive Energy Domestic Battery

Hope you can help.

Nice work to research this @john_easton, it does look relatively straight forward in terms of an API to implement, once (you) the user provides an API key the rest looks pretty easy.... Anyone.... :slight_smile:

I may be able to get to it, but it would be fair wait. I tend to take on more than I should. If someone from the UK is interested I'd be happy to help guide them through it.


I may well take a look at this since I'm in the process of being transferred to Octopus, but it'll probably need to wait until they can install a new smart meter.

1 Like

That's great news Rob, I hope that your move to Octopus Energy goes smoothly.

You will certainly need to have your Smart Meter/s installed and working before you actively trial the use of their API with Hubitat. But there are things that you might be able to investigate beforehand in rediness for that. Their https://tech.octopus.energy/ might also be useful for that, depending on how techy you are.

Do let me know how it goes for you.

I'm fairly techy, been a programmer for about 40 years :slight_smile:

Thanks for that link.

I do have a smart meter already, but I think it's only SMETS1 (and not necessarily the right type)

Finally made a limited start on this, it looks as though given the account number and the API key I can create all the meters as devices automatically. Once that's done I'll see what can be done about retrieving the half-hourly prices (although at the moment they mostly seem to be at, or just below the capped rate).


That's great news Rob. Do let us know how you get on.

You are correct about the half hourly rate presently, but I suspect the 35p cap will be raised (unfortunatley) which will make the tariff much more attractive again, particulalry since there will still be part of some days when the rate is likley to be negative.

Well done Rob.

Very interested in this as im heading down the solar and batteries route.

Are u looking at export as well?

Not sure what the feature set is going to be yet, more than happy to listen to suggestions.

If as a minimum it would be great to be able to trigger events based on the prevailling Octopus time of use rate. e.g. switch on a plug if the half hourly rate is less than #p/kWh, and/or switch off when it is above #p/kWh.

It would be useful to be able to monitor the Octopus outgoing rates too, but I'm less sure what practical uses that could be put to.

1 Like

Out going would work if you have a battery, if it ever goes higher than the import empty battery to the grid.

Not massively important but would be useful.

That would be useful for someone who has built their own battery and/or solar installation, and could be very helpful in those circumstances.

My own battery comes with cloud services that optimises storage, import, and export. It uses a solar API and the Octopus API to automate that, in conjunction with an algorythm which learns patterns of consumption in the home.

What the smart battery stoarge isn't able to do however, is to see or manage how the overall domestic load is built up (my car charger comes with its own cloud services that uses the Octopus API to manage BEV charging).

What would be really useful then would be a means of allowing Hubitat to manage home device use to optimise for the time of use electricity price.

Just thought I should keep you up to date with the development.

I currently have a working main app where you enter your account number and API key, with a child app for each import electricity meter and a corresponding device which can fetch the prices (currently that's a device command rather than on a schedule). The child app and corresponding device are created automatically when you click the update button.

The child app allows you to specify named price bands, the ultimate goal of which will be to inform you in some fashion about the current (and possibly upcoming) price band the meter is in.

There will probably be a special notification for plunge pricing (which we hit in my area for the first time last Saturday since I've been with Octopus).

It's been slow going as my time is fairly limited at present, but it's ticking along.

In its current state it's not suitable for any automations I'm afraid.

I'd like to add consumption data at some point, in order to predict what a bill will look like, but that's a way off at the moment.


This is really great Rob, well done.

I wish that I had your skills, or even enough knowedge to understand the process more fully. My hope had been that the app could be used to trigger events based on price, eg if price is below X then run revice Y, or (better still) run device Y for X hours when the price is lowest in the coming 24 hours.

Is it resaonable to hope that this might be possible?


Yes, that's the sort of thing I'm aiming for.

Although I'd probably suggest that something like Rule Machine should be used for that.

I may make the bands into switches that get turned on when a price band comes into play. Possibly with a setting to only do it if it's more than some configurable number of half-hour slots. I suppose if a lower price band becomes current then it should leave the switch for the initial band turned on.

It's been a bit tricky doing anything with it the last few days since prices have been stuck at or near the cap for a while.

Hi there, just resurrecting this. Did anything ever come of it? Thanks!

I've got this working in principle, although i'm not using the API. Instead, I'm using the method shared by @LibraSun (thanks very much for this) in this post here:

as for how this is relevant to agile octopus, I've used IFTTT to populate the data daily into google sheets (a free applet so a pro membership is not required), some sheets functions to manipulate it into a format that hubitat can extract, and then created a rule using the guidance above that runs at 2330 each night to extract the data into a series of hub variables according to the half hourly values. It seems to work nicely for the first few variables i've entered (i've not put all 48 in yet); the only thing I need to confirm is if the sheets data will update in the background without me opening it. I think it should, but haven't confirmed.

In theory I can probably also write some google sheets formulae that calculate the cheapest 1 hour, 2 hour, 3 hour window and then export that time as a further variable to use in Hubitat, in order to trigger automations at certain times.

1 Like

I'm still only part way there - the problem is that when I find the time to work on it the rates seem to get stuck at 35p/kWh which makes it tricky to perform any tests.

I can see about putting the current code up on github though in case anyone wants to take it over.

Download the Hubitat app