Coinmarketcap Integration

Hi,

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.

I’m using the coinmarketcap currency IDs found here: https://api.coinmarketcap.com/v2/ticker/
Here is my code:

sensor:
  - platform: coinmarketcap
    currency_id: 1
    display_currency: USD
    display_currency_decimals: 2

  - platform: coinmarketcap
    currency_id: 52
    display_currency: USD
    display_currency_decimals: 2

I would love to get this working through HomeAssistant because I can use the values when the market changes to trigger different automations.

Any help is greatly appreciated.
Thank you.

I know some API’s allow X requests per X period. Could be that your IP gets blocked when your instance does too many requests.

Check the faq or documentation.

Thanks for your reply, I’m only trying to display 2 digital coins, so I don’t think I’m sending that many requests to coinmarketcap.

Also once they stop working even after I wait a whole day, they still dont start working on their own again.

I have same problem too. Since yesterday integration does not working

see Issue: 32551Coinmarketcap platform uses an outdated API, the homeassistant component is using the old coinmarketcap api. Seems they disabled the old api a day or two ago…

yup, thank you.

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.

More info here: BitFetch.io - Integrate Bitcoin & Cryptocurrency Data into Home Assistant!

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.

craigcarps from github left a comment on the raised issue over at github, providing us with a working example.

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
2 Likes

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:

{{ states.sensor.coinmarketcap_curl.attributes.data.BTC.quote.USD }}

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

Captura de pantalla 2023-07-27 064833

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).