這篇文章將教您如何在 Home Assistant 中顯示 BTC 等虛擬貨幣價格。

configuration.yaml 中加入以下設定:

rest:
  - scan_interval: 60
    resource: https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin%2Cethereum%2Cbinance-coin%2Csolana&order=market_cap_desc&sparkline=false&price_change_percentage=1d
    sensor:
      - name: BTC
        json_attributes_path: "$[0]"
        value_template: "{{ value_json[0].current_price }}"
        unit_of_measurement: USD
        json_attributes:
          - id
          - current_price
          - price_change_percentage_24h
          - last_updated
      - name: ETH
        json_attributes_path: "$[1]"
        value_template: "{{ value_json[1].current_price }}"
        unit_of_measurement: USD
        json_attributes:
          - id
          - current_price
          - price_change_percentage_24h
          - last_updated
      - name: SOL
        json_attributes_path: "$[2]"
        value_template: "{{ value_json[2].current_price }}"
        unit_of_measurement: USD
        json_attributes:
          - id
          - current_price
          - price_change_percentage_24h
          - last_updated

即可看到貨幣出現在 Sensor 之中。 image