Adding Ethereum Price as a REST Sensor in Home Assistant

Having quick and easy access to crypto prices such as Ethereum is very handy if you are an investor. But what if you wanted to be able to do more with that information? Maybe you want to have an alert sent to your phone if the price is above or below a certain set point. Perhaps you have a smart watch and want to be able to have the price update on your wrist for information at-a-glance. You can do all of those things by adding a rest sensor with the price of Ethereum.

Prerequisites

The only prerequisite for this sensor is to have Home Assistant installed. I prefer to keep my rest sensors in a rest.yaml file so if you want to copy my information you will want to have that setup as well.

Finding the sensor

The first step to bringing the Ethereum price into your Home Assistant, is finding where to retrieve the price on the internet. I prefer to grab prices from Coinbase since it is quite simple once you know what to look for. We will navigate to the Ethereum price on Coinbase, and then use Google Chrome to inspect from where that price is being pulled.

Ethereum Price Page on Coinbase
Ethereum Price page on Coinbase

It is very straightforward on Coinbase as the Ethereum price is simply at https://www.coinbase.com/price/ethereum.
Now that we can see the value, we can inspect the page to find from where the value is populated. Right click anywhere on the page and select “inspect” to open up the inspection window. The tab we are looking for is “Network” which is where you can see the network and api calls made from this web page. After you have the inspection window opened, refresh the web page so that the network tab can populate all of the api calls.

Finding Where The Information Comes From

Network Requests on Coinbase Ethereum Price
Network Requests on Coinbase Ethereum Price

At the time of this screenshot, the page had already made 157 requests, but the one we are interested in is this query to load the price chart. When you click on this query, you can see the request URL as well as the response that gets sent back from that request. If this looks a lot like the API call REST sensor, that’s because it basically is the same.

Stepping in to the query for the Ethereum Price.
Stepping into the Query for the Ethereum Price

The “Request URL” is call that is being made to the server to find the Ethereum Price. This will become the “Resource” for our REST sensor. We can copy this URL and paste it into our browser to see what information is available.

The response for the Ethereum Price on Coinbase
The response for the Ethereum price on Coinbase

This response has a lot of information in it. What we would like to pull would be the price from the hourly quote at the beginning of this json file. Inside the data-assetBySlug-hour-quotes[0] we see the “price” which is what we are going to pull into our Home Assistant. This will be the same target every time we grab the Ethereum price so it will always pull in the most recent quote which appears to refresh every ten minutes.

Adding the REST Sensor to Home Assistant

We now have the URL we will use as our resource and the json path to get to the information we would like to use for our Ethereum price. The final step is bringing it all together as a REST sensor in Home Assistant.
Again, I try to keep all of my REST sensors together in the rest.yaml file, so this will copy and paste straight in if you do the same.

- resource: https://www.coinbase.com/graphql/query?&operationName=useGetPriceChartDataQuery&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%22b56be28dfa78566206fb130f9b4a21503b3eb17ce0c7e3649743916534ad6058%22%7D%7D&variables=%7B%22skip%22%3Afalse%2C%22slug%22%3A%22ethereum%22%2C%22currency%22%3A%22USD%22%7D
  sensor:
    - name: Ethereum Price
      value_template: "{{ ((value_json['data']['assetBySlug']['hour']['quotes'][0]['price'])) }}"
      unit_of_measurement: "$"

The “resource” is the URL for the call to get the JSON data. Then we add the sensor based on what we want to grab from this DATA. The “value_template” is how we tell Home Assistant what value to use for this REST sensor and the “unit_of_measurement” is there to keep it organized.

Ethereum price as REST sensor in Home Assistant
Ethereum Price as REST Sensor in Home Assisant

And you’re all set! This new sensor will update with the new Ethereum price at the standard polling interval. You can create automations with this information or add it to the companion app and have it show up on your smart watch!

Leave a Reply

Your email address will not be published. Required fields are marked *