API value from JSON

Hello, I’m trying to read a value from JSON, but so far without success. At https://api.coinbase.com/v2/prices/spot?currency=EUR I get the data:

{"data":{"base":"BTC","currency":"EUR","amount":"36142.35"}}

With value_template: this should be easy, right? Perhaps the value can also be formatted in a more meaningful way? For example 25.123 instead of 25123.63?
Thanks for any help!

What are you trying to extract? I find this site helpful https://jsonpathfinder.com/

1 Like

Also, can’t you use the integration? Coinbase - Home Assistant

Thanks for the help, the integration gives me a 404 error. But it works like this now:

- platform: rest
  scan_interval: 300
  resource: 'https://api.coinbase.com/v2/prices/spot?currency=EUR'
  method: GET
  name: BTC
  authentication: basic
  verify_ssl: false
  unit_of_measurement: "EUR/BTC" 
  value_template: "{{ value_json.data.amount | round(0) }}"

Then you should post an issue to github to get it fixed.

I’ll do. How to give this rest-value a unique_id (to manage the icon)? I’m new to rest & hass.io, sorry… :man_shrugging:

edit: I found something in Setting a friendly_name or unique_id on a Rest sensor? - #14 by phileep. I’ll have a look, actually I’m only interested in the icon (currently an eye, that doesn’t make sense).

Changing the device_class will change the icon.

Thank You, it works. I had to add a entity to dashboard, not just a element. But I’ll have al look for the device_class later.

404 means it can’t reach the host. That’s most likely a user error in the configuration with the wrong information or a networking issue.

Something else: the values are retrieved correctly and also rounded.
But in the graph they are not treated as values of a scale, but separately:
grafik

type: history-graph
entities:
  - entity: sensor.btc
title: Verlauf BTC

The battery graph is correctly displayed as a curve with the same setting:
grafik

type: history-graph
entities:
  - entity: sensor.galaxy_s10_battery_level
title: Batteriestand S10

You need to give unit_of_measurement to produce graphs.

Thats it, thank You!