Json extraction and Developer Tools - Template Editor - UKNOWN

Hi guys,

I am trying to extract certain information from JSON file.

Then testing data with Template Editor i get the right values

{% set value_json = {

  "device_summary": {
    "details": [
      {
        "dig": "team",
        "ver": "0.8.0"
      }
    ]
  },
  "device_stats": {
    "details": [
      {
        "dig": "team2",
        "what": "gold",
        "metal": "iron",

        "fans": [
          34,
          31,
          44,
          36,
          40
        ]
      }
    ]
  },
  "notes": "none"
}
 %}

From {{ value_json }} I get
{‘device_summary’: {‘details’: [{‘dig’: ‘team’, ‘ver’: ‘0.8.0’}]}, ‘device_stats’: {‘details’: [{‘dig’: ‘team2’, ‘what’: ‘gold’, ‘metal’: ‘iron’, ‘fans’: [34, 31, 44, 36, 40]}]}, ‘notes’: ‘none’}

From {{ value_json.device_stats.details[0].fans }} I get [34, 31, 44, 36, 40]
From {{ value_json.device_stats.details[0].fans[0] }} I get 34

But when I configure sensor I get state UNKNOWN - rather then 34

  - platform: rest
    name: Fans percentage
    resource: https://xxx.xxx.xxx.xxx
    method: GET
    headers:
      Authorization: Bearer **TOKEN**
    value_template: ' {{  value_json.device_stats.details[0].fans[0]  }} '
    unit_of_measurement: "%" 
    scan_interval: 30      

Any help with understanding why is this happening would be much appreciated.

What you put in the template editor is not JSON.

What do you actually get from the REST sensor without using value_template?

I am not getting any values, sensor is not even showing in Dev Tools. Error message in the log files saying it’s over 255 characters.

When I run Shell command

curl -X GET "https://xxx.xxx.xxx.xxx" -H  "accept: application/json" -H  "Authorization: Bearer **TOKEN**" | jq  '.device_stats.details[0].fans[0]'

I get the right value of 34

Thank you

Hmm, interesting.

You could enable debug for homeassistant.components.rest and then there might be useful info in home-assistant.log.

Thank you - will try that - good idea :slight_smile:

Thank you for pointing me in the right direction ! I had a typo in URL !!!

Much appreciated

1 Like