Hello,
It does indeed work. I had to setup a rest.yaml page as I don’t use rest in that way anywhere else, but other than that, it was pretty easy to get going.
In my code, I changed the names so that the sensors are all grouped together within HA.
So this in a file called rest.yaml and an entry in the configuration.yaml of
rest: !include includes/rest.yaml
Full code:
- resource_template: >-
{% set regionid = 12 %}
https://api.carbonintensity.org.uk/regional/regionid/{{ regionid }}
scan_interval: 3600
sensor:
- name: "Generation Mix Biomass"
value_template: >-
{% set genlist = value_json.data[0].data[0].generationmix %}
{% for genitem in genlist %}
{% if genitem['fuel'] == 'biomass' %}
{{ genitem['perc'] }}
{% endif %}
{% endfor %}
unit_of_measurement: '%'
- name: "Generation Mix Coal"
value_template: >-
{% set genlist = value_json.data[0].data[0].generationmix %}
{% for genitem in genlist %}
{% if genitem['fuel'] == 'coal' %}
{{ genitem['perc'] }}
{% endif %}
{% endfor %}
unit_of_measurement: '%'
- name: "Generation Mix Imports"
value_template: >-
{% set genlist = value_json.data[0].data[0].generationmix %}
{% for genitem in genlist %}
{% if genitem['fuel'] == 'imports' %}
{{ genitem['perc'] }}
{% endif %}
{% endfor %}
unit_of_measurement: '%'
- name: "Generation Mix Gas"
value_template: >-
{% set genlist = value_json.data[0].data[0].generationmix %}
{% for genitem in genlist %}
{% if genitem['fuel'] == 'gas' %}
{{ genitem['perc'] }}
{% endif %}
{% endfor %}
unit_of_measurement: '%'
- name: "Generation Mix Nuclear"
value_template: >-
{% set genlist = value_json.data[0].data[0].generationmix %}
{% for genitem in genlist %}
{% if genitem['fuel'] == 'nuclear' %}
{{ genitem['perc'] }}
{% endif %}
{% endfor %}
unit_of_measurement: '%'
- name: "Generation Mix Other"
value_template: >-
{% set genlist = value_json.data[0].data[0].generationmix %}
{% for genitem in genlist %}
{% if genitem['fuel'] == 'other' %}
{{ genitem['perc'] }}
{% endif %}
{% endfor %}
unit_of_measurement: '%'
- name: "Generation Mix Hydro"
value_template: >-
{% set genlist = value_json.data[0].data[0].generationmix %}
{% for genitem in genlist %}
{% if genitem['fuel'] == 'hydro' %}
{{ genitem['perc'] }}
{% endif %}
{% endfor %}
unit_of_measurement: '%'
- name: "Generation Mix Solar"
value_template: >-
{% set genlist = value_json.data[0].data[0].generationmix %}
{% for genitem in genlist %}
{% if genitem['fuel'] == 'solar' %}
{{ genitem['perc'] }}
{% endif %}
{% endfor %}
unit_of_measurement: '%'
- name: "Generation Mix Wind"
value_template: >-
{% set genlist = value_json.data[0].data[0].generationmix %}
{% for genitem in genlist %}
{% if genitem['fuel'] == 'wind' %}
{{ genitem['perc'] }}
{% endif %}
{% endfor %}
unit_of_measurement: '%'