Sensor based on REST doesnt work

Hello,

first of all, im very happy to use home assistant, i switched from iobroker to openhab and now im finally here. Im trying to build my fronted and i want to see my ethereum mining stats.

So i try to build a custom sensor based on rest to get informations about my mining rig.
But it doesnt work, and i dont know how to find the problem, every sensor is unknown.

homeassistant:
  customize:
    sensor.amd01_status:
      friendly_name: "AMD01"
      icon: mdi:ethereum

sensor:
  - platform: rest
    name: AMD01
    resource: https://api.minerstat.com/v2/stats/XXXXXXXXX/XXXXXXX
    value_template: "{{ value_json.info.status }}"
    json_attributes:
      - info
      - revenue
      - mining
  - platform: template
    sensors:
      info_status:
        value_template: "{{ states.sensor.amd01_status.attributes.info.status }}"
      info_uptime:
        value_template: "{{ states.sensor.amd01_status.attributes.info.uptime}}"
      revenue_day:
        value_template: "{{ states.sensor.amd01_status.attributes.revenue.usd_day }}"
      revenue_week:
        value_template: "{{ states.sensor.amd01_status.attributes.revenue.usd_week }}"
      revenue_month:
        value_template: "{{ states.sensor.amd01_status.attributes.revenue.usd_month }}"
      hashrate:
        value_template: "{{ states.sensor.amd01_status.attributes.mining.hashrate.hashrate }}"

group:
  amd01:
    name: AMD01
    entities:
      - sensor.info_status
      - sensor.info_uptime
      - sensor.revenue_day
      - sensor.revenue_week
      - sensor.revenue_month
      - sensor.hashrate

Post the results of your url

Of course, this is the sample result from minerstat:

{
 "AMD01": {
  "info": {
   "type": "nvidia",
   "system": "linux",
   "status": "online",
   "inactive": 0,
   "status_reason": "",
   "status_cpu": "idle",
   "uptime": "3d 21h 7min",
   "sync": 4,
   "time": "2020-04-13 18:34:45",
   "note": 0,
   "profit_switch": 0,
   "name": "Worker001",
   "version": "4",
   "groups": "nvidia,msos",
   "cmd": "",
   "electricity": 0.05,
   "hot": 75,
   "veryHot": 85,
   "devices": 7,
   "consumption": "+150",
   "os": {
    "status": "online",
    "sync": 4,
    "uptime": "36d 10h 49min",
    "cpu_temp": 27,
    "cpu_load": 28,
    "freespace": 36.112,
    "freemem": 0.851,
    "localip": "192.168.0.3"
   }
  },
  "hardware": [
   {
    "name": "P102-100",
    "temp": 67,
    "fan": 99,
    "power": 169,
    "powerMin": 125,
    "powerMax": 300,
    "powerStock": 250,
    "speed": 42.508,
    "bus": "01:00.0",
    "core": 1657,
    "coreMax": 1911,
    "memory": 5643,
    "memoryMax": 5505,
    "load": 100
   },{
    "name": "P102-100",
    ...
   }, ...
  ],
  "revenue": {
   "usd_day": 3.663,
   "usd_day_dual": 0,
   "usd_day_cpu": 0,
   "usd_week": 25.643,
   "usd_month": 109.897,
   "usd_month_dual": 0,
   "usd_month_cpu": 0,
   "btc_day": 0.00054,
   "btc_week": 0.003779,
   "btc_month": 0.016197,
   "coin": 0.71335365,
   "coin_dual": 0,
   "coin_cpu": 0,
   "cprice": 5.13521,
   "cprice_dual": 0,
   "cprice_cpu": 0
  },
  "mining": {
   "client": "PHOENIX-ETH",
   "client_version": "4.9c",
   "client_cpu": "",
   "client_cpu_version": "",
   "crypto": "ETH",
   "crypto_dual": "",
   "crypto_cpu": "",
   "pool": "eth.2miners.com: 2020",
   "pool_dual": "",
   "pool_cpu": "",
   "hashrate": {
    "hashrate": 304.67,
    "hashrate_unit": "MH",
    "hashrate_dual": 0,
    "hashrate_unit_dual": "",
    "hashrate_cpu": 0,
    "hashrate_unit_cpu": ""
   },
   "shares": {
    "accepted_share": 11958,
    "accepted_share_dual": 0,
    "accepted_share_cpu": 0,
    "rejected_share": 0,
    "rejected_share_dual": 0,
    "rejected_share_cpu": 0
   }
  }
 }
}

And this is my updated code, because i missed the main tag “AMD01”

homeassistant:
  customize:
    sensor.amd01_status:
      friendly_name: "AMD01"
      icon: mdi:ethereum

sensor:
  - platform: rest
    name: AMD01
    resource: https://api.minerstat.com/v2/stats/XXXXXXXXXX/XXXXXXxXX
    value_template: "{{ value_json.AMD01.info.status }}"
    json_attributes:
      - AMD01
  - platform: template
    sensors:
      info_status:
        value_template: "{{ states.sensor.amd01_status.attributes.AMD01.info.status }}"
      info_uptime:
        value_template: "{{ states.sensor.amd01_status.attributes.AMD01.info.uptime}}"
      revenue_day:
        value_template: "{{ states.sensor.amd01_status.attributes.AMD01.revenue.usd_day }}"
      revenue_week:
        value_template: "{{ states.sensor.amd01_status.attributes.AMD01.revenue.usd_week }}"
      revenue_month:
        value_template: "{{ states.sensor.amd01_status.attributes.AMD01.revenue.usd_month }}"
      hashrate:
        value_template: "{{ states.sensor.amd01_status.attributes.AMD01.mining.hashrate.hashrate }}"

group:
  amd01:
    name: AMD01
    entities:
      - sensor.info_status
      - sensor.info_uptime
      - sensor.revenue_day
      - sensor.revenue_week
      - sensor.revenue_month
      - sensor.hashrate

Edit: And is it possible to set an default value, if the API cannot be reached? I want to get rid of the message: “Entity is not available” in my frontend

This should be all you need following the rest integration

rest:
  - resource: https://api.minerstat.com/v2/stats/XXXXXXXXXX/XXXXXXxXX
    sensor:
    - name: AMD01 Status
      value_template: "{{ value_json.AMD01.info.status }}"
    - name: AMD01 Uptime
      value_template: "{{ value_json.AMD01.info.uptime }}"
    - name: AMD01 Revenue Day
      value_template: "{{ value_json.AMD01.revenue.usd_day }}"
    - name: AMD01 Revenue Week
      value_template: "{{ value_json.AMD01.revenue.usd_week }}"
    - name: AMD01 Revenue Month
      value_template: "{{ value_json.AMD01.revenue.usd_month }}"
    - name: AMD01 Hashrate
      value_template: "{{ value_json.AMD01.mining.hashrate.hashrate }}"

However, there is some invalid json in what you posted:

So that could be causing your current setup to fail.