[SOLVED] RESTful Sensor.. How to get the right attribute from JSON result

Hi,
I’m sorry for the stupid question, but I am not able to decypher a rest API.
Basically I want to get the value of a stock price as a sensor.

For this I planned to use this REST API:
https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=IBM&apikey=demo

The output is the following:

{
    "Global Quote": {
        "01. symbol": "IBM",
        "02. open": "133.5200",
        "03. high": "133.6000",
        "04. low": "131.0200",
        "05. price": "131.8700",
        "06. volume": "5391520",
        "07. latest trading day": "2020-06-09",
        "08. previous close": "135.7500",
        "09. change": "-3.8800",
        "10. change percent": "-2.8582%"
    }
}

The REST Sensor I was trying to use and does not work… (I tried different variants):

  - platform: rest
    resource: https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=IBM&apikey=demo
    name: Stockprice
    json_attributes_path: "GLOBAL_QUOTE"
    json_attributes:
      - "05. price"
    scan_interval: 3600

also value_template: “{{ value_json.getString(“05. price”) }}” does not work…

Anyone has a clue how to get the price into the sensor attribute?

I use this regularly to help me.
Not sure if that’s your issue however.

JSON Path Finder

Thanks! this is nice, but I get this result as Path : x[“Global Quote”][“05. price”]

My issue is : How do I translate that into the right YAML in the sensor config to get this as sensor attribute value?

I finally got it, so want to close the loop for others if they run into the same issues. I was having difficulties as there were spaces and special characters in the structure and fields.

So final, working solution is this:

  - platform: rest
    resource: https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=IBM&apikey=demo.
    name: Stockprice
    value_template: '{{ value_json["Global Quote"]["05. price"] }}'
    scan_interval: 3600
3 Likes