Octopus Energy Agile Tariff

Thanks for the reply, this prompted me to finally sort this out. For information @AP05TLE that doesn’t work during summer as all the values are 1 hour out. A simple fix is to add local=false in each of the timestamp_custom functions. So timestamp_custom (’%Y-%m-%dT%H:%M:%SZ’, local=false)

However, this solution hits the Octopus API servers every 30 seconds which seems wrong when the data is only updated once per day. My solution, currently in testing, is to create an automation that updates the rest sensor every 24 hours at 16:10pm. I still need to add a test to take action in case of failure…

alias: System - Energy - Update Octopus Outgoing
description: ''
trigger:
  - platform: time_pattern
    hours: '16'
    minutes: '10'
condition: []
action:
  - service: homeassistant.update_entity
    data: {}
    target:
      entity_id: sensor.octopus_outgoing
mode: single

and then create a template sensor that searches through the list to pull out the correct data for the 30 minute slot. The various triggers ensure the value is updated at restart etc. and defaults to 7.5p if an invalid result is obtained.

- trigger:
    - platform: time_pattern
      minutes: /30
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
    - platform: state
      entity_id: sensor.octopus_outgoing
  sensor:
    - name: Octopus Outgoing Current Price
      unit_of_measurement: 'p/kWh'
      state_class: measurement
      state: >-
        {% set ts_now = ((as_timestamp(now())/1800)|round(0,'floor')|int * 1800) %}
        {{ state_attr('sensor.octopus_outgoing', 'results')
          | selectattr('valid_from', 'equalto', (ts_now | timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', local=false)) )
          | map(attribute='value_inc_vat') | first | float(7.5) }}

I then set the scan_interval on the rest sensor to once per month to effectively disable the auto updates.

  - platform: rest
    name: octopus_outgoing
    scan_interval: 2678400   # every month
    resource_template: >-
      https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-A/standard-unit-rates/?period_from=
      {% set ts_now = ((as_timestamp(now())/1800)|round(0,'floor')|int * 1800) %}
      {{ ts_now | timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', local=false) }}&period_to=
      {{ (ts_now + 24*60*60) | timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', local=false) }}
    unit_of_measurement: 'p/kWh'
    value_template: >-
      {{ (value_json.results[-1].value_inc_vat) | float(7.5) }}
    json_attributes:
      - "results"

As I said, still in testing but seems OK so far.

Thanks @gedger - very helpful. I’ll give it a try
somewhere back in the depths of this post it was mentioned that setting scan interval didn’t work and the api was being hit anyway. Have you checked this in your tests?

Confirmed only updates once per day from the automation. I also made a change to get the data until midnight the next day rather than 24 hours.

This feels like a very stupid question (well it probably is) but just starting to look at this and skimming through the thread here this doesnt seem to be an issue for others but just trying to load up/install for the first time I dont know what to fill in on the front page? Do I need to bypass this by populating configuration.yaml?

I get the same when adding through the integration screen. Instead I’ve added the component in HACS and put the config in the configuration.yml file

Most likely because Python treats a TimeStamp with a ‘Z’ on the end as local time when it converts it.

As a further update I’ve now created a simple markdown card to display Octopus Outgoing data as a table. It only shows the future rates from now. The styling is done by the card-mod plugin so delete the style section if you don’t want to use this.

type: markdown
style:
  ha-markdown:
    $: |
      table {
        border-collapse: collapse;
        padding: 5px;
        width: 100%;
      }
      tr:nth-child(even)
        {background-color: #f2f2f2}
content: |
  Time | Price| 
  :--- | :--- | 
  {%- set results = state_attr('sensor.octopus_outgoing', 'results') %}
  {%- for record in results|reverse %}
  {%- set ts = as_timestamp(record.valid_from) %}
  {%- set ts_now = ((as_timestamp(now())/1800)|round(0,'floor')|int * 1800) %}
  {%- if ts >= ts_now %}
  {{ ts|timestamp_custom ('%H:%M', local=true) }} | {{ record.value_inc_vat }} |
  {%- endif %}
  {%- endfor %}
title: Octopus Outgoing
view_layout:
  position: sidebar

3 Likes

Hey everybody. Before I dust off the HA syntax docs, does anybody have the logic to select top X most £ per KW exported slots and trigger an action only for these per day?

I can find a lot of examples of if value > INT, but that could be 12 30 mins slots and my batteries would be flat after 4 slots, so ideally I want to limit it to the most profitable slots to force discharge my batteries.

Hello, Looks like this thread has not been touched in a long time (or I don’t understand the time stamps). World went and firmly stayed in the proverbial, but from an Octopus Agile point of view its getting better/cheaper it seems. October has seen 8 plunges at the time of post and many sub 10p slots. Average (based on nothing but glancing at energy-stats and agileprices website graphs) is about 20-25p which is cheaper than most tariffs available. How long this will last for, who knows, too much turmoil. I however am in the lucky position that I am capped at 35p till May 2023, while over Summer I almost never saw it dip below 35p its getting back to being rare to seeing it got to 35p over than 4-7pm.

Anyway, Has anyone been working on anything Agile related in HA? I have the Octopus Energy and Octopus Agile HACS integrations working which works great for viewing and basic on/off scenarios for plunges and user defined cheaper than scenarios, has anyone got anything new to share?

I have just had 6kw of Solar Panels and 9.5kwh battery installed to mitigate the insanity to a point and should finally be able to export as of Monday and be paid for it. Sadly Agile Outgoing has the negative impact of the cheaper energy mentioned earlier. Will still stick with it though for a bit even though Octopus SEG is now 15p per kwh. May switch once calculations have been done as to what works out better.

My ideal scenario would be to maximise the plant I have to minimise cost of import and maximise the cost of export. This would need to be timed and scripted carefully.

So specifically I need:

  1. a way to charge my battery on plunges but never overshoot. Octoblock seemed the best option for this but not available in HACS and if I try to install custom repo to the git then it errors with “<Integration badguy99/octoblock> Repository structure for v0.2.2 is not compliant”. Was hoping it would do 30 minute minimum as a block too but does not seem to work. Installed Manually.

  2. a method to charge my battery from the cheapest slots IF the solar won’t cover the demand

  3. exporting of energy at the peak prices. Import needs to be lower than export price at all times.

So in a nut shell, act as a cost effective battery for the grid with Solar being the preference source.

Hoping I don’t have to re-invent the wheel here and that the silence is just temporary. Would love to never have to look at the logo again one day and just sit back in the confidence that there is no other earthly way to get cheaper energy and be maximising the return on my investment.

Look forward to this threads revival (or am I alone now? and just a mad man shouting into a long emptied event hall…?)

2 Likes

Octoblock does that, maybe worth looking at that as a starting point. Single py file really. GitHub - badguy99/octoblock: Octoblock is an app which works under AppDaemon within Home Assistant which finds the cheapest “n” hour block for import or the most expensive “n” hour block for export, and works out the price of that block, for the Octopus Energy, Agile Octopus / Agile Outgoing Octopus tariffs.
Deso not seem to adjust for daylight saving time though. Still a good place to start.

So… I’m getting my kit installed in a couple of weeks and have been playing with some Python code to optimise usage based on historical data. My objective is to write something in appDaemon that will optimise the next 24 hours based on forecast.solar, my typical usage for a xxxday in month and the tariff I am on. At present I’m on Octopus Eco7 and I’m not sure whether I will switch to Agile. My gut tells me that this we are in the lull before the storm for Eurpoean utility prices: gas stores are full, the weather is mild, there’s still some solar being generated but it’s been pretty windy. Long term wholesale energy prices are still high so the market says it’s a temporary blip. That said, there is more scope for optimising usage when on a fixed rather than an agile tariff - though with limited solar at present it seems to be as simple as “charge your battery at night”:

So once I have the kit installed and some real data to work wth I will see what can be done for real…

I don’t suppose anyone has the knowledge to display the Outgoing rates using the Agile rates card? I would like the outputs in the same format but cannot seem to make it work :frowning:

I have tried to adjust a copy of the agile-rates-card.js to use the attributes format from the sensor.octopus_outgoing but my limited JS coding skills are holding me back.

see post 539 above

Thanks, yes i have this but the formatting is not the same and I am struggling to get that looking the same.

Hi so i might me able to help with getting Octoblock on to your HA. Ive just been trying to work out the same thing as you and been able to add it to HA without using HACS as i got the same error as you. For a while i was trying to add the information as i would for any other sensor in the config file for HA and custom components folder. But as it turns out it needs to be within the App Deamon folders.

Steps as follows:

  1. Make sure that app Daemon and file editor are installed.
  2. Download the Git repository for Octoblock
  3. Using file editor copy the ‘octoblock.py’ file into the config/appdeamon/apps folder
  4. add the templated code to the apps file from the github apps.yaml area that starts with ‘octoblock:
    module: octoblock’
  5. If you restart the app deamon add on you should see those sensors in HA
  6. you can then edit the parameters following the Github to choose what you want out of those entities

That’s about as far as ive got so far.

1 Like

We are back on Agile after a year away on Go, so I am trying to put everything back.
Something we used a lot was the rates card from MarkG, but as both it and the integration that drove it are no longer maintained and are appear to be broken, I wonder if anyone had an alternative.

I see above there is an outgoing rates card that has been developed, which I have tried to modify, but without much luck. I can see the content is in the Octopus integration under sensor.octopus_energy_electricity_xxxx_xxxxx_current_rate but haven’t found an easy way to extract it. Does anyone have anything I can borrow?

I am in the same boat. I have moved to Agile a couple of days ago. I use the Octopus integration and then markdown card to display simple table with the upcoming rates.


type: markdown
content: >
  Time &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Price

  {%- set results =
  state_attr('sensor.octopus_energy_electricity_xxxxxxxx_xxxxxxxxxx_current_rate',
  'rates') %}

  {%- for record in results %}

  {%- set ts = as_timestamp(record.from) %}

  {%- set ts_now = ((as_timestamp(now())/1800)|round(0,'floor')|int * 1800) %}

  {%- if ts >= ts_now %}

  {{ ts|timestamp_custom ('%H:%M', local=true)

  }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {{

  record.rate }}

  {%- endif %}

  {%- endfor %}
title: Octopus Agile Rates

2 Likes

My head hurts from reading all of this! I’m not having any luck getting GitHub - markgdev/home-assistant_OctopusAgile: Octopus Agile custom component for Home Assistant installed and working, I assume it’s broken.

All I’m looking to do is get the upcoming rates into a card in home assistant, anyone help with the format to do that?

You should be using Octopus integration:
https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy
Octopus Agile as per the github comment is no longer maintained

As for the rates look two posts above

2 Likes

It just took some time to update.

Thanks again.