Help with REST Sensor with a variable key

Hi,

I’m having trouble creating my rest sensors.

This what I have so far and it seems to work:

rest:
  - resource: http://192.168.1.200:8266/api/v2/get-nodes
    scan_interval: 60
    sensor:
      - name: "Tdarr_Node_1"
        value_template: "OK"
        json_attributes_path: "$.NfpRMAU27"
        json_attributes:
          - "_id"
          - "nodeName"
      - name: "Tdarr_Node_2"
        value_template: "OK"
        json_attributes_path: "$.Y21O0p9bK"
        json_attributes:
          - "_id"
          - "nodeName"

And this is how the JSON looks like:

{
  "NfpRMAU27": {
    "_id": "NfpRMAU27",
    "nodeName": "CTNTower",
    "remoteAddress": "::ffff:172.17.0.1",
    "config": {
      "nodeID": "NfpRMAU27",
      "nodeName": "CTNTower",
      "serverIP": "192.168.1.200",
      "serverPort": "8266",
      "handbrakePath": "",
      "ffmpegPath": "",
      "mkvpropeditPath": "",
      "pathTranslators": [
        {
          "server": "",
          "node": ""
        }
      ],
    },
  },
  "Y21O0p9bK": {
    "_id": "Y21O0p9bK",
    "nodeName": "VM_Tower",
    "remoteAddress": "::ffff:192.168.1.210",
    "config": {
      "nodeID": "Y21O0p9bK",
      "nodeName": "VM_Tower",
      "serverIP": "192.168.1.200",
      "serverPort": "8266",
      "handbrakePath": "",
      "ffmpegPath": "",
      "mkvpropeditPath": "",
      "pathTranslators": [
        {
          "server": "",
          "node": ""
        }
      ],
    },
  }
} 

My problem is that NfpRMAU27 & Y21O0p9bK are not constant. Every time that the resource gets restarted, those keys will change. The nodeName will remain constant, but I need the key/_id in order to perform further actions with them. As you can see I have hard coded them in for now, but that’s not the proper long term solution.

So how can I make this work?

So I’ve been playing around a bit more and tried this instead:

rest:
  - resource: http://192.168.1.200:8266/api/v2/get-nodes
    scan_interval: 900
    sensor:
      - name: "Tdarr_Node_All"
        value_template:  >
          {% for value in value_json %}
            {{value}} {{ value_json[value].nodeName }}
          {% endfor %}
        json_attributes_path: "$..config"
        json_attributes:
          - "nodeID"
          - "nodeName"

When testing it afterwards {{ state_attr('sensor.tdarr_node_all','nodeID') }} gives me NfpRMAU27

If I try {{ states('sensor.tdarr_node_all') }} it gives me

NfpRMAU27 CTNTower

  Y21O0p9bK VM_Tower

How would I be able to extract just the second sets of values?