You may have noticed I changed one other thing in the template. I added parentheses ( ) to group several terms performing the calculation. It ensures round(3) acts on the result of the entire calculation and not just on 11.36.
To see what I mean, put this into the Template Editor:
{% set x = 100.123 %}
{{ x / 3 }}
{{ x / 3 | round(1) }}
{{ (x / 3) | round(1) }}
Sorry for not getting back to you with my results. I’ve just added these items into my config and whilst the config shows as valid, I’m getting results back that look odd.
From my energy tracking HS110’s I can see I used 9.29kWh of electricity yesterday:
The sensor you have very kindly provided shows the following instead:
Using the curl commands on the octopus developer website I can see the usage reflected properly there.
If you have any suggestions I’d be very grateful for your help.
Edit: my sensors to fetch the data only contain two values so I believe the fault lies with the way the data is being obtained:
A few updates which will hopefully answer a few of your questions.
The graph above is simply the values of the sensor plugged into the standard history-graph lovelace card. However, I’ve made some changes recently which make this whole thing work much better.
The API has appeared to have only just started working properly again after being down since 06/04/2019 - even with the correct CURL requests and 200 OK responses, the latest data it was reporting was from this date. As of this afternoon service appears to be working as normal. This is almost definitely why your usage hasn’t been as expected, @anon12983141!
I have found a much better way of creating a graph to chart usage. As it stands, the first sensor pulls all the consumption data from the previous 24 hours, then the second one calculates the total usage. However, the API doesn’t update with the previous day’s usage until around 6-8am (usually) which causes a 6 hour gap in the data.
The way around this that I think works the best is as follows:
First, create an input_number which will be your new consumption ‘sensor’:
Basically, this will only update the input_number with the new consumption data once it becomes available (when sensor.electricity goes from ‘0’ to ‘48’ after the API has pushed the previous day’s half-hourly consumption figures). Makes sense?
This then allows you to use @kalkih’s excellent mini-graph-card to make nice pretty energy usage charts like this:
Some tweaks are needed to counteract daylight savings time - otherwise during the summer months the sensor will record 25 hours worth (50 records) of consumption data due to the way the API behaves. So your electricity and gas sensor commands should be updated to include both period_from AND period_to, as per the following:
@ajoyce Thanks for great examples / templates above.
Never having dabbled in REST before its taken me all night to get working sensors and Lovelace Cards displayed but I’ve gotten there! However I’d like to know if you think the following is possible…
Currently we have a little energy monitor on our old gas and electric meters ( Loop Device) which notifies us when we have hit 50%, 75%, 90% etc of our weekly budget. When we have our new Smart Meters installed next month I’d like to try and replicate this with HA. ( The notification side I’m happy with, its the Octopus API calls I don’t have a clue…)
I know the querying “https://api.octopus.energy/v1/products/FIX-12M-19-04-01/” lists the available tariffs; and if I can pull the applicable daily usage, multiply by the rate and add the daily charge then I should be able to work out current spend ( albeit delayed by update delay). I just don’t know how to specifically pull those bits of relevant information and store them as a useable variable in HA.
I’m certainly not asking for you to do this for me; just a few helpful points if you could? Or infact if its not possible…
Hi there! I think in most cases you may end up complicating things by using the API to access tariffs, depending on what kind of tariff you have. If you’re on a fixed rate tariff, it’s simple; you just append the calculations for the price to the automation. Using my fixed rate tariff for electricity, which is 3.52p/kWh and 16p/day standing charge, this would be:
You can get your rate and standing charges from your last statement in your online account. I’ll have to give variable rate tariffs some thought, but is this the sort of thing you’re after?
On the 28th of last month, my electricity usage stopped updating. On the 3rd of this month, my gas stopped updating. No changes have been made to my sensor.yaml entries.
The curl commands on the octopus energy developers site return valid, accurate data still (up to the dates mentioned).
I’m having the same issue too. The curl requests work for me, but only for fetching data older than the dates you’ve specified above. Looks like the problem isn’t with this coding but instead with Octopus’s backend - they haven’t updated their database with the latest meter readings. I recall this has happened a few times in the past and normally takes a week or two for them to realise the issue and fix it.
When it is fixed, one other change you might want to make to your code is changing the end time to 23:59:59 like this:
This is because at times the 0000h - 0000h time interval can return 48 OR 49 results, which breaks updates using the automation. Using the above code should guarantee 48 results every time.
Here’s hoping they fix their data upload problems soon!
Always a pleasure! Have also tweaked this integration so it’s in a bash script to keep the main config.yaml tidy - can share this if needed.
Anyway - I see yesterday my gas and electricity sensors kicked back into gear again, looks like they’ve fixed things on the backend - are you seeing success with yours?
Replace x’s, y’s and z’s as required and link to wherever you’ve put your scripts - I’ve put mine in a folder called bash_scripts in my config folder (correct file path to config folder can be found in “Developer Tools -> Info -> Path to configuration.yaml”
Yesterday I just added the sensor without the automation and got the Blue bar with 50 (as per image below. When I added the automation this morning and restarted I got the Orange bar with 2.
I manually triggered the automation and got a consumption of 0.287kWh which I guess is the sum of the two entries from yesterday?
Am I missing parts of the configuration out?
If i try curl -H "Authorization: Basic xxxxxxxxxxxxxxxx"
The sensor returns no values.
Are you bale to share your complete configuration?