Hello, I have some strange behavior. I have server providing this JSON response:
{“btc”: {“luck_b10”: “0.80”, “luck_b50”: “1.11”, “luck_b250”: “1.01”, “hash_rate_unit”: “Gh/s”, “pool_scoring_hash_rate”: 7970543307.1116, “pool_active_workers”: 151559, “round_probability”: “0.08”, “round_started”: 1636128319, “round_duration”: 941, “pps_rate”: null, “blocks”: {“708346”: {“date_found”: 1636128319, “mining_duration”: 31730, “total_shares”: 58755565025679, etc. etc.
I need to get value “mining_duration”. for that, I would use following statements, that are working well:
sensor 49:
- platform: rest
resource: https://slushpool.com/stats/json/btc/
method: GET
headers:
SlushPool-Auth-Token: my token
value_template: "{{ value_json.mining_duration }}"
json_attributes_path: $.btc.blocks.708346
json_attributes:
- "mining_duration"
scan_interval: 37
name: slush_prev
the problem is that the block number in first line of array “blocks” is not constrant and it changes. So according to the JSON documentation, I would replace
json_attributes_path: $.btc.blocks.708346
with first record on the “blocks” array
json_attributes_path: $.btc.blocks[0]
but that is not working and no value is returned. That leads me to suspicion that implementation of JSON parser is not standard.
Any advice? Thank you!