Splitting JSON file for sensor

Hello! I’m trying to split this json file to create multiple sensors:

Specifically, ambientTemperatureCelsius, heatCelsius, ambientHumidityPercent


  {  
    "traits": {
      "sdm.devices.traits.Info": {
        "customName": "Nest"
      },
      "sdm.devices.traits.Humidity": {
        "ambientHumidityPercent": 50
      },
      "sdm.devices.traits.Connectivity": {
        "status": "ONLINE"
      },
      "sdm.devices.traits.Fan": {},
      "sdm.devices.traits.ThermostatMode": {
        "mode": "HEAT",
        "availableModes": [
          "HEAT",
          "OFF"
        ]
      },
      "sdm.devices.traits.ThermostatEco": {
        "availableModes": [
          "OFF",
          "MANUAL_ECO"
        ],
        "mode": "OFF",
        "heatCelsius": 16.43044,
        "coolCelsius": 24.44443
      },
      "sdm.devices.traits.ThermostatHvac": {
        "status": "OFF"
      },
      "sdm.devices.traits.Settings": {
        "temperatureScale": "CELSIUS"
      },
      "sdm.devices.traits.ThermostatTemperatureSetpoint": {
        "heatCelsius": 18.95204
      },
      "sdm.devices.traits.Temperature": {
        "ambientTemperatureCelsius": 20.75
      }
    },
  }

what integration are you getting this information from?

I’m looking into the device access console from Google for their nest products

yes but how are you reading this JSON? Is it located at a URL, is it a file on your local drive?

At this URL: resource: https://smartdevicemanagement.googleapis.com/

I’m trying to create a sensor with the rest platform using the get method, this does work, but I’m trying to get multiple attributes with one call!

Thanks:)

  - platform: rest
    name: nest_thermostat
    resource: https://smartdevicemanagement.googleapis.com/XXX
    method: GET
    headers:
      Content-Type: application/json
      Authorization: !secret my_sensor_secret_token
    value_template: "{{ value_json['traits']['sdm.devices.traits.Temperature']['ambientTemperatureCelsius'] }}"

Place the entire json in as an attribute:

  - platform: rest
    name: nest_thermostat
    resource: https://smartdevicemanagement.googleapis.com/XXX
    method: GET
    headers:
      Content-Type: application/json
      Authorization: !secret my_sensor_secret_token
    value_template: "{{ value_json['traits']['sdm.devices.traits.Temperature']['ambientTemperatureCelsius'] }}"
    json_attributes:
    - traits

Then make a template sensor for each piece of info that you want as a separate sensor. Here’s an example one:

  - platform: template
    sensors:
      nest_thermostat_temp:
        value_template: >
          {% set traits = states_attr('sensor.nest_thermostat', 'traits') %}
          {{ traits['sdm.devices.traits.Temperature']['ambientTemperatureCelsius'] }}

Looking better already! This is from the developer tool when I look at the sensor.

What would be the best way to strip out the unnecessary information

traits: 
sdm.devices.traits.Info:
  customName: Nest
sdm.devices.traits.Humidity:
  ambientHumidityPercent: 46
sdm.devices.traits.Connectivity:
  status: ONLINE
sdm.devices.traits.Fan: {}
sdm.devices.traits.ThermostatMode:
  mode: HEAT
  availableModes:
    - HEAT
    - 'OFF'
sdm.devices.traits.ThermostatEco:
  availableModes:
    - 'OFF'
    - MANUAL_ECO
  mode: 'OFF'
  heatCelsius: 16.43044
  coolCelsius: 24.44443
sdm.devices.traits.ThermostatHvac:
  status: 'OFF'
sdm.devices.traits.Settings:
  temperatureScale: CELSIUS
sdm.devices.traits.ThermostatTemperatureSetpoint:
  heatCelsius: 16.00467
sdm.devices.traits.Temperature:
  ambientTemperatureCelsius: 20.71999

friendly_name: nest_thermostat

Something like this

  customName: Nest
  ambientHumidityPercent: 46
  status: ONLINE
  mode: HEAT
  temperatureScale: CELSIUS
  heatCelsius: 16.00467
  ambientTemperatureCelsius: 20.71999