Hi,
I’m very new to Home Assistant, I’m trying to use the JSON file returned from an Octopus energy rest pull for both pricing and consumption and exports.
I know I can only normally get these a day after I’ve used them but I’d like to create a dashboard that can show electricity costs for the day/week/month and then roll up to the year.
I know that in PowerShell I could just use a foreach loop to cycle through the elements in the Results section but I’m not sure how I’d do the following in HA:
loop through the json elements and select the “valid_from” and “value_inc_vat” elements from each.
as above but loop through the elements of the usage JSON file and then for out the 1/2 hourly price
Do the same but for exports.
store these variables long term.
create a dynamic tile on a dash board
Once I get a grip on the coding language I’m normally alright with things but any help, etc, would be greatly received.
The structure of the JSON is:
Sorry, I didn’t want to post the json file in case it broke any rules, etc.
I’ve read through the Restful sensor page and, correct me if I’m wrong, I’d use the josn_attributes line to pull out the 2 lines I want for the “valid_from” and “value_inc_vat”
I get that part, the part I don’t understand, am it’s probably me over thinking it, how would I cycle through all the results in the JSON?
I’m not sure what you are trying to do so I can’t help because of that.
But looking at the template tools there is an example how to loop a jsonstructure.
For loop example getting entity values in the weather domain:
{% for state in states.weather -%}
{%- if loop.first %}The {% elif loop.last %} and the {% else %}, the {% endif -%}
{{ state.name | lower }} is {{state.state_with_unit}}
{%- endfor %}.
So what you need to do is to change the entities
value_template: >-
{% for index in value_json["results"] -%}
{{ index.value_exe_vat }}
{%- endfor %}.
That’s about what I understand that you want to do.