Help with parsing long JSON into multiple sensors

I am trying to integrate Heatermeter into HA, and need to parse a long JSON result into HA. I have brought the JSON into the template editor, and figured out the correct templates, but the sensor dosen’t work. I want to get a sensor for the set temp, then each of the four “C” values.

Capture

Sensor.yaml code:

     - platform: rest
        name: hm_set
        resource: http://www.json-generator.com/api/json/get/bUqTKMCRea
        value_template: '{{ value_json[set] }}'
      - platform: rest
        name: hm_pit
        resource: http://www.json-generator.com/api/json/get/bUqTKMCRea
        value_template: '{{ value_json.temps.0.c }}'

JSON code:

    {
      "time": 1553700649,
      "set": 240,
      "lid": 0,
      "fan": {
        "c": 0,
        "a": 0,
        "f": 0
      },
      "adc": [
        0,
        0,
        0,
        0,
        0,
        0
      ],
      "temps": [
        {
          "n": "Pit",
          "c": null,
          "a": {
            "l": 180,
            "h": 260,
            "r": "l"
          }
        },
        {
          "n": "Flat",
          "c": 76,
          "a": {
            "l": -40,
            "h": 195,
            "r": null
          }
        },
        {
          "n": "Probe 2",
          "c": 85,
          "a": {
            "l": -40,
            "h": -200,
            "r": null
          }
        },
        {
          "n": "Point",
          "c": 90,
          "a": {
            "l": -40,
            "h": 195,
            "r": "h"
          }
       }
      ]
    }

Either
{{ value_json['set']}}
or
{{ value_json.set }}
but not
{{ value_json[set] }}

Either
{{value_json.temps[0]['c'] }}
or
{{value_json.temps[0].c }}
but not sorry, this also works
{{ value_json.temps.0.c }}

I had already tried these

value_template: "{{value_json['temps'][1].c}}"
value_template: '{{value_json[temps][1].c}}'
value_template: '{{value_json.temps.1.c}}'

Those didn’t work either. I’m wondering if it has to do with it testing against json-generator.com (i’m at work, and forgot to plug in the hetermeter before I left home).

I like to use jq to test json parsing

pi@raspberrypi:~ $ cat test.json | jq .temps[1].c
76

I don’t think the value_template is the issue. In your previous post you listed three and the first and third are valid (they work in the Template Editor). If they failed to parse the received JSON data then there’s something else amiss.

someone on FB figured it out. The feed from json-generator.com had [ ] around the entire block, so it needed to be value_json[0].temps[1].c for the test to work. Thanks for the help.

So the sample data you posted above was wrong?

That was a waste of time … :frowning:

… and “there’s something else amiss” proved to be true.

1 Like

Can you elaborate on what you have build? Would love to integrate heatermer!

Put me down as another that would love to integrate heatermeter into HA.

For anyone interested, subscribe to notifications on this ticket: https://github.com/CapnBry/HeaterMeter/issues/48 (plan to add MQTT to heatermeater). Please don’t go crazy spamming the bug with “me too” comments.

Alternative, it looks like someone started a direct component: https://github.com/fancygaphtrn/heatmeter

1 Like