Hi community, please help I’m too new with these things sorry if this may be a duplicate post.
Here’s my JSON:
"status": "success",
"timestamp": "2024-07-03T17:17:00.736Z",
"currency": "MYR",
"unit": "toz",
"metal": "gold",
"rate": {
"price": 11117.613,
"ask": 11118.2734,
"bid": 11116.9525,
"high": 11156.3182,
"low": 10976.543,
"change": 128.805,
"change_percent": 1.17
}
}
I’m trying to get a sensor from API request but my json data has different attributes path. I would like to get my sensor to show in the form of (last image):
State/Attributes - Timestamp
Attributes - price
Attributes - ask
Attributes - bid
Attributes - high
Attributes - low
Attributes - change
Attributes - change_percent
Currently my DIY sensors are in the sensor.yaml file.
If I were to give it an attribute path I can only get to the attributes of “rates” but no timestamp attributes (below is my current configuration in sensor.yaml).
# Spot Gold (in Troy Oz)
- platform: rest
resource: https://api.metals.dev/v1/metal/spot?api_key=[MY_API_KEY]&metal=gold¤cy=MYR
name: "Spot Gold"
scan_interval: 28800
headers:
content-type: "application/json"
value_template: "{{ value_json.value }}"
json_attributes_path: "$['rate']"
json_attributes:
- timestamp
- price
- ask
- bid
- high
- low
- change
- change_percent
My question would be how can I make a sensor with the timestamp (in state), price (in attributes), change_percent (in attributes) with just one API request.
Alternatively everything (timestamp,price,change_percent) in attributes?