Json values recognition

Hello, I jave this output in json

{
   "coretemp-isa-0000":{
      "Adapter": "ISA adapter",
      "Package id 0":{
         "temp1_input": 40.000,
         "temp1_max": 80.000,
         "temp1_crit": 99.000,
         "temp1_crit_alarm": 0.000
      },
      "Core 0":{
         "temp2_input": 37.000,
         "temp2_max": 80.000,
         "temp2_crit": 99.000,
         "temp2_crit_alarm": 0.000
      },
      "Core 1":{
         "temp3_input": 37.000,
         "temp3_max": 80.000,
         "temp3_crit": 99.000,
         "temp3_crit_alarm": 0.000
      },
      "Core 2":{
         "temp4_input": 36.000,
         "temp4_max": 80.000,
         "temp4_crit": 99.000,
         "temp4_crit_alarm": 0.000
      },
      "Core 3":{
         "temp5_input": 36.000,
         "temp5_max": 80.000,
         "temp5_crit": 99.000,
         "temp5_crit_alarm": 0.000
      }
   }
}

and want to create sensor with this value only:

 "Package id 0":{
         "temp1_input": 40.000,

how to recognize and get only this with value_json.

- platform: mqtt
  state_topic: 'house/plex-temp'
  device_class: temperature
  unit_of_measurement: '°C'
  value_template: '{{ value_json.**???????** | is_defined }}'

This template should return the value 40 for the key named temp1_input.

{{ value_json['coretemp-isa-0000']['Package id 0']['temp1_input'] }}

It uses bracket notation, instead of dot notation, because the first two key names contain characters that are incompatible with dot notation (hyphens and spaces).

For future reference, you can use https://jsonpathfinder.com/ to help you construct JSON paths.


NOTE

I’m not quite sure why you added the is_defined filter. It won’t prevent the template from failing if the received payload is missing any of the three keys.

Use an MQTT Sensor’s “availability” feature to gracefully handle the situation where the received payload doesn’t contain data in the desired format.

This is my config:

- platform: mqtt
  state_topic: 'house/plex-temp'
  name: "Plex Server Temperature"
  device_class: temperature
  unit_of_measurement: '°C'
  value_template: '{{ value_json.['coretemp-isa-0000']['Package id 0'].temp1_input }}'
  expire_after: 21600 # 6 hours 

but still get error :

Error: Testing configuration at /config
ERROR:homeassistant.util.yaml.loader:while parsing a block mapping
  in "/config/sensors.yaml", line 239, column 3
expected <block end>, but found '<scalar>'
  in "/config/sensors.yaml", line 244, column 36
Failed config
  General Errors:
    - Error loading /config/configuration.yaml: while parsing a block mapping
  in "/config/sensors.yaml", line 239, column 3
expected <block end>, but found '<scalar>'
  in "/config/sensors.yaml", line 244, column 36

Successful config (partial)

I also try with your way

{{ value_json['coretemp-isa-0000']['Package id 0']['temp1_input'] }}

and same error apear

The problem is that you are using single-quotes inside and outside the template. That’s invalid (and explains why it failed during the loading of the sensor configuration).

If you use single-quotes inside the template, use double-quotes outside the template.

  value_template: "{{ value_json['coretemp-isa-0000']['Package id 0']['temp1_input'] }}"

Thank you !!!

Just one remark, which you also help me from jsonpathfinder.
Correct is :

"{{ value_json['coretemp-isa-0000']['Package id 0'].temp1_input }}"

Yes, you can use a combination of bracket and dot notation. The only reason temp1_input can be accessed using dot notation is because it doesn’t contain any incompatible characters (and doesn’t start with a number). The other two contain hyphens/spaces so they must be referenced using bracket notation.