With the help of the people that reacted here, I was able to get the GoldAPI.io REST-interface to work. It’s in my sensors.yaml, then inplemented on both the rest AND the template platform. Big advantage of this solution is that the API only updates when explicitly called to do so, not when attributes must be retrieved; there’s a limit of 500 free updates/month.
Here’s the code:
# Gold Market Data Sensor
- platform: rest
resource: https://www.goldapi.io/api/XAU/EUR
name: "Gold API"
json_attributes:
- price
- low_price
- high_price
- bid
- ask
- error
method: GET
value_template: >
{% if value_json.price is defined %}
{{ (value_json.price * 32.1507)|round(0)|string}}
{% else %}
{{ 'no data' }}
{% endif %}
scan_interval: 31536000
headers:
x-access-token: !secret gold_api_key
Content-Type: "application/json"
- platform: template
sensors:
gold_price:
value_template: "{{ (state_attr('sensor.gold_api', 'price')|float * 32.1507)|round(0)}}"
gold_low:
value_template: "{{ (state_attr('sensor.gold_api', 'low_price')|float * 32.1507)|round(0) }}"
gold_high:
value_template: "{{ (state_attr('sensor.gold_api', 'high_price')|float * 32.1507)|round(0) }}"
gold_bid:
value_template: "{{ (state_attr('sensor.gold_api', 'bid')|float * 32.1507)|round(0) }}"
gold_ask:
value_template: "{{ (state_attr('sensor.gold_api', 'ask')|float * 32.1507)|round(0) }}"
So when sensor.gold_api is called, the API updates from the server; if one of the attributes (i.e. sensor.gold_bid) is called, it is retrieved from the previously updated (object) JSON