Coinmarketcap Integration


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:
Here is my code:

  - 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: - 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 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

  - 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 ""'
    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)
    - data
  - platform: template
        friendly_name: 'Bitcoin Price'
        unit_of_measurement: 'USD'
        value_template: '{{ (( | float) | round(2) }}'
        friendly_name: 'Ethereum Price'
        unit_of_measurement: 'USD'
        value_template: '{{ (( | float) | round(2) }}'
        friendly_name: 'Ripple Price'
        unit_of_measurement: 'USD'
        value_template: '{{ (( | 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'
  - platform: numeric_state
    entity_id: sensor.btc_price
    above: '50000.00'
condition: []
  - service: tts.google_translate_say
    entity_id: media_player.living_room_speaker
      message: >-
        Bitcoin has reached surpassed an alert marker and is trading at {{
        states.sensor.btc_price.state }}
  - service: notify.notify
      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

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