I tried to integrate some digital currency into my home assistant config but for some reason it sometimes work and most of the time it doesn’t work especially when I restart home assistant.
I tried 2 different HA installations, one on an ubuntu machine and another one on a Raspberry Pi 3B+. In both installations the coinmarketcap sensor is behaving the same, it just works sometimes and a lot of the times it says entity not found, then when I restart, some of digital currency work and then when I restart again non works.
We made BitFetch and started using it with HA due to the unreliability of the Bitcoin sensor as well as the CoinMarketCap and other cryptocurrency HA sensors stopped working. We don’t have a custom component (yet!) but our team is successfully using it with HA in their homes via Node Red.
We’re happy to help you set it up if you need help, just DM us or respond, and would love your feedback. BitFetch supports hundreds of cryptocurrency pairs, and our FREE plan was made with HA users in mind.
The Coinmarketcap integration is deprecated, however using a command_line template you can still use CMC, just make sure you use curl to call the new api https://pro-api.coinmarketcap.com and provide the api key in the header info.
Below I have typed it out with preformatting to preserve the indents, based on USD values, and looking up 3 coins: BTC, ETH and XRP as an example:
Don’t forget to substitute the XXXXXXXX characters with your API key which can be obtained for free over at CoinMarketCap
sensor:
- platform: command_line
name: coinmarketcap_curl
command: '/usr/bin/curl -X GET -H "X-CMC_PRO_API_KEY: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" -H "Accept: application/json" -d "symbol=BTC,ETH,XRP&convert=USD" -G "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest"'
value_template: '{{ value_json.value }}'
scan_interval: 600 #10 mins refresh (this rate will use 144 credits per day out of the allocated 333 credits)
json_attributes:
- data
- platform: template
sensors:
btc_price:
friendly_name: 'Bitcoin Price'
unit_of_measurement: 'USD'
value_template: '{{ ((states.sensor.coinmarketcap_curl.attributes.data.BTC.quote.USD.price) | float) | round(2) }}'
eth_price:
friendly_name: 'Ethereum Price'
unit_of_measurement: 'USD'
value_template: '{{ ((states.sensor.coinmarketcap_curl.attributes.data.ETH.quote.USD.price) | float) | round(2) }}'
xrp_price:
friendly_name: 'Ripple Price'
unit_of_measurement: 'USD'
value_template: '{{ ((states.sensor.coinmarketcap_curl.attributes.data.XRP.quote.USD.price) | float) | round(2) }}'
I personally decided to take it further by adding an automation so that google assistant announced an alert if the value surpasses a set value, and pushes a notification too:
alias: Bitcoin value exceeds specific value
description: '50,000 USD'
trigger:
- platform: numeric_state
entity_id: sensor.btc_price
above: '50000.00'
condition: []
action:
- service: tts.google_translate_say
entity_id: media_player.living_room_speaker
data:
message: >-
Bitcoin has reached surpassed an alert marker and is trading at {{
states.sensor.btc_price.state }}
- service: notify.notify
data:
title: Crypto Alert
message: 'Bitcoin is now trading at {{ states.sensor.btc_price.state }}'
mode: single
Maybe you already know, but I just found out that you can get more information than the cryptocurrency price from CMC. Just go to developers options, templates and use this:
It will show you all available information (price, volume_24h, volume_change_24h, percent_change_1h, percent_change_24h, percent_change_7d, percent_change_30d, percent_change_60d, percent_change_90d, market_cap, market_cap_dominance, fully_diluted_market_cap, tvl, last_updated)
In fact i use it to get percent_change_24h and create this mushroom chips cards
Check this out if you are interested (it is originally written in spanish, but through that link you can chose your language and translate it).