There are already a few different ways to get crytpo currency values into HA. Some are now broken, some are not free, so I had a look for another way.
I found https://nomics.com/ which have a free API at Free Cryptocurrency & Market Data API (Historical & Real-Time Price, Exchange & Trade Data) which only has a limit of 1 call per second.
After signing up for the API, the resource to call for a restful sensor is made up like so
https://api.nomics.com/v1/currencies/ticker?key=<APIKEY>&ids=<COINS>&interval=1h,1d,7d,30d&per-page=100&page=1&sort=first_priced_at
COINS is comma seperated list of coins to track, so in my usecase was
BTC,ETH,DOGE,BCH,BNB,XRP,BCH,LTC,XLM,TRX
This will return current data for coin values, market caps, record highs etc but with the interval paramaters I also get the change over 1 hour, 1 day etc.
My full rest sensor is as follows
- resource: !secret nomics_crypto_api
scan_interval: 10
sensor:
### BTC
- name: "Crypto - BTC"
json_attributes_path: "$.[0]"
value_template: '{{ value_json[0].price | round(4) }}'
unit_of_measurement: "USD"
json_attributes:
- name
- symbol
- price
- logo_url
- rank
- high
- high_timestamp
- market_cap
- first_trade
- name: "Crypto - BTC - 1 Hr"
json_attributes_path: "$.[0].1h"
unit_of_measurement: "USD"
value_template: '{{ value_json[0]["1h"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - BTC - 1 D"
json_attributes_path: "$.[0].1d"
unit_of_measurement: "USD"
value_template: '{{ value_json[0]["1d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - BTC - 7 D"
json_attributes_path: "$.[0].7d"
unit_of_measurement: "USD"
value_template: '{{ value_json[0]["7d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - BTC - 30 D"
json_attributes_path: "$.[0].30d"
unit_of_measurement: "USD"
value_template: '{{ value_json[0]["30d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
### ETH
- name: "Crypto - ETH"
json_attributes_path: "$.[1]"
value_template: '{{ value_json[1].price | round(4) }}'
unit_of_measurement: "USD"
json_attributes:
- name
- symbol
- price
- logo_url
- rank
- high
- high_timestamp
- market_cap
- first_trade
- name: "Crypto - ETH - 1 Hr"
json_attributes_path: "$.[1].1h"
unit_of_measurement: "USD"
value_template: '{{ value_json[1]["1h"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - ETH - 1 D"
json_attributes_path: "$.[1].1d"
unit_of_measurement: "USD"
value_template: '{{ value_json[1]["1d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - ETH - 7 D"
json_attributes_path: "$.[1].7d"
unit_of_measurement: "USD"
value_template: '{{ value_json[1]["7d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - ETH - 30 D"
json_attributes_path: "$.[1].30d"
unit_of_measurement: "USD"
value_template: '{{ value_json[1]["30d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
### BNB
- name: "Crypto - BNB"
json_attributes_path: "$.[2]"
value_template: '{{ value_json[2].price | round(4) }}'
unit_of_measurement: "USD"
json_attributes:
- name
- symbol
- price
- logo_url
- rank
- high
- high_timestamp
- market_cap
- first_trade
- name: "Crypto - BNB - 1 Hr"
json_attributes_path: "$.[2].1h"
unit_of_measurement: "USD"
value_template: '{{ value_json[2]["1h"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - BNB - 1 D"
json_attributes_path: "$.[2].1d"
unit_of_measurement: "USD"
value_template: '{{ value_json[2]["1d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - BNB - 7 D"
json_attributes_path: "$.[2].7d"
unit_of_measurement: "USD"
value_template: '{{ value_json[2]["7d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - BNB - 30 D"
json_attributes_path: "$.[2].30d"
unit_of_measurement: "USD"
value_template: '{{ value_json[2]["30d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
### DOGE
- name: "Crypto - DOGE"
json_attributes_path: "$.[3]"
value_template: '{{ value_json[3].price | round(4) }}'
unit_of_measurement: "USD"
json_attributes:
- name
- symbol
- price
- logo_url
- rank
- high
- high_timestamp
- market_cap
- first_trade
- name: "Crypto - DOGE - 1 Hr"
json_attributes_path: "$.[3].1h"
unit_of_measurement: "USD"
value_template: '{{ value_json[3]["1h"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - DOGE - 1 D"
json_attributes_path: "$.[3].1d"
unit_of_measurement: "USD"
value_template: '{{ value_json[3]["1d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - DOGE - 7 D"
json_attributes_path: "$.[3].7d"
unit_of_measurement: "USD"
value_template: '{{ value_json[3]["7d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - DOGE - 30 D"
json_attributes_path: "$.[3].30d"
unit_of_measurement: "USD"
value_template: '{{ value_json[3]["30d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
### XRP
- name: "Crypto - XRP"
json_attributes_path: "$.[4]"
value_template: '{{ value_json[4].price | round(4) }}'
unit_of_measurement: "USD"
json_attributes:
- name
- symbol
- price
- logo_url
- rank
- high
- high_timestamp
- market_cap
- first_trade
- name: "Crypto - XRP - 1 Hr"
json_attributes_path: "$.[4].1h"
unit_of_measurement: "USD"
value_template: '{{ value_json[4]["1h"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - XRP - 1 D"
json_attributes_path: "$.[4].1d"
unit_of_measurement: "USD"
value_template: '{{ value_json[4]["1d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - XRP - 7 D"
json_attributes_path: "$.[4].7d"
unit_of_measurement: "USD"
value_template: '{{ value_json[4]["7d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - XRP - 30 D"
json_attributes_path: "$.[4].30d"
unit_of_measurement: "USD"
value_template: '{{ value_json[4]["30d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
### BCH
- name: "Crypto - BCH"
json_attributes_path: "$.[5]"
value_template: '{{ value_json[5].price | round(4) }}'
unit_of_measurement: "USD"
json_attributes:
- name
- symbol
- price
- logo_url
- rank
- high
- high_timestamp
- market_cap
- first_trade
- name: "Crypto - BCH - 1 Hr"
json_attributes_path: "$.[5].1h"
unit_of_measurement: "USD"
value_template: '{{ value_json[5]["1h"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - BCH - 1 D"
json_attributes_path: "$.[5].1d"
unit_of_measurement: "USD"
value_template: '{{ value_json[5]["1d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - BCH - 7 D"
json_attributes_path: "$.[5].7d"
unit_of_measurement: "USD"
value_template: '{{ value_json[5]["7d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - BCH - 30 D"
json_attributes_path: "$.[5].30d"
unit_of_measurement: "USD"
value_template: '{{ value_json[5]["30d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
### LTC
- name: "Crypto - LTC"
json_attributes_path: "$.[6]"
value_template: '{{ value_json[6].price | round(4) }}'
unit_of_measurement: "USD"
json_attributes:
- name
- symbol
- price
- logo_url
- rank
- high
- high_timestamp
- market_cap
- first_trade
- name: "Crypto - LTC - 1 Hr"
json_attributes_path: "$.[6].1h"
unit_of_measurement: "USD"
value_template: '{{ value_json[6]["1h"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - LTC - 1 D"
json_attributes_path: "$.[6].1d"
unit_of_measurement: "USD"
value_template: '{{ value_json[6]["1d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - LTC - 7 D"
json_attributes_path: "$.[6].7d"
unit_of_measurement: "USD"
value_template: '{{ value_json[6]["7d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - LTC - 30 D"
json_attributes_path: "$.[6].30d"
unit_of_measurement: "USD"
value_template: '{{ value_json[6]["30d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
### XLM
- name: "Crypto - XLM"
json_attributes_path: "$.[7]"
value_template: '{{ value_json[7].price | round(4) }}'
unit_of_measurement: "USD"
json_attributes:
- name
- symbol
- price
- logo_url
- rank
- high
- high_timestamp
- market_cap
- first_trade
- name: "Crypto - XLM - 1 Hr"
json_attributes_path: "$.[7].1h"
unit_of_measurement: "USD"
value_template: '{{ value_json[7]["1h"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - XLM - 1 D"
json_attributes_path: "$.[7].1d"
unit_of_measurement: "USD"
value_template: '{{ value_json[7]["1d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - XLM - 7 D"
json_attributes_path: "$.[7].7d"
unit_of_measurement: "USD"
value_template: '{{ value_json[7]["7d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - XLM - 30 D"
json_attributes_path: "$.[7].30d"
unit_of_measurement: "USD"
value_template: '{{ value_json[7]["30d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
### TRX
- name: "Crypto - TRX"
json_attributes_path: "$.[8]"
value_template: '{{ value_json[8].price | round(4) }}'
unit_of_measurement: "USD"
json_attributes:
- name
- symbol
- price
- logo_url
- rank
- high
- high_timestamp
- market_cap
- first_trade
- name: "Crypto - TRX - 1 Hr"
json_attributes_path: "$.[8].1h"
unit_of_measurement: "USD"
value_template: '{{ value_json[8]["1h"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - TRX - 1 D"
json_attributes_path: "$.[8].1d"
unit_of_measurement: "USD"
value_template: '{{ value_json[8]["1d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - TRX - 7 D"
json_attributes_path: "$.[8].7d"
unit_of_measurement: "USD"
value_template: '{{ value_json[8]["7d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
- name: "Crypto - TRX - 30 D"
json_attributes_path: "$.[8].30d"
unit_of_measurement: "USD"
value_template: '{{ value_json[8]["30d"]["price_change"] | round(4) }}'
json_attributes:
- price_change_pct
This allows me to display the latest crypto information like so
Hope this can be helpful to somebody.
There is a slight issue at present where by the data is returned every 10 seconds but all the data for the 10 coins I track is pulled in 1 request. This means you dont fall foul of the 1 call per second limit. However, it means all the coins are returned in various arrays to pulling this information into sensors means using template sensors such as value_json[8].price
This is fine if the coins are always returned in the same order on the page. By default, they are returned by marketcap, however by appending the API query with &sort=first_priced_at then you should be able to order them by the time they were first priced in the market. however, this sort function seems to be ignored in my testing and they are always returned by marketcap which is noticeable today as big movements in the market are changing the top 10 listed coins. Ive reached out to nomics to get this paramater fixed.