rr19-hub
(Rr19 Hub)
April 27, 2022, 5:46am
1
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!
nickrout
(Nick Rout)
April 27, 2022, 5:50am
2
What are you trying to extract? I find this site helpful https://jsonpathfinder.com/
1 Like
nickrout
(Nick Rout)
April 27, 2022, 6:33am
3
Also, can’t you use the integration? Coinbase - Home Assistant
rr19-hub
(Rr19 Hub)
April 27, 2022, 10:27am
4
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) }}"
nickrout
(Nick Rout)
April 27, 2022, 10:29am
5
Then you should post an issue to github to get it fixed.
rr19-hub
(Rr19 Hub)
April 27, 2022, 10:34am
6
I’ll do. How to give this rest-value a unique_id (to manage the icon)? I’m new to rest & hass.io , sorry…
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).
nickrout
(Nick Rout)
April 27, 2022, 10:42am
7
Changing the device_class will change the icon.
rr19-hub
(Rr19 Hub)
April 27, 2022, 10:50am
8
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.
petro
(Petro)
April 27, 2022, 10:56am
9
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.
rr19-hub
(Rr19 Hub)
April 28, 2022, 6:08am
10
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:
type: history-graph
entities:
- entity: sensor.btc
title: Verlauf BTC
The battery graph is correctly displayed as a curve with the same setting:
type: history-graph
entities:
- entity: sensor.galaxy_s10_battery_level
title: Batteriestand S10
nickrout
(Nick Rout)
April 28, 2022, 6:46am
11
You need to give unit_of_measurement to produce graphs.