Octopus Energy Agile Tariff

Dream combo, tesla powerwall and octopus…

do you have solar or just a powerwall curiuosly, even just a powerwall here would benefit from charging during night for the peak hours

all 3 :slightly_smiling_face:

5kw Solar edge system + 2 x Special Edition Red Powerwall 2 (one hand signed by Elon)

Almost the same here. 3 x powerwall, 12kw solar edge & model x.

Ive found myself here in the last week after switching from Octopus Go to Agile and looking for exactly the same as you - a way to charge the powerwall when price goes below X.

There is a web page called nureauwocket that will do this, but in my experience its a bit flakey and at times doesnt do what I expect.

There is EV energy that will do the same for the car, but again doesnt do what I would quite like. i.e. it doesnt use the regional variations of the agile prices, nor can it account for the solar or powerwall feeding the car during charging, so the cost calculations are out.

This octocost module is a great start, though id like to see it account for standing charge in the cost.

Im a complete novice at coding, and havent done anything since writing web pages in notepad at college a couple of decades ago - to say Im out of my depth here is an understatement to say the least.

Ive managed to set up Home Assistant, get octocost and both tesla modules set up and I even managed to change the decimal places on the octocost module (dont laugh, it took me ages to figure out and i just wanted to try and do something simple to start).

Now im at the stage where I want to convert the percentage left in the powerwalls to KWh, and then use the last X hours usage to give an estimated time that the powerwall will run out (either in X time remaining, or an estimated time of day it will run out)

I think its going to take a while before Im anywhere near capable of figuring out how to switch the powerwall into backup mode on a schedule defined by agile prices. Just the step above doing simole calculations with existing sensors requires me to do a lot of research.

Id be grateful of any assistance or input, and happy to help out if i can, or even share anything I come up with (if i manage it, but a blind squirrel occasionally finds a nut right?).

I’ve just updated to the latest HA version

Home Assistant 0.111.4

But i’m now struggling with the orginal command line curl sensor (in post 1).
Its been working for months, but since the update I get “Entity is non-numeric: sensor.electricity_cost”

But when I dig about I states etc I can see the state says ‘unknown’.

Anyone else having any trouble?

Hi Brian

After problems with the curl sensor i’ve decided to implement your Agile current pricing rest sensor.

The pull works, but its an hour out. I’ve tried time_zone as both GB and Europe/London as well as display current time on my dashboard which is correct. My underlying linux clock and TZ are all okay too.

Is the problem to do with Agile API storing as UTC?

Any thoughts on how to fix?

Please post your sensor config. Here’s mine, working fine on 0.111.0 and updated on the half-hour by a separate automation:

- platform: command_line
  name: Agile cost
  scan_interval: 86400
  command: curl \"https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-E/standard-unit-rates/?period_from={% set ts_now = ((as_timestamp(utcnow())/1800)|round(0,'floor')|int * 1800) %}{{ ts_now |timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', False) }}&period_to={{ (ts_now + 1800) |timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', False) }}\"
  value_template: '{{ (value_json.results[0].value_inc_vat) | round(2) }}'
  unit_of_measurement: 'p/kWh'

If I drop the bit in quotes into Developer Tools / Templates, I get (at the time of writing):

https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-E/standard-unit-rates/?period_from=2020-06-19T11:30:00Z&period_to=2020-06-19T12:00:00Z

which returns some JSON:

{"count":1,"next":null,"previous":null,"results":[{"value_exc_vat":6.53,"value_inc_vat":6.8565,"valid_from":"2020-06-19T11:30:00Z","valid_to":"2020-06-19T12:00:00Z"}]}

@Hodor, i am in almost the same situation as you (slightly less fancy) with the same goals and looks like I maybe a few steps ahead of you currently.

I have the following card, showing House load, Solar generation, Battery usage (- is charging, green line shows zero mark) and battery %:

image

The kWh calculation is quite easy using a template, I calculate this now but don’t use it yet, however, keep in mind the % from tesla is not linear so this is a “best guess” at what the % converts into. Also if you have any backup reserve etc etc.

I have the Tesla integration being able to set my battery into backup only (so it pulls from the grid) but still awaiting my smart meter so no point in using or automating this yet.

Apologies, the above is probably a bit off topic of just the “agile tariff”, when I get the smart meter, i will be linking the two

1 Like

Oh also, maybe of interest for people on this group i have a Solcast integration working that predicts the amount of Solar we will generate each day. So this will form part of my calculation on if i charge the Powerwall from the grid over night or not. You can see the prediction for tomorrow is way over a full charge, however today, is less than a full charge etc. etc.

It soon gets complicated but quite fun to gamify all of this. I will probably start a new thread when this is all working but need Covid to calm down a bit and let Octopus start working on Smart meters again first.

image

Let me know if you want more info

1 Like

This guy has been working on Solcast too…

1 Like

Yup i am using that as a base. Its not quite working yet, so having to mix and match a bit but they have done the hard legwork already (always nice).

1 Like

I also updated to 0.111.4 and the curl sensor stopped working. So I changed it to a rest sensor.

sensor:
  - platform: rest
    name: Agile cost
    scan_interval: 86400
    resource_template: "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-E/standard-unit-rates/?period_from={% set ts_now = ((as_timestamp(utcnow())/1800)|round(0,'floor')|int * 1800) %}{{ ts_now |timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', False) }}&period_to={{ (ts_now + 1800) |timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', False) }}"
    value_template: '{{ (value_json.results[0].value_inc_vat) | round(2) }}'
    unit_of_measurement: 'p/kWh'

Thanks for all this helpful info.

I’m just starting on Home Assistant and it’s quite a steep learning curve. I’m reading through loads of posts on this forum, which is a great help.

This ‘rest sensor’… do I just copy & paste this into the configuration.yaml file or does it need extra work as well?

I stopped using the rest sensor as it was hammering the Octopus API server - you can’t control how often it runs. I now use my node-RED node to pull the data and feed InfluxDB.

That is what an API should do!

I can’t remember, does the API return the time with a ‘Z’ on the end or +00:00. Python does not handle Z properly as the fromISO method is just the reverse of the toISO method which does not handle the Z format so is not a true fromISO converter. (Issue 35829: datetime: parse "Z" timezone suffix in fromisoformat() - Python tracker) - it is a feature not a bug. (Treating of time in Emoncms - UTC or BST - #10 by borpin - Emoncms - OpenEnergyMonitor Community)

The Node-RED is Javascript which does convert it correctly.

I don’t use the Agile Tariff but I am with Octopus so have been following this thread with interest.

I have other REST Sensors that I control using:

    scan_interval:
      minutes: 10

Have you checked it actually works? When I checked, I could see it being called more often than the set scan_interval.

The other issue here is that you want it to call every 30 mins on the hour/half hour. The REST sensor cannot be configured to do that. The Node-RED sensor I did only calls on the hour / half hour.

Definitely :slight_smile: Else I’d have been blocked form several services by now :wink:

Well you could do that by setting the scan_interval to something very big and then have an automation using:

      - service: homeassistant.update_entity
        entity_id: sensor.octopus

Which is actually what I do. It works well but I don’t use Node Red so don’t have that choice.

1 Like

Just try it: it should work. Note that the Octopus URL includes your region code, which is the last character in the E-1R-AGILE-18-02-21-E part of the URL. You’ll need to find yours from your account page.

Brilliant - thanks for that. It works a treat.

Not sure what I’m doing wrong - but what goes in the ‘auth’ box?

@ringle it’s the api key from here: https://octopus.energy/dashboard/developer/