Time of Use Electricity Supply - Octopus Energies

Hi all,

would anyone have any apps created which would be able to access Octopus’s api and bring back the current unit price for electricity? Octopus have several smart tariffs which change every half hour, in line with the actual unit cost of electricity. At certain points in the day, apparently, they also pay you to use electricity, so I’m currently looking to see if I can get this integrated into VeraPlus, so we can charge items around the house, run our air source heating, etc, and when the missus gets her electric car (which she’s started thinking about) charging that too.

The missing part of this, is the integration into Vera.

Thanks
Tony

How does that work.

I’ve thought about Octopus Energy a little bit knowing they have an API. Not currently with them however.

Api details.

Maybe a plugin like Site Sensor can be used to pull values in to Vera? Never used that plugin myself.

Or maybe there is some LUA code samples on the forum for this type of thing.

1 Like

Hi Stu,

hope you and the family are keeping well.

Octopus rely on customers having a working smart meter, and feeding back their usage every 30 mins. This is the flaw in our current house, Bulb installed a SMETS2 smart meter, but it has never worked in the 18 months since it was installed, but Octopus have agreed to come and install a new meter (or see if they can get the current one working) so we can then move onto one of their smarter tariffs.

So basically, when peak demand is high, between 4-7pm, prices rocket, but during the evening and overnight, the prices drop really low, and apparently for an hour a night (or it used to be), they actually pay customers to use the surplus electricity, which is generated and would be lost. So having a number of items in our house, run smartly, I plan to make the most of those cheaper hours and shift our usage accordingly.

If you’re interested, I have a reference code, which gives new customers £50 credit, and I get the same…

I’ll check out site sensor, see if I can access their api and pull in the data - that would be great, otherwise it may be a case of trying to write one… something I’ve not done on Vera, but would be up for the challenge!

Thanks
Tony

1 Like

FYI, I have a virtual meter, pulling some data from other sources, and it’s pretty easy to do. Just do an HTTP call to your endpoint and update urn:micasaverde-com:serviceId:EnergyMetering1 / KWH variable.

If you create a device from Apps, Develop Apps, Create device with:

  • D_PowerMeter1.xml as device filename
    you’re good to go, and you just need to update the variable (ie: via Reactor/Pleg/code/whatever).
1 Like

I am using Octopus Agile, and have created some simple LUA code to grab and process the daily prices.
This can be used with Scenes to turn devices on or off, and to sent alerts about prices, eg if the wholesale prices go very low, or even negative, then heating and charging can be turned on. Hue lights could be changed to indicate the current price.

At present, I increase room temps for my Air Source Heat Pump before peak time, then reduce it during peak. I disable my car from charging from the mains, and turn off a couple of my other devices. I have not seen any negative prices yet, but should get an email from Vera if prices plunge. I also check that my house battery charge is timed during the cheapest price period (and use the battery during the peak time).

The code and some instructions are on github at https://github.com/octoplayer2/Vera-OctopusAgile.
Ideally this should be wrapped up as a Virtual Device, but at present I have concentrated on making it do what I need. I hope it may also be useful for others, so any comments, suggestions or bug fixes welcome.
Also if you decide to switch to octopus energy, feel free to use my Introduction code to get us both £50. share.octopus.energy/denim-koala-967

Cheers
Octoplayer

3 Likes

Hi Octoplayer,

thanks - I’ve tried setting this up on my veraplus - for some reason the rate variables are not being changed, when we hit the specific times (for example the 4 hours of cheapest electricity).

Would it be possible, for you to add a couple of extra variables (I’ve tried but my knowledge is limited) - current price and next price ?

Thanks

Hi Tony,
Yep, I only update the rates once a day around 7pm, but should be able to add Current Price and NextPrice fairly quickly, they would be updated every 30 min.
Good idea, thanks

Feel free to take a look at my own Virtual HTTP Devices for inspiration on how to do a virtual device :wink:
GitHub - dbochicchio/vera-VirtualDevices: Virtual HTTP Devices plug-in for Vera and openLuup

VirtualAlarmPartition is the easiest, probably very similar to your use case.

1 Like

Thanks; I have modded the SolarMeter device, but that was too complex to act as basis for what should be a simple device. I’ll have a look at the Alarm Partition some time…
Cheers
Octo

1 Like

I have updated the code in Github to include the Current and Next prices. Only briefly tested, but it seems to be working.
Just copy the code into the scene LUA and press Submit. The new variables should appear on the next half-hour, or edit the ValidTilEpoch entry to a small timestamp, eg 0, and run the scene to get the updated values.

Cheers

1 Like

Thanks for the update, that’s working great. Do I need to ensure that the scene to submit every 30 mins?

Hi Tony,
The Code calculates how long to the next half-hour slots, adds 5s for good luck and sets a call-back for itself, so you don’t need to call it again.
If you do run the scene again manually, it will queue multiple instances of the callback. That should not hurt, but better to avoid just in case.
I start it with a call in the Startup code, so it is fully automatic.
Cheers

1 Like

I have an updated version coming soon, which fixes a bug in the Epoch time values, allows selection of inc or exc vat, and, gets the correct peak times if the system restarts during a peak.
Will post it on Github in a day or two after a bit more testing.

New version is now on GitHub https://github.com/octoplayer2/Vera-OctopusAgile.
Note I have tweaked the threshold for peak rate based on collecting some more recent data, and default prices are now including vat.

Octo

1 Like

Firstly, this code is great (and will remove the need for me to use a synced IFTTT Octopus → hue light % change to make triggers work in Vera - massive improvement).

I’m using this slightly differently (manually created sensor, but running the lua 120 seconds after luup reloads via a Reactor plugin sensor trigger. The variables are pulled into expressions in reactor too, and used as triggers from there).

Everything appears to be working great, but I see a slight discrepancy with the half hour prices in my account vs the current/next prices displayed in the Vera variables.

I have prices displayed in my account inc. VAT and they are today:
14:30 - 15:00 = 11.55
15:00 - 15:30 = 11.55
The tariff displayed on the Octopus API page is: E-1R-AGILE-18-02-21-M (which I set in the lua:
local Product = “AGILE-18-02-21”
local Tariff = “E-1R-AGILE-18-02-21-M”)

But… in Vera i’m seeing right now (@ 14:44)
Current: 11
Next: 11

The next set:
In account:
15:30 - 16:00 = 12.60
16:00 - 16:30 = 25.62

variables showing:
Current :12
Next: 24.4

The variables seem to change and be close, but I can’t figure out why they don’t quite match. Any idea’s (Could it be they are showing non VAT? , I see “Lowest Price - pence inc or exc VAT” in the readme, but it was not so clear which is displayed or if changeable )

It’s not a big deal, but it would be nice to know why :slight_smile:

Hi,
The reactor start is a good option, I occasionally have to restart to get rid of an “failed attempt to call a nil value” error, which may be due to calling the code before initialisation has finished.
Looks like I uploaded a version with the declarations duplicated and IncVat instead of IncVAT.
The price discrepancy was probably the VAT, although you should have 2 or more sig fig.

I have also just added a Pricing variable, to fix the price display to 2sf and put both values in a string for ease of display on my AltUI panel.
Hope that fixes the price issue, please post if it does not.

Cheers
octo

Thanks for this. The correction has resolved the pricing mismatch via account display and vera variables :slight_smile:

Currrently though the new “pricing” variable is displaying the same value, unsure if it has to run a cycle to be correct. Now i see:

CurrentPrice: 27.237
NextPrice: 30.45

Pricing Price now: 27.24, next=27.24p

As for the code launching, I now am deterred from using scenes. They disappear too easily if a device no longer exists and they sometimes mess things up if a reboot/luup reload happens mid scene.
I have created a trigger for ‘luup reloaded’ in Reactor with an activity of 120 second delay and then run lua and your code pasted in there. Seems to work perfectly.
In the same sensor I then define the expressions which are pulled from the virtual AgileMeter device.
This makes it then super easy to contain the code, when it runs, the data pulled and any actions or clever logic you may want to operate on devices and other expressions.

Really grateful for this integration, thanks!

One ‘customer comment’ might be in the help or description for the place where the virtual device # is inserted.
Its currently: “local AgileMeterId = TRV2[“AgileMeter”] – Insert Device ID of Agile Meter… Could make this autmatic one day”

TRV2[“AgileMeter”] is confusing. Really unsure what the TRV2 part is but I stripped all of that out and replaced with the device ID. More confusing if you (meaning when I) didn’t call the virtual device AgileMeter. I personally would have found something like this more intuitive (but maybe this is just me):
local AgileMeterId = [NewVirtualDeviceID] – Insert Device ID of Agile Meter…

I have one question though, what are the values displayed after the / in:
ValidTil 23:00/15
PeakStart 16:00 /14

P.S your text comment - autmatic :wink:

Hi,
Sorry for any confusion with TRV2 - I have been pasting the code into Github from my Vera, rather than the other way round, and I have a table of device names / numbers created as part of my start up. Rather than have to remember to edit the Id every time I paste it out, I have left it as I use it. I have ToDo note to automate extracting the Device Id automatically, but that would replicate code I have elsewhere, so it is low priority. :slight_smile:

The / nn is the day’s date, so the data set you have goes up to 23:00 on the 15th, and the peak being displayed starts at 16:00 on 14th. In the evening that should switch to show the next day’s peak. (I was using that to check that the correct peak is getting detected. I did not want tomorrows start and todays end! )

“Automatic” corrected, but did not make it into the current update

Thanks for the feedback and comments
Octo

Forgot to say, the Pricing display was a victim of copy and paste, with the same price displayed in both slots. When I did it the future price was the same anyway and I didnt notice…apologies
Octo

Hi,
No need to be sorry, just trying to make the code easier for everyone :slight_smile:
Although the pricing was corrected, I noticed that for some reason the callback wasn’t working on the new version, and values never updated unless I called the script again manually (running from Reactor at least). I reverted back to the old one late last night and it ran OK and updated again for the last few hours.

I’ll pull the latest copy now (0816) and update with my info and try it again. Could be something I did perhaps. Will feedback later.

This is going to be super useful, thanks for sharing :slight_smile:

Best Home Automation shopping experience. Shop at getvera!

© 2021 Ezlo Innovation, All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules