Octopus Energy Agile Tariff

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/

Hi. I managed a little while ago to get a dashboard set, I also found the powerwall api percentage not matching with the app.

Apparently there is around a 5% reserve (additional to the reserve we can set in the app) so to get a better match you need to do 95/100 of the api reported percentage (though this still drifts when below 30% soc).

Have you found a way to switch your PW to backup mode based on the agile pricing, either current or future?

I can pull stuff from the tesla api, but does it accept post to change the mode?

Yep using the Tesla powerwall custom component I can set it backup only (pulls from the grid) when ever it is less than £0.05 and less then 80% full or negative (I get paid £0.05 outgoing so even if we overfilled the battery it’s still free)

Hi, would you mind sharing how you did this to an absolute beginner?

I’ve got a dashboard showing the stuff I can pull, like powerwall charge, solar incoming and octopus current price.

Can you advise how you took the octopus price and used this to change the powerwall?

As a beginner with HA I’m just about confident in pulling stuff from an api to a sensor, but sending commands based on other sensors and getting it to do this every half hour, or building a schedule for the next 24 hours etc is my next step of learning.