Octopus Energy - Gas Tracker Tariff Dynamic Pricing sensors - SOLVED

Hi,

I hate to resurrect and old thread but I have been trying to get this working for my own HA instance with my Octopus Tracker.

I have the below code which works fine and pulls tomorrows Electric and Gas prices from the Octopus API. I have disabled the scan_interval and run homeassistant.update_entity in an automation.

sensor:
  - platform: rest
    unique_id: electric_tomorrow
    resource_template: https://api.octopus.energy/v1/products/SILVER-FLEX-22-11-25/electricity-tariffs/E-1R-SILVER-FLEX-22-11-25-F/standard-unit-rates/?period_from={{(now().timestamp()+ (86400)) | timestamp_custom('%Y-%m-%d')}}
    method: GET
    name: Octopus Electricity Tomorrow
    value_template: "{{(value_json.results[0].value_inc_vat) | round (4) }}"
    unit_of_measurement: 'p/KWh'
    #scan_interval: 2628002
    force_update: true
    icon: mdi:lightning-bolt-circle

  - platform: rest
    unique_id: gas_tomorrow
    resource_template: https://api.octopus.energy/v1/products/SILVER-FLEX-22-11-25/gas-tariffs/G-1R-SILVER-FLEX-22-11-25-F/standard-unit-rates/?period_from={{(now().timestamp()+ (86400)) | timestamp_custom('%Y-%m-%d')}}
    method: GET
    name: Octopus Gas Tomorrow
    value_template: "{{(value_json.results[0].value_inc_vat) | round (4) }}"
    unit_of_measurement: 'p/KWh'
    #scan_interval: 2628002
    force_update: true
    icon: mdi:fire-circle

My biggest issue Is I’m seeing a ton of errors in my logs related to the above. Any idea how to resolve the below errors?

2023-08-03 09:04:37.810 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 0 when rendering '{{(value_json.results[0].value_inc_vat) | round (4) }}'
2023-08-03 09:04:37.816 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 0 when rendering '{{(value_json.results[0].value_inc_vat) | round (4) }}'
2023-08-03 09:05:07.482 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 0 when rendering '{{(value_json.results[0].value_inc_vat) | round (4) }}'
2023-08-03 09:05:07.486 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 0 when rendering '{{(value_json.results[0].value_inc_vat) | round (4) }}'
2023-08-03 09:05:37.420 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 0 when rendering '{{(value_json.results[0].value_inc_vat) | round (4) }}'
2023-08-03 09:05:37.424 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 0 when rendering '{{(value_json.results[0].value_inc_vat) | round (4) }}'
2023-08-03 09:06:07.425 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 0 when rendering '{{(value_json.results[0].value_inc_vat) | round (4) }}'
2023-08-03 09:06:07.429 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 0 when rendering '{{(value_json.results[0].value_inc_vat) | round (4) }}'
2023-08-03 09:06:37.407 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 0 when rendering '{{(value_json.results[0].value_inc_vat) | round (4) }}'
2023-08-03 09:06:37.410 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 0 when rendering '{{(value_json.results[0].value_inc_vat) | round (4) }}'

1 Like

Did you manage to resolve this? I’m also looking to pull the next day rate

This seems to work for me. I needed to specify the start and end date for only 1 day. Not sure it’s correct, but seems ok?

  - platform: rest
    unique_id: octopus_electric_today
    resource_template: https://api.octopus.energy/v1/products/SILVER-FLEX-22-11-25/electricity-tariffs/E-1R-SILVER-FLEX-22-11-25-L/standard-unit-rates/?period_from={{(now().timestamp()- (86400)) | timestamp_custom('%Y-%m-%d')}}&period_to={{(now().timestamp()- (0)) | timestamp_custom('%Y-%m-%d')}}
    method: GET
    name: Octopus Electricity Today
    value_template: "{{(value_json.results[0].value_inc_vat) | round (4) }}"
    unit_of_measurement: 'p/KWh'
    scan_interval: 00:00:10
    #scan_interval: 2628002
    force_update: true
    icon: mdi:lightning-bolt-circle

  - platform: rest
    unique_id: octopus_electric_tomorrow
    resource_template: https://api.octopus.energy/v1/products/SILVER-FLEX-22-11-25/electricity-tariffs/E-1R-SILVER-FLEX-22-11-25-L/standard-unit-rates/?period_from={{(now().timestamp()+ (86400)) | timestamp_custom('%Y-%m-%d')}}&period_to={{(now().timestamp()+ (2*86400)) | timestamp_custom('%Y-%m-%d')}}
    method: GET
    name: Octopus Electricity Tomorrow
    value_template: "{{(value_json.results[0].value_inc_vat) | round (4) }}"
    unit_of_measurement: 'p/KWh'
    scan_interval: 00:00:10
    force_update: true
    icon: mdi:lightning-bolt-circle



  - platform: rest
    unique_id: octopus_gas_today
    resource_template: https://api.octopus.energy/v1/products/SILVER-FLEX-22-11-25/gas-tariffs/G-1R-SILVER-FLEX-22-11-25-L/standard-unit-rates/?period_from={{(now().timestamp()- (86400)) | timestamp_custom('%Y-%m-%d')}}&period_to={{(now().timestamp()- (0)) | timestamp_custom('%Y-%m-%d')}}
    method: GET
    name: Octopus Gas Today
    value_template: "{{(value_json.results[0].value_inc_vat) | round (4) }}"
    unit_of_measurement: 'p/KWh'
    scan_interval: 00:00:10
    force_update: true
    icon: mdi:fire-circle

  - platform: rest
    unique_id: octopus_gas_tomorrow
    resource_template: https://api.octopus.energy/v1/products/SILVER-FLEX-22-11-25/gas-tariffs/G-1R-SILVER-FLEX-22-11-25-L/standard-unit-rates/?period_from={{(now().timestamp()+ (86400)) | timestamp_custom('%Y-%m-%d')}}&period_to={{(now().timestamp()+ (2*86400)) | timestamp_custom('%Y-%m-%d')}}
    method: GET
    name: Octopus Gas Tomorrow
    value_template: "{{(value_json.results[0].value_inc_vat) | round (4) }}"
    unit_of_measurement: 'p/KWh'
    scan_interval: 00:00:10
    force_update: true
    icon: mdi:fire-circle

image

Next day rate is now available through BottlecapDaves Octopus add on or you can use you’re own rest sensor like above.

Is the api not working for anyone else today?

API stopped working for me on the 1st - Is everyone in the same boat?

@j1234 I really think you should look at your rest sensors again and change the scan_interval to something MUCH less aggressive. Do you really need all 4 sensors to be checking every 10 seconds? That frequent an update might get you rate limited/banned. Once an hour should be sufficient being as prices are static for the day

@Alister yes, same for me from the integration. No update since 1st October.

Of course every 10 secs is incorrect. Just for testing.

1 Like

Mine stopped working too!
Was using this : https://octopus.energy/api/v1/tracker/G-1R-SILVER-22-07-22-B/daily/current/0/0

Yes, me too. Was using https://octopus.energy/api/v1/tracker/G-1R-SILVER-FLEX-22-11-25-B/daily/current/0/0/.

Get the following error

{
  "error": "We're currently unable to retrieve tracker data"
}

I can pull the price from https://api.octopus.energy/v1/products/SILVER-VAR-22-10-21/gas-tariffs/G-1R-SILVER-VAR-22-10-21-B/standard-unit-rates/ but the response format is different. Anyone good at extracting today’s value from the json?

{
  "count": 356,
  "next": "https://api.octopus.energy/v1/products/SILVER-VAR-22-10-21/gas-tariffs/G-1R-SILVER-VAR-22-10-21-B/standard-unit-rates/?page=2",
  "previous": null,
  "results": [
    {
      "value_exc_vat": 4.53,
      "value_inc_vat": 4.7565,
      "valid_from": "2023-10-01T23:00:00Z",
      "valid_to": "2023-10-02T23:00:00Z",
      "payment_method": null
    },
    {
      "value_exc_vat": 4.51,
      "value_inc_vat": 4.7355,
      "valid_from": "2023-09-30T23:00:00Z",
      "valid_to": "2023-10-01T23:00:00Z",
      "payment_method": null
    },
    {
      "value_exc_vat": 4.51,
      "value_inc_vat": 4.7355,
      "valid_from": "2023-09-29T23:00:00Z",
      "valid_to": "2023-09-30T23:00:00Z",
      "payment_method": null
1 Like

Mine is working again.

Me too :+1:

Interestingly mine is working, but the rate updates at 1pm in the afternoon instead of just after midnight as it did up until 1st October. Do other people get the same?

There is an alternative address to get the costings, but it doesn’t show the standing charge.
https://api.octopus.energy/v1/products/SILVER-FLEX-22-11-25/gas-tariffs/G-1R-SILVER-FLEX-22-11-25-B/standard-unit-rates/

(remember to change to B to your locality)

Hi jaketame, your card looks nice. Could you share which card you use to create it? Thanks!

For someone or those who want to Automate specific price i have a simple code you can add to this developed code to archive this - you just add as a condition in HA