Hello everyone, I’m back again! And this time with another great Home Assistant Tutorial! Today, I’m going to show you how to make your crypto portfolio visible in Home Assistant. Additionally, I’ll teach you how to display graphs on your dashboard and how to track the highest and lowest values of your cryptocurrencies. Even if you don’t have any bitcoins or other cryptocurrencies yourself, you’ll still learn a lot about how to work with numbers in Home Assistant. Let’s get started!
โญโญโญ NOTE: โญโญโญ
This article accompanies a YouTube video. I wrote it for people who would rather read than watch a video. To keep doing this, I want to ask you to check out the video, leave a comment under the video, give the video a thumbs up, and subscribe to my YouTube channel. This means that the video is offered more often to new visitors so that they also stay informed of the latest Home Assistant tutorials.
Thank you for your support!
Ed
First of all, I want to tell you that the crypto values I show in this video are not my own cryptocurrencies. In this video, I’m just showing an example, and they are not based on my personal crypto portfolio. Although I do wish I had bitcoins myself, haha. But anyway, now that Bitcoin has risen above 100,000 dollars, I thought it would be fun to show how you can keep track of your crypto portfolio in Home Assistant.
First, you need an integration to fetch your cryptocurrency values. For this, we’re going to use the HACS integration ‘Cryptoinfo advanced.’ If you haven’t installed HACS yet, check out this video where I explain how to do that. You can find the link in the description of this video.
- Go To HACS.
- Search for Crypto.
- Click on Cryptoinfo Advanced.
- Click Download.
- Click Download again.
- Now restart Home Assistant by clicking on Settings.
- Click on the arrow next to the Repair message to Restart Home Assistant.
- Click Submit.
- Click Finish.
- Home Assistant will now be restarted.
After Home Assistant has been restarted, we need to create a sensor for each cryptocurrency we want to display. We will do this in YAML, and for that, we need a text editor. You can use the Studio Code Server or File Editor add-on for this. I personally use Studio Code Server. If you haven’t installed it yet, here’s how you can do that:
- Go to Settings.
- Click Add-ons.
- Click Add-on store.
- Search for studio.
- Click Studio Code Server.
- Click Install.
- After the installation is completed, turn on all the toggle switches and click start.
Studio Code Server is now installed. We will now add the sensor code.
- Go to Studio Code Server.
- You see all the files on your Home Assistant server on the left side.
- Click on Configuration.yaml.
- Add the following line:
sensor: !include sensors.yaml
- Save your configuration.yaml.
- Create a new file and name that file sensors.yaml.
- Add the following code:
- platform: cryptoinfo_advanced
id: "bitcoin"
cryptocurrency_name: "bitcoin"
currency_name: "eur"
unit_of_measurement: "โฌ"
multiplier: 0.4
update_frequency: 15
- platform: cryptoinfo_advanced
id: "litecoin"
cryptocurrency_name: "litecoin"
currency_name: "eur"
unit_of_measurement: "โฌ"
multiplier: 20
update_frequency: 15
- platform: cryptoinfo_advanced
id: "ripple"
cryptocurrency_name: "ripple"
currency_name: "eur"
unit_of_measurement: "โฌ"
multiplier: 150
update_frequency: 15
- I’ve added three crypto currencies to the sensors.yaml, namely bitcoin, litecoin and ripple.
- For each currency you need to add some lines.
- The first line points to the integration.
- Then you need to define an id. That id can be looked up in Home Assistant later.
- Then you enter the cryptocurrency name. In the first case it’s “bitcoin”.
- You can find the cryptocurrency names on this page. Just search with control-F in the code for the currency that you want to use. When I search for “ripple” I will find the currency name: ripple, but sometimes the name is a bit different than you would expect.
- Then you define the currency name. I use euros, so it’s eur.
- The unit of measurement is the euro sign.
- And then the multiplier. Let’s say that I have 0.4 bitcoin in my portfolio. The multiplier value is 0.4 in that case.
- The last line contains the update frequency in minutes. I’ve set it to 15 minutes because I don’t want to flood the integration with api calls with the risk of being banned. So, every 15 minutes the value of the bitcoin will be retrieved in euros.
I did the same for Litecoin and Ripple. For Litecoin, I added a multiplier of 20, and for Ripple, a multiplier of 150. So, in this hypothetical case, I would own 0.4 bitcoins, 20 Litecoins, and 150 Ripples.
- Save the sensors.yaml file.
- Go to settings.
- Click the three dots in the upper right corner.
- Select Restart Home Assistant.
- Select restart Home Assistant again en click restart.
If everything went well, three new sensors have now been added to Home Assistant: one for Bitcoin, one for Litecoin, and one for Ripple. We can test this in the developer tools.
- Go to developer tools.
- Click the States tab.
- Search for bitcoin.
- You will see the value in euros for the bitcoins you own.
- Search for litecoin and you will see the value in euro for your litecoin as well.
- The same counts for your ripple.
I need your help!
You will be doing me a huge favor if you subscribe to my channel if you haven’t already. And, you will help me a lot if you also give this video a thumbs up and leave a comment. This way, YouTube will present this video to new people, making the channel grow! In the video description, you will also find information about how you can sponsor me so that I can continue to make these tutorials for you.
Thank you!
Now that the sensors for our cryptocurrencies are available, we can start working on our dashboard. Open a dashboard and click on the plus symbol.
- Make sure your dashboard view is set to “Sections”.
- Give your dashboard a title. I name it Crypto.
- Set the maximum number of sections to three.
- Click Save.
- Delete the “New Section” Header. I know, you can also rename it in this case, but I’m just showing you how to create a heading.
- Click the plus sign.
- Select Heading.
- Give your heading a name, for instance “Bitcoin”.
- Select an icon. In this case it’s the bitcoin icon.
- Click Save.
- Click the plus sign.
- Select the Tile card.
- Select the Bitcoin entity.
- Click Appearance.
- Enter a name in the name field.
- Select a color.
- Toggle the vertical option.
- Click the layout tab.
- Toggle precise mode.
- Set the layout to 4 by 2. I want to show two extra tile cards later in this tutorial so this way I can position three Tile cards next to each other.
- Click Save.
- Click the plus sign.
- Search for history.
- Select the History Graph card.
- Choose the Bitcoin entity in the entity field.
- Click the Layout tab.
- Toggle the Full Width card switch.
- Click Save.
The Bitcoin section is now ready. I did the same with the Litecoin and Ripple sections, so the result would be like this now. As you can see the graphs show the entity names. For instance, it shows Cryptoinfo Bitcoin, but I want it to show the name Bitcoin instead. Next to that, the number of decimals is set to 1 and I want it to be 2. Let’s change that!
- Click on the Bitcoin tile card.
- Click the cog wheel.
- Enter the custom name that you want to show in the name field.
- Select the precision that shows two decimals in the display precision field.
- Click Save.
- You will see that the precision has been changed, but the name in the history graph has not changed yet. Don’t worry, when you refresh your browser it will change!
- I did the same for Litecoin and Ripple and will refresh the browser now.
- As you can see, the names in the history graphs have now also been adjusted.
Our dashboard now displays the cryptocurrencies from our portfolio. Of course, it will take a while for the history graph to populate. After all, a value is retrieved every 15 minutes, and we’ve only just set everything up. So give it some time before you see the graphs filling up. But actually, you want to see even more. You want to see what the lowest and highest values of your cryptocurrencies have been, and you’d like to see how much euro value you have in total in your cryptocurrencies. So, weโre going to build that as well.
First, weโll create helpers where weโll store these values.
- Go to Settings.
- Select Devices and Services.
- Click the Helpers Tab.
- Click Create Helper.
- Select the Number helper.
- Give your Helper a name. In this case, Bitcoin Min.
- Set the maximum value to 1000000.
- Set the display mode to Input field.
- Set the step size to 0.01.
- Set the unit of measurement to the euro sign.
- Click Create.
Now also create number helpers for Bitcoin Max, Litecoin Min, Litecoin Max, Ripple Min, and Ripple Max. Use the same settings you used for the Bitcoin Min helper. Next, we will fill the current values of our cryptocurrencies into the helpers. To do this, click on each helper we just created and enter the amount you see on your dashboard. This gives us a starting point for all our minimum and maximum values.
In addition to these minimum and maximum helpers, we also want to see the total value of our portfolio and the highest total value our portfolio has ever had. So, weโll create two more helpers for that as well.
- Click Create Helper.
- This time select the “Combine the state of several sensors” helper.
- Give this helper the name Crypto Total.
- And select Bitcoin, Litecoin, and Ripple as Entities.
- Select Sum in the Statistic characteristic field.
- Make sure that the precision field is set to 2.
- Click Submit.
- Click Finish.
If you now click on the Crypto Total helper, youโll see the total amount displayed there. Next, weโll create one more helper, which is the Crypto Total Max helper.
- Click Create Helper Again.
- Select the Number Helper.
- Give the Helper the name Crypto Total Max.
- Set the maximum value to 1000000.
- Select the Input field as display mode.
- Set the step size to 0.01 and the unit of measurement to the euro sign.
- Click Create.
All right, all our helpers are now ready. Next, weโll create an automation that will populate these helpers. Letโs start with the automation that will fill in the maximum values.
- Go to Settings > Automations and Scenes.
- Click Create Automation.
- Click Create New Automation.
- Select Add Trigger.
- Select Entity.
- Select State.
- Search for the Bitcoin entity.
- Click the three dots in the upper right corner.
- Select Edit ID.
- Enter the Trigger ID Bitcoin.
- Click Add Trigger and do the same for Litecoin.
- Click Add Trigger again and do the same for Ripple.
- Click Add Trigger again.
- Select Entity.
- Select State
- Select the Crypto Total entity.
- Click the three dots in the upper right corner.
- Select Edit ID.
- Enter the Trigger ID Crypto Total.
The triggers are now defined. let’s create the actions!
- Go to the Then Do section.
- Click Add Building Block.
- Select Choose.
- Open the first option.
- Click Add Condition.
- Select Other Conditions.
- Select Triggered By.
- Toggle the bitcoin trigger id checkbox, so this action will trigger when the value of the bitcoin changes.
- Click Add Action.
- Search for input number.
- Select: Input Number Set.
- At target select the Bitcoin Max input number helper that we created before.
- For the value we need to enter some YAML. Click on the three dots in the upper right corner of the action.
- Select Edit in YAML.
- Enter the following code:
action: input_number.set_value
metadata: {}
data:
value: >
{% if states('sensor.cryptoinfo_bitcoin')|float(0) >
states('input_number.bitcoin_max')|float(0) %}
{{ states('sensor.cryptoinfo_bitcoin')|float(0) }}
{% else %}
{{ states('input_number.bitcoin_max')|float(0) }}
{% endif %}
target:
entity_id: input_number.bitcoin_max
- So, what are we doing here?
- We check if the current bitcoin value is greater than the value that is stored in the input number bitcoin max helper. If so, we set the input number bitcoin max helper to the current bitcoin value.
- If not, we use the input number value. This is needed to prevent an error in the Home Assistant logs.
- Now, we are going to repeat this step for Litecoin and Ripple.
- Click on add Option and repeat the steps you did for Bitcoin, but use the Litecoin variables instead.
- And repeat this for Ripple using the ripple variables.
- And lastly, repeat this for Crypto Total. Notice that I used round(2) here instead of float(0).
If you want to know more about YAML and Jinja code, please follow my Yaml and Jinja course where I explain everything in detail. The link is in the description of this video.
- Click Save and give your automation a meaningful name.
Our automation is now almost ready, but I need to do one more thing, namely that I have to set the automation to the queued mode. There is a chance that all triggers might be triggered simultaneously, and in that case, I want them to be handled one after the other.
- Click the three dots in the upper right corner.
- Select Change mode.
- Select Queued.
- Click Change Mode.
- Click Save.
The helpers with the maximum values are now being filled automatically. Now we need to do the same for the helpers with the minimum values.
- Click the three dots in the upper right corner.
- Click Duplicate.
- Delete the Crypto Total trigger.
- And remove the Crypto Total option in the Then Do Section.
- Now open option 1.
- We are going to add a condition to make sure that the value will never be set to 0 when a value cannot be retrieved.
- Click Add condition.
- Select Entity.
- Select Numeric State.
- Select Bitcoin.
- Enter 0 in the Above field.
- Scroll down to the Actions section and open the Input Number Set on Bitcoin Max section.
- Alter the code so that it points to the Bitcoin Min helper and change the greater than sign to the less than sign.
- Follow the same procedure for Litecoin and Ripple.
- Click Save and give your automation a meaningful name.
The helpers with the minimum values are now also being filled automatically. Now we just need to add these values to our dashboard.
- Open the dashboard that we created before.
- Click the pencil.
- Click the plus sign in the Bitcoin section.
- Select the Tile card.
- Choose the bitcoin min input number helper.
- Click Appearance.
- Change the color, toggle the vertical switch, and change the icon to your liking.
- Click the Layout tab.
- Toggle precise mode and set the layout to 4 by 2.
- Do the same for the Bitcoin Max input helper.
- Drag and drop the Bitcoin Min and Bitcoin Max tile cards next to the Bitcoin Tile Card.
- Repeat this procedure for Litecoin and Ripple.
Now we just need to add the Crypto Max helpers. Iโm going to add them as badges.
- Click the Plus in the badge section.
- Click Entity.
- Select the Crypto Total Entity.
- Click Appearance.
- Change the icon and color to your liking.
- Toggle the Name checkbox.
- Click Save.
- Do the same for the Crypto Total Max input number helper.
- Click Done.
Your dashboard is now complete, and from now on, you can monitor your cryptocurrency portfolio through Home Assistant. However, thereโs one thing that isnโt displayed very nicely: the input number helpers donโt show two decimal places when a number after the decimal is a multiple of ten. Unfortunately, you canโt set precision for input number helpers in Home Assistant. Iโve created a feature request for this on the Home Assistant forums. If youโd also like this to be added, please vote on the feature request. Youโll find the link in the video description.
That said, there is a solution. You can create a template for each minimum and maximum value, and then two decimal places will be displayed. Itโs beyond the scope of this video to explain how, but if you take my YAML and Jinja course, youโll be able to create it yourself. The link for this is also in the video description.
As always, you can copy the code for free from the screen, but if youโd like to support me, you can make a donation. In return, youโll get all the code and two blueprints that you can download, making it easy to copy and paste them into your Home Assistant setup. Youโll still need to create the helpers yourself, but this will save you a lot of time and probably some frustration. Anyway, see what works best for you. Your support helps me a lot in keeping this channel alive.
Iโd like to give a special thanks to these people who support me monthly with a small contribution. Without your help, I wouldnโt be able to continue this work. Thank you all so much. If youโd also like to help ensure this channelโs survival, you can support me through Patreon, Ko-Fi, or by becoming a paid member of this channel. If you join through Ko-Fi, youโll also get significant discounts on the code you can download.
Thank you for watching, and donโt forget to give this video a thumbs up, leave a comment, and subscribe to my channel. That also helps keep this channel going, as YouTube will show this video to more people.
Iโll see you soon in my next video!
Bye Bye!