Rest sensor json_attributes_path doesn't support template values

I would like to be able to select dynamically what part of the json result is included as attributes. Currently json_attributes_path has to be hard coded. For example in this YAML snippet which returns air quality values from a specific station id STA-IS0037A:

sensor:
  platform: rest
  name: air_quality
  resource: https://api.ust.is/aq/a/getLatest
  json_attributes_path: "$.STA-IS0037A.parameters"
  json_attributes:
    - H2S
    - "NO"
    - NO2
    - PM1
    - PM10
    - PM2.5
    - SO2
  value_template: "{{value_json['STA-IS0037A'].name}}"
  scan_interval: 3600

What I would really like to do would be to use an input_text or input_select to select dynamically the station id and what part of the json to include like this:

json_attributes_path: “$.{{ states(‘input_select.air_station_id’) }}.parameters”

Not entirely what you were looking for, but you can use JSON Path Expressions to at least select a specific part of the JSON for the attributes - for example, I use:

json_attributes_path: $…mobileDevices[?(@.id==74527239)]

Which basically selects a part of the JSON (from a TADO API call) based on the mobile device ID (which I’ve randomized here).

1 Like