Been reading all this with interest. I’ve been using HA for a couple of years to monitor my boiler and central heating. I’ve recently been moved to Octopus Energy and have a SMETS2 smart meter, so would like to get that data into HA. I’ve enabled half-hourly data on my Octopus account and can download .CSVs so just need to stitch it all in HA.
I guess I’m interested in half-hourly consumption which I can then aggregate somehow by day, week, month. I don’t need realtime (yet) so the Octopus API sounds the route to go. I’m on the price-cap tariff, so not expecting frequent price changes, but it would be good if that’s retrievable through the API so the rates are up to date.
Is there a wiki or other doc summarising how to set things up? Thanks.
Hi, been quietly following this thread, many thanks for all the efforts, very useful.
I notice that the number of entries check doesn’t cater for daylight savings …
Note: I have only just implemented the entire code by [oneofthemany], and have just tested with the data from the 31st October, as my earlier version failed due to the 48 only check … it all seems to work great.
e.g. Gas cost
{% if usage is defined and (usage|count in [48,46,50]) %}
and Electricity cost
{% if usage is defined and (usage|count in [48,46,50]) %}
{% set ns = namespace(total=0) %}
{% for p in range(0, usage|count) %}
and for Electricity cost off peak
{% if usage is defined and (usage|count in [8,6,10]) %}
{% set ns = namespace(total=0) %}
{% for p in range(0, usage|count) %}
Mention of CSV was a red herring. I’m keen to go the API route (rather than realtime with Hildebrand etc.). I can live with data 24 hours out of date - the IHD does the realtime bit for me. It’s more being able to look back at the half-hourly data.
So… just curious whether there’s a step-by-step guide to getting data via the API into HA and into the Energy view (or whatever else is appropriate). Seen lots of good stuff in this thread - it’s just piecing it all together! Would also be good if Phil at Octopus was able to drive some HA stuff from their end. We’ll see.
I’m on the tariff for Avro Energy orphans, called “Flexible Avro”. Do I need to changed anything to reflect that or does the API key, MPAN/MPRN and meter serial numbers automatically sort it all out? Thanks.
I have no idea when and if your tariff will be exposed by Octopus or even what that looks like as octopus only took on Avro at the back end of September.
But the best piece of advice would be getting confirmation with Octopus of what’s exposed, if anything at all prior to moving forward, as this will impact what’s required for your overall config.
Thanks. I’m trying to start small and build up. So, just trying to get gas consumption at this point.
With this code in configuration.yaml…
- platform: rest
name: Gas consumption
resource_template: >-
{% set mprn = 'MY MPRN' %}
{% set serial = 'MY SERIAL NO' %}
{% set date = as_timestamp(now() - timedelta(days = 1))|timestamp_custom('%Y-%m-%d') %}
https://api.octopus.energy/v1/gas-meter-points/{{ mprn }}/meters/{{ serial }}/consumption/?period_from={{ date + 'T00:00:00' }}&period_to={{ date + 'T23:59:59' }}
headers:
Authorization: !secret octopus_auth
value_template: "{{ value_json.results|sum(attribute='consumption')|round(3) }}"
unit_of_measurement: 'kWh'
device_class: energy
json_attributes:
- "results"
I’m getting errors of the form…
2021-11-06 14:30:41 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'results' when rendering '{{ value_json.results|sum(attribute='consumption')|round(3) }}'
The first section correctly renders into a URL to get my gas consumption. When I paste it into a browser and supply my API key as the username, 48 half-hourly readings come back in JSON. So the issue appears to be the value_template section. Am I doing something really silly for this not to work? Probably…
This is exactly the question I’ve been trying to work out the answer to… it seems to me like the entire energy dashboard as been built on the assmption metering data will arrive in real time and be stored by HA as it arrives, hence the single reading with of “consumption” being read into the graphs at the point yesterday’s data arrives (so for me at 6am today I had a single massive consumption recorded which should actually be in yesterday’s graphs.
I find the documentation for HA really confusing at the best of times, but I would love to work out how to apply the reading from @oneofthemany’s hard work to be recorded on the right day, if we can work that out, then having it record each 30 min segment through the day retrospectively may be possible.
Any pointers or thoughts from anyone would be great; I am happy to test or try any ideas people have.
I can understand the quest for half hourly data, but ultimately it comes down to the end user and their specific needs, but and there is a but, I personally don’t need it to be that granular and the 4 hour slots I have set up make it very easy to understand my usage and where I can perhaps be better with my consumption.
The easiest way is to get kWh usage in half hour slots, would be through smart sockets, but you are left with very little in the marketplace in terms of sockets that actually function and deliver telemetry - I have gone all out and used a £100 socket only to find that when I used it for charging my PHEV it crashed my whole zigbee network - luckily I had it all in containers and it was easy to recover the state from last backup
I can imagine moving forward the Energy tab will be better and offer far more, and I am looking forward to that, but at the moment I am more than happy with what I have until things get better.
Your assumption is correct. I was on a meetup in the summer where Paulus was a guest speaker and he confirmed at the moment Home Assistant only allows real time data and there is no feature to backdate readings yet.
Thanks oneofthemany this has all been really useful and I have finally found time to start setting up my config.
I have one small issue/question.
I don’t seem to be able to get 48 readings for electricity until two days later. Can you think of a reason for this? I’m suspecting it must be some quirk it the data collection for my meter because this:
So apparently there is no reading for that last half an hour (unless I wait another 24 hours).
Thanks for any insight…
And as an aside, I am far from an expert when it comes to date time formats and as you omitted them I’m probably wrong but I just thought I’d check; shouldn’t the datetimes have a ‘Z’ at the end to cater for BST? (i.e. 2021-11-14T09:00:00Z) - it’s six months until I can check for myself!!