Octopus Energy Agile Tariff

Im using HA Core so no HACS. I have the component installed but i wasnt 100% sure how to configure it. I added my details, not sure what start date refers to and i didnt want to use money makers or timers which i believe you can just leave blank but the component had an error on launch.

ive since disabled it anyway and have been looking at the restful component instead. I can get all the results but displaying them is a different story.

It looks like you’re (@eximo84) just going to have to try it and see what works. I’m just trying to get the agile rates card to work first it was complaining about the comment line (So not sure why have it in the example ??) … now I’m thinking it’s because the install says Url: /local/…

Yeah this is where HA and HACs becomes ’ oh so confusing for the first time.’ It’s enough to put you off HA sometimes :slight_smile: and as for YAML — well it really lives up to the name, maybe should have been called YAFUML.

Maybe take a look at HACs to have that installed and then

I’ve been a lurker on this for a while, way before I signed up, I do have to hit my head on a table sometimes at the instructions as they are not intuitive.

In short welcome to the testing team :cowboy_hat_face: of the wild-wild-west

I’ve finally got the configuration working (with lovelace cards) … and as @baz123 pointed out I can see currently that something (the rest interface maybe) is spamming the octopus servers, even more than my echo dots to the usual amazon servers.

The start date is used for calculating your historic cost. You can put in whatever you like as long as it’s after the date that octopus started receiving your half hourly data.
If you did want to get going with the custom component, feel free to chuck an issue with the error you have on GitHub and I will try and help.

Is the HACS installation working? I just added the repo, restarted HA and then tried to install the component but I get what looks like a dialog with no field labels that looks like this:
OctopusAgileHACS

I’m guessing this is asking for stuff like region code/API key, but in what order?

So it should install with HACS but then configuration is still done through configuration.yaml. Did it install the component in your custom components directory already? :crossed_fingers:

Yes I think so. There’s an octopusagile folder under config/custom_components with some python files in there.

If I just want to add now/next prices to my home dashboard for now, how much of the configuration.yaml example do I need? Is it just down to the startdate line, and then the sensor declaration, like this?:

octopusagile:
  region_code: "H"
  mpan: <my mpan>
  serial: <my serial>
  auth: <my auth>
  startdate: "2020-05-08" << what goes here? Is it the date I joined Agile?
sensor:
- platform: "octopusagile"

I’m pretty certain that’ll do it. You may need to add an empty entry for timers and moneymakers.
You’re right that it’s the date you joined agile.

I’ve just installed octopusagile today and I’m trying to get the hang of the timers sections. Is there a way to force the evaluation to happen now rather than wait until 1900Z ?

Yup, you can call the service “octopusagile.update_timers” from Developer tools -> Services. Same with testing the timers triggering but call “octopusagile.half_hour”

Hi, thanks for replying to me , unfortunately trying what you suggests throws a ‘failed to call service’ error - this is in the logs:

2021-01-01 09:26:44 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140540092382560] 'timers'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1484, in _execute_service
await self._hass.async_add_executor_job(handler.job.target, service_call)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/octopusagile/__init__.py", line 81, in handle_update_timer
timers = config["octopusagile"]["timers"]
KeyError: 'timers'

My Configuration.yaml file looks like this:

octopusagile:
  region_code: "C"
  mpan: 'my mpan'
  serial: 'my serial'
  auth: 'my auth code'
  startdate: "2020-12-31"
 moneymakers:
  - switch.sonoff_1000cd9566: null
  timers:
  - day_from: today
    day_to: today
    entity_id: switch.sonoff_1000a27818
    numHrs: 1.5
    params: null
    time_from: '12:00:00'
    time_to: '16:00:00'
  run_devices:

Prior to this I have the errors, repeated every 30 mins:

2021-01-01 09:30:00 ERROR (SyncWorker_5) [custom_components.octopusagile] 'run_devices'
2021-01-01 09:30:00 ERROR (SyncWorker_1) [custom_components.octopusagile] 'timers'

Any suggestions ? Thanks in advance

I wondered if the example was trying to provide more than an example on how to define a timer that straddles two days (also modified the days and times incase the timer code would only work on values present in the octopusagile.rates entity) so I set the config as follows , but no more success - same error as before:

  timers:
  - day_from: today
    day_to: today
    entity_id: switch.sonoff_1000a27818
    numHrs: 1
    params: null
    requirements:
      - day_from: today
        day_to: today
        numHrs: 1
        time_from: '10:00:00'
        time_to: '16:00:00'
    time_from: '11:30:00'
    time_to: '20:30:00'
  run_devices:

@db1964 I’m just going through re-installing my whole HA and I’ve just completed this integration.

I’m no expert but I think you should compare the indentations in your config.yaml to the examples as you are aligned differently to mine, in particular your moneymakers: line needs another leading space.

Whether this will help I have no idea and I’m not about to break mine to find out!! :slight_smile:

It looks like it could be an indentation issue unless it got lost in formatting on here.
It should look more like this

octopusagile:
  region_code: "C"
  mpan: 'my mpan'
  serial: 'my serial'
  auth: 'my auth code'
  startdate: "2020-12-31"
  moneymakers:
  - switch.sonoff_1000cd9566: null
  timers:
  - day_from: today
    day_to: today
    entity_id: switch.sonoff_1000a27818
    numHrs: 1.5
    params: null
    time_from: '12:00:00'
    time_to: '16:00:00'
  run_devices:

You’re right, I was trying to show as much detail as possible, I’m always happy to take suggestions to improve documentation, I’m aware it’s not my strong point!

Well I’ve gone through the configuration.yaml looking for any trailing spaces , and made sure I used leading spaces for indentation , everything looks OK - see picture below:

I also changed the values to the ones I actually want rather than test values ( on the basis that if I do find a working slution I don’t want to then touch it all - if it is this sensitive ) . But things seem to have become worse - see error below:

2021-01-01 13:08:15 ERROR (MainThread) [homeassistant.setup] Error during setup of component octopusagile
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 213, in _async_setup_component
result = await task
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/octopusagile/__init__.py", line 72, in setup
for entity_id, vals in data["device_times"].items():
KeyError: 'device_times'
2021-01-01 13:08:15 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform octopusagile.sensor: Unable to set up component.

Oh and the ‘Configuration Check’ button show s config is OK

Perfect! Thanks for the reply. It seemed to work without the empty entries for timers or moneymakers.
Got it showing on the app and the dashboard on my home display, which was the whole point of doing this.

Follow-up question: is there a way to change the title on the custom rates card like with the grid card I’ve used below? I’m just trying to minimise ‘leaky abstractions’ in my dashboard, at least for headings, as my wife doesn’t really care for the underlying devices or tariffs, only that there are ‘good’ times and ‘bad’ times for using electricity. :smiley:

It looks like something went wrong with the data file that gets stored. If you delete /config/octopusagile.json and restart hopefully that will get you sorted.

Glad you got sorted! Just went back and checked - it’s hard coded near the top of agile-rates-card.js, which is stored in the www directory in your home assistant config directory. You can change it in there, it would be good to have it configurable so will add that in at some point too.

1 Like

Hi Markg , thanks for your patience on this . Your suggestion of deleting the octopusagile.json file means that the integration starts now . I also have octopusagile.rates populated , as well as a few other octopusagile entities but no timers. I tried calling octopusagile.update_timers as a service but it threw the following error:

2021-01-01 15:08:15 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140593900333136] min() arg is an empty sequence
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1484, in _execute_service
await self._hass.async_add_executor_job(handler.job.target, service_call)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/octopusagile/__init__.py", line 129, in handle_update_timers
min_rates = myrates.get_min_times(required_slots, date_rates, parsed_requirements)
File "/config/custom_components/octopusagile/OctopusAgile/Agile.py", line 115, in get_min_times
min_key = min(d, key=d.get)
ValueError: min() arg is an empty sequence

I also tried calling octopusagile.half_hour as a service and got the following:

2021-01-01 15:02:31 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140593900333136] 'NoneType' object is not iterable
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1484, in _execute_service
await self._hass.async_add_executor_job(handler.job.target, service_call)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/octopusagile/__init__.py", line 176, in handle_half_hour_timer
for device in devices:
TypeError: 'NoneType' object is not iterable

also, :slight_smile: , assuimg I get some timers out of this does the integration itself call the timer.start function in some way ? or is that someting for me to call in a seperate Automation ? if it is the latter is there a reccomended condition that should be true in order to trigger the Automation - I’m assuming running the automation is something you would do on a daily basis once the timers have been updated - is triggering the automation by time the best way or does octopusagile raise some event that I can hook into ?

No worries at all. Looking at your config above I believe the issue might have been that there were no rates available for your timers when you tried to allocate the times. If you try again now the rates for tomorrow are released I think you might have better luck. Usually it wouldn’t be an issue as the service will get run automatically once the rates are available (it tries from 7pm onwards).

What will happen is that the timers entity will get populated and then at each half hour the references entities will get turned on/off based in the timers, if that makes sense? Some people have wanted more control over their devices (once it’s controlled by the agile integration, if you turn it on outside of an allocated timer it’ll get turned off again at the next half hour) so use an input Boolean and then automate their device based on whether that is on/off.