Octopus Energy Agile Tariff

I’ve managed to get the octopus energy agile pricing working directly via a curl command as i was having issues with IFTTT delays

image

You may have to edit the API URL to retrieve the agile pricing for you region. Those values can be found on the octopus developers page. YOU DO NOT NEED YOUR API KEY FOR THIS TO WORK

sensor code is;

sensor:
  - platform: command_line
    name: electricity_cost
    scan_interval: 86400
    command: curl \"https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-F/standard-unit-rates/?period_from={{ now().year }}-{{ now().month }}-{{ now().day }}T{{ now().hour }}:{% if now().minute <30 %}00{% else %}30{% endif %}&period_to={{ now().year }}-{{ now().month }}-{% if (now().hour == 23) and (now().minute >=30) %}{{ now().day+1 }}{% else %}{{ now().day }}{% endif %}T{% if (now().hour == 23) and (now().minute >=30) %}00{% elif now().minute >=30 %}{{ now().hour+1}}{% else %}{{ now().hour}}{% endif %}:{% if now().minute >=30 %}00{% else %}30{% endif %}\"
    value_template: '{{ (value_json.results[0].value_inc_vat) | round(2) }}'
    unit_of_measurement: 'p/KWH'

I also added some automation to periodically update the pricing as to not spam the Octopus API

- id: '1578085069925'
  alias: Update Octopus Agile Price
  description: ''
  trigger:
  - hours: '*'
    minutes: '30'
    platform: time_pattern
    seconds: '0'
  - hours: '*'
    minutes: '0'
    platform: time_pattern
    seconds: '0'
  condition: []
  action:
  - data:
      entity_id: sensor.electrictiy_cost
    service: homeassistant.update_entity

Hope someone finds this useful!

Thanks for this! First day with Hassio and mainly want to make use of the Octopus Agile API, not quite as easy as I thought!

I have copied your ‘sensor code’ into configuration.yaml which seems to work… is that correct?

Where does the ‘automation’ go?

And how did you create the nice semicircular graph?

Many thanks!

Yes then the automation bit goes in automation.yaml. The automation bit is to only call the api on the hour and on the half hour.

To display in in the format i have it in you need to add a gauge to your home page and the select the sensor youve just created.

Thanks, that’s great!

Really getting into this now and seems a great way to make full use of Agile.

BTW my main use is to make ‘smart’ my very old Economy 7 heaters (electrician installing contactors controlled by a Sonoff which I will flash with Tasmota) avoiding cloud based issues. Going to try and use some Zigbee temperature sensors, your Agile pricing sensor and person tracking to only heat when really needed and when the price is low enough…

J

Interesting, thanks! I have just been looking at the tariff and thought that using HA to automate things based on the tariff would be interesting. Eg. switch on the dishwasher or tumble drier at the cheapest point overnight (yes, I appreciate the fire hazards, perhaps I need a smart smoke detector too!)

They generate the following day’s tariff daily “usually” around 4pm, so it might be possible to schedule a single download and cache it I think?

I’m currently with Bulb, but after having a SMETS2 meter installed I find I can’t actually use their best smart tariff, and they don’t have any sort of detailed usage API available, so I might jump ship…

Yes, eventually want to be a bit smarter, but at the moment just switching below/above thresholds. Want to work out how to calculate lowest cost periods* for similar reasons to you @Gareth79, and maybe start controlling my immersion heater too.

  • You can do this using Octopus’ IFTTT triggers already but want to move away from IFTTT as find it unreliable

@dmgreen have you, or seen someone, look ahead at the cost to schedule automations?

I, like @Gareth79, am looking to, for example “turn on X when cost is at lowest average price for 2 hours tomorrow”

Don’t want to reinvent the wheel if you have seen it elsewhere!

J