Skip to content

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.

License

Notifications You must be signed in to change notification settings

badguy99/octoblock

Repository files navigation

octoblock

hacs_badge

Codacy Badge

If you think this will be useful to you, please consider signing up to Octopus Energy with my referral code: https://share.octopus.energy/dense-ape-125 - You'll get £50 credit too!

Contributions Only

I no longer use Agile Octopus tariffs, and do not plan on making any more updates to this code. As such if you want something, please feel free to fork the code and make changes. I will happily merge received PRs.

Summary

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.

It creates and sets sensors for the cost and start time, for example, using the apps.yaml file below, the following entities are created and then updated:

sensor.octopus_1hour_time
sensor.octopus_1hour_price
sensor.octopus_1_5hour_time
sensor.octopus_1_5hour_price

Sensors for export will be created with naming such as:

sensor.octopus_export_1hour_time
sensor.octopus_export_1hour_price

Sensor names can be overridden and your own name specified in the yaml configuration. These will be of the format sensor.<your_name>_time and sensor.<your_name>_price with any dots in <your_name> changed to underscores.

Special Cases

With start_period set to now and hour set to 0 the current import or export price is returned, and the sensors are named:

sensor.octopus_current_price
sensor.octopus_export_current_price

With start_period set to now and hour set to next the next import or export price is returned, and the sensors are named:

sensor.octopus_next_price
sensor.octopus_export_next_price

Installation

Use HACS or download the octoblock directory from inside the apps directory here to your local apps directory, then add and customise the following configuration to appdaemon/apps/apps.yaml to enable the octoblock module.

Example apps.yaml Configuration

octoblock:
  module: octoblock
  class: OctoBlock
  region: H
  import_code: AGILE-FLEX-22-11-25
  export_code: AGILE-OUTGOING-19-05-13
  use_timezone: False
  price_round: 2
  time_format: "%Y-%m-%dT%H:%M:%S%Z"
  blocks:
    - hour: 1
      import: True
      start_period: now
      name: octopus_1hour
    - hour: 1.5
      start_period: today
      name: octopus_vacuum
      limits:
        start_time: '07:00'
        end_time: '16:00'
    - hour: 2
      import: True
      start_period: now
    - hour: 0
      start_period: now
      name: octopus_current_import
    - hour: 0
      export: True
      import: False
      start_period: now
      name: octopus_current_export
  lookaheads:
    - price: 3.0
      operation: below
      and_equal: True
      duration_ahead: 12
      name: hw_via_electric_not_gas

The module and class sections need to remain as above, other sections should be changed as required.

Octoblock module

region is the region letter (e.g. H) from the end of your tariff code which will look something like E-1R-AGILE-18-02-21-H. The tariff code used to be found on the Octopus Energy developer dashboard webpage in the Unit Rates section for your account, but Octopus seem to have removed this.

The easiest way now to get the tarrif code (and region) for your import and export account is using the Octopus Energy Integration:

Install, configure and start the integration, go to Developer Tools/States and filter on current_day_rates, then look at the attributes of the _current_day_rates and _export_current_day_rates entities for the tarrif_code attribute which will be formatted something like E-1R-AGILE-FLEX-22-11-25-H.

import_code and export_code should be specified from the tariff code retrieved above with the preceeding E-1R- and the trailing -H removed. If not specified they default to AGILE-FLEX-22-11-25 and AGILE-OUTGOING-19-05-13 respectively.

NB: If you get the tariff code wrong (e.g. forget to remove the E-1R- prefix or -H suffix) you will get an error ERROR octoblock: Error 404 getting incoming tariff data: {"detail":"Not found."} reported in the appdaemon log and the rest of the octoblock configuration (custom blocks etc) will be ignored!

use_timezone can be set to True or False, and defaults to False, it allows you to specify if the date/time should be displayed in UTC (False), or using Europe/London (True) as the timezone. For example, 2020-03-29T02:00:00Z or 2020-03-29T03:00:00 BST respectively.

price_round can be set to the number of decimal places to round the average price for the specified period to, and defaults to 4 if not specified. For example, set to 2 to round to 2 decimal places, e.g. 14.56 p/kWh.

time_format can be set to a strftime format code that the date/time that the block starts at. If not specified it defaults to %Y-%m-%dT%H:%M:%S%Z, e.g. 2020-03-19T20:00:00Z. An easier to read and shorter time format for example could be %a %-I:%M %p which would display the block start time as Tue 1:30 AM. Note that if you change the time_format from the default then you may need to adjust any automation scripts so that they can still match the returned block time. If you are only displaying the block time in a Lovelace UI dashboard display as shown below then this won't be an issue.

Blocks

You can have multiple blocks with different time periods (hour setting) or starting points (start_period setting) as needed. It will work with whole hour or half hour blocks in the hour setting.

start_period is optional, it can be set to either now or today, and will default to now

now and today give subtly different results. now is re-evaluated every time the callback is run (once every 30 minutes), and today uses a start time of 00:00:00 with today's date.

This means that using today you will get the absolute cheapest block for today, even if that is in the past, and using now will get the cheapest block for the remainder of the day. today may be of more use with automated triggers, and now may be of use when you are wanting to display the cheapest time on a Lovelace UI card and use that information to turn on devices which cannot be automated, by hand.

This may be best illustrated with a couple of pictures:

State information with now start period

Using now start_period this has turned on and off a few times within the day as it is reevaluated as the day goes on

State information with today start period

Using today start_period this has only turned on once during the day

Setting start_period to now and hours to 0 will give the current import or export price.

When using today for the start_period it can be limited further usings limits > start_time and/or limits > end_time (please note the formating in the example yaml above) to restrict the period searched. This may be useful for example if you have something that you only want to run within certain times of the day, due to noise issues etc.

import and export should be set to True or False as required, import: True and export: False for the Agile Octopus tariff, and import: False and export: True for the Agile Outgoing Octopus tariff.

Lookaheads

Look aheads provide a HA sensor that will be set to true if the price will go below or above (depending upon operation setting) a specified point, x, within the next duration_ahead hours, up to the maximum look ahead that Octopus Energy provide price data for.

Setting operation to above or below and and_equal to True or False in the yaml file give different functions; namely: greater than, less than, greater than & equal, and less than and equal. Such that it should be possible to set up required trigger points looking at prices in the future for automations.

Home Assistant Automation

The created start time sensors can then be used to trigger automations within Home Assistant. This requires the Time Date integration to be configured as well. The triggers such as the following can be set up to trigger the automations.

  trigger:
  - platform: template
    value_template: '{% if (states("sensor.date_time_iso") + (" BST"))  == (states("sensor.octopus_1hour_time"))
      or (states("sensor.date_time_iso") + (" GMT"))  == (states("sensor.octopus_1hour_time"))
      -%} True {%- endif %}'

Lovelace UI Cards

Once the sensors are created, they can be displayed as cards within the Lovelace UI. For example:

type: entities
title: Best 1hr Price
show_header_toggle: false
entities:
  - entity: sensor.octopus_1hour_price
    icon: 'mdi:flash'
    name: Price
  - entity: sensor.octopus_1hour_time
    icon: 'mdi:clock-outline'
    name: Time
        
type: entities
title: Best 1.5hr Price
show_header_toggle: false
entities:
  - entity: sensor.octopus_1_5hour_price
    icon: 'mdi:flash'
    name: Price
  - entity: sensor.octopus_1_5hour_time
    icon: 'mdi:clock-outline'
    name: Time

Lovelace UI best usage time example cards

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages