Templates in command line sensor + Octopus Energy API

Hi Chris,

I’m getting electrical previous day consumption since two days now. My gas had always been “unknown” and no smart gas meter readings on the Octopus site… I reported that to them 3 months ago but still not fixed it.

I can’t promise any timelines, but I’ve just started playing with this API with the intention of writing a fully featured integration.

At the moment the API is returning no readings (I have had is setup for daily readings for the last 3 years), but as soon as I can get data out of it I will start on it.

1 Like

Does someone have access to the octopus energy forums? If so could you please invite [email protected]?

I’ve asked Octopus but they have told me they cannot invite me, that I need to find someone who already has access for an invite - which is strange given they own their own forum!

Hi Mark,

I looked on the Octopus forum but can not see any where to invite you. I guess that you are not an Octopus energy customer… Please check your IM as I sent you the e-mail address of Phil Steel who is the forum leader.

Hi Chris,

I am a customer. Thanks for sending Phil’s contract details I will reach out to him and see if he is able to invite!

Mark

Hi Mark,

Then for me it was a simle as going to my Octopus account page / developer and scroll to the bottom:

Octopus Forum

If you’re interested in using the API, or more generally about our smart tariffs, we have a forum where customers and staff discuss all things smart. You can check it out here.

EDIT: I seem to remember there was a statement to e-mail octopus to join…but I dont see that now. Just e-mail Phil and I’m sure he will let you in :slight_smile:

Yeah now it asks you to get an invite from another member. I did email octopus and they just recited the page to me and asked me if I knew anyone already on the forum that could invite me :smiley:

Cross fingers Phil will sort me out.

Ok but if not and he advises the same about needing an invitation, Please try to find out how I can invite you as its not very apparent on the forum.

If you want any help on this please give me a shout. I’ve got some python experience so can help where I can.

Nick

Thanks Nick - Python is may day job so should be ok on that front - most of it is just learning how the home assistant architecture works.

I am going try and submit some API feature requests so we can auto discover meters attached to your account, and what type of meters they are (smets1/2 etc) as at the moment the integration is going to need to you to manually enter all this info.

OK great sounds good! Well, if you want any help testing please let me know.

I’ve implemented a few more sensors in my config to:

  • Convert gas m3 to kWh
  • Convert both kWh values to an actual cost

Everything seems to match up to my Octopus account - however my values are slightly out on my IHD.

If anyone gets an invite to the forums please can you DM me and invite me too? :smiley:

Greetings. I am wondering if anyone has made any further progress in creating a custom component for retrieving the Octopus meter data please? I would like to get my historical gas consumption into HA and then graphing it in Lovelace. It’s just nice to have all energy data in one place.
For the time being, I am using this excellent tool: https://energy.guylipman.com/sm/admin?source=octopus to view my consumption. It’s a much better UX than Octopus own dashboard!

Thank you @chriscolden this works a treat, nice and simple!

Hey Everyone, I hope you are all well.
Kinda new to all of this API stuff but I have managed to get an overview of our last 24 hours of usage onto our HA dashboard (thanks to all of you lovely people)… Well I’m hoping it shows up when the transfer has completed from our previous supplier.

I wondered if there was a way to show a rough estimate of our next bill. We are on a fix Tariff but would like it to auto update so I don’t have to message with code in 12 months when I’ve forgot how I set it all up in the first place. Is that at all possible.

Thanks again for all of your help so far, you guys are amazing.

Jim

Are you able to share your extended sensors/code?

Would be interested to see what my costs in HA say vs the IHD (I’ve had a constant running battle with Octopus Support telling them my display doesn’t match their bills/data, at one point the website said I’d used more gas over 2x half hour periods in the middle of the night that would be physically impossible even in a year with all my gas usage on max… lol)

Does anyone else get some junk data round the 1am mark? The reading went from (full previous day) 1.36 to 0.3 at 1am and then unavailable until 3am when it went to 0.02 (and has stayed stable there since then)

I have a similar thing with the electricity when it went form 4.4 (full day) then at 1am 4.7 and then unavailable until 5am where it’s stayed at since (4.97)

1 Like

My IHD doesn’t match my bill either. I’ve practically given up on the IHD as it keeps disconnecting too.

This is probably not the best way of doing it but it works:

    sensors:
      electricity:
        unit_of_measurement: "kWh"
        value_template: >
          {% if states('sensor.electricity_2') == "47" %}
          {{ (state_attr("sensor.electricity_2", "results") | map(attribute="consumption") | sum ) | round(2) }}
          {% else %}
          {{ states('sensor.electricity_2') }}
          {% endif %}
      gas:
        unit_of_measurement: "m3"
        value_template: >
          {% if states('sensor.gas_2') == "47" %}
          {{ (state_attr("sensor.gas_2", "results") | map(attribute="consumption") | sum /11.36 ) | round(2) }}
          {% else %}
          {{ states('sensor.gas_2') }}
          {% endif %}
      electricity_cost:
        unit_of_measurement: "£"
        value_template: >
          {{ (states('sensor.electricity') | float * 0.1621 + 0.1994) | round(2)}}
      gas_kwh:
        unit_of_measurement: "kWh"
        value_template: >
          {{ (states('sensor.gas') | float * 1.02264 * 39.6 / 3.6) | round(2)}}
      gas_cost:
        unit_of_measurement: "£"
        value_template: >
          {{ (states('sensor.gas_kwh') | float * 0.027 + 0.1899) | round(2)}}

You would need to build a forecast that can handle seasonality. If it wasn’t for the seasonal change in usage you could just take the average monthly usage and forecast that way.

However changes in heating and electricity over winter would cause this to be inaccurate. I’m not sure if there are any built-in forecasting algorithms in HA?

It appears BST has affected the my data.
A few days ago it was reporting my gas, electricity, & export using the method above - but not worked since the hour change.