Is there some limitation in in HA when using json_attributes_path because I can’t get array saved into attributes even doe it works on http://jsonpath.com.
JSON
{
"location": {
"name": "Samobor",
"region": "Grad Zagreb",
"country": "Croatia",
"lat": 45.8,
"lon": 15.72,
"tz_id": "Europe/Zagreb",
"localtime_epoch": 1679912365,
"localtime": "2023-03-27 12:19"
},
"current": {
"last_updated_epoch": 1679912100,
"last_updated": "2023-03-27 12:15",
"temp_c": 9.0,
"temp_f": 48.2,
"is_day": 1,
"condition": {
"text": "Partly cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/day/116.png",
"code": 1003
},
"wind_mph": 9.4,
"wind_kph": 15.1,
"wind_degree": 260,
"wind_dir": "W",
"pressure_mb": 1004.0,
"pressure_in": 29.65,
"precip_mm": 0.3,
"precip_in": 0.01,
"humidity": 76,
"cloud": 75,
"feelslike_c": 7.9,
"feelslike_f": 46.1,
"vis_km": 10.0,
"vis_miles": 6.0,
"uv": 2.0,
"gust_mph": 5.6,
"gust_kph": 9.0,
"air_quality": {
"co": 240.3000030517578,
"no2": 3.700000047683716,
"o3": 85.0999984741211,
"so2": 1.0,
"pm2_5": 1.600000023841858,
"pm10": 2.5,
"us-epa-index": 1,
"gb-defra-index": 1
}
},
"forecast": {
"forecastday": [
{
"date": "2023-03-27",
"date_epoch": 1679875200,
"day": {
"maxtemp_c": 11.4,
"maxtemp_f": 52.5,
"mintemp_c": 5.2,
"mintemp_f": 41.4,
"avgtemp_c": 7.8,
"avgtemp_f": 46.0,
"maxwind_mph": 14.1,
"maxwind_kph": 22.7,
"totalprecip_mm": 52.2,
"totalprecip_in": 2.06,
"totalsnow_cm": 0.0,
"avgvis_km": 7.4,
"avgvis_miles": 4.0,
"avghumidity": 72.0,
"daily_will_it_rain": 1,
"daily_chance_of_rain": 89,
"daily_will_it_snow": 0,
"daily_chance_of_snow": 0,
"condition": {
"text": "Heavy rain",
"icon": "//cdn.weatherapi.com/weather/64x64/day/308.png",
"code": 1195
},
"uv": 2.0,
"air_quality": {
"co": 276.5040014648437,
"no2": 7.775999946594238,
"o3": 73.63599975585937,
"so2": 0.6160000064969062,
"pm2_5": 2.9479999852180483,
"pm10": 4.3599999904632565,
"us-epa-index": 1,
"gb-defra-index": 1
}
},
"astro": {
"sunrise": "06:46 AM",
"sunset": "07:17 PM",
"moonrise": "09:36 AM",
"moonset": "01:15 AM",
"moon_phase": "Waxing Crescent",
"moon_illumination": "30",
"is_moon_up": 0,
"is_sun_up": 0
}
},
{
"date": "2023-03-28",
"date_epoch": 1679961600,
"day": {
"maxtemp_c": 11.1,
"maxtemp_f": 52.0,
"mintemp_c": 2.6,
"mintemp_f": 36.7,
"avgtemp_c": 6.6,
"avgtemp_f": 43.9,
"maxwind_mph": 11.2,
"maxwind_kph": 18.0,
"totalprecip_mm": 0.0,
"totalprecip_in": 0.0,
"totalsnow_cm": 0.0,
"avgvis_km": 10.0,
"avgvis_miles": 6.0,
"avghumidity": 46.0,
"daily_will_it_rain": 0,
"daily_chance_of_rain": 0,
"daily_will_it_snow": 0,
"daily_chance_of_snow": 0,
"condition": {
"text": "Sunny",
"icon": "//cdn.weatherapi.com/weather/64x64/day/113.png",
"code": 1000
},
"uv": 3.0,
"air_quality": {
"co": 426.1880010986328,
"no2": 23.51599998474121,
"o3": 44.03199970066547,
"so2": 0.576000000834465,
"pm2_5": 11.303999965190888,
"pm10": 15.640000002384186,
"us-epa-index": 1,
"gb-defra-index": 1
}
},
"astro": {
"sunrise": "06:44 AM",
"sunset": "07:19 PM",
"moonrise": "10:19 AM",
"moonset": "02:20 AM",
"moon_phase": "Waxing Crescent",
"moon_illumination": "39",
"is_moon_up": 1,
"is_sun_up": 0
}
},
{
"date": "2023-03-29",
"date_epoch": 1680048000,
"day": {
"maxtemp_c": 13.4,
"maxtemp_f": 56.1,
"mintemp_c": 1.9,
"mintemp_f": 35.4,
"avgtemp_c": 7.6,
"avgtemp_f": 45.8,
"maxwind_mph": 11.0,
"maxwind_kph": 17.6,
"totalprecip_mm": 0.0,
"totalprecip_in": 0.0,
"totalsnow_cm": 0.0,
"avgvis_km": 10.0,
"avgvis_miles": 6.0,
"avghumidity": 58.0,
"daily_will_it_rain": 0,
"daily_chance_of_rain": 0,
"daily_will_it_snow": 0,
"daily_chance_of_snow": 0,
"condition": {
"text": "Partly cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/day/116.png",
"code": 1003
},
"uv": 3.0,
"air_quality": {
"co": 321.37199829101564,
"no2": 11.343999919891358,
"o3": 66.14799993515015,
"so2": 0.300000008046627,
"pm2_5": 9.58399995803833,
"pm10": 12.631999950408936,
"us-epa-index": 1,
"gb-defra-index": 1
}
},
"astro": {
"sunrise": "06:43 AM",
"sunset": "07:20 PM",
"moonrise": "11:12 AM",
"moonset": "03:16 AM",
"moon_phase": "First Quarter",
"moon_illumination": "49",
"is_moon_up": 1,
"is_sun_up": 0
}
}
]
}
}
Wanted output:
[
{
"co": 276.5040014648437,
"no2": 7.775999946594238,
"o3": 73.63599975585937,
"so2": 0.6160000064969062,
"pm2_5": 2.9479999852180483,
"pm10": 4.3599999904632565,
"us-epa-index": 1,
"gb-defra-index": 1
},
{
"co": 426.1880010986328,
"no2": 23.51599998474121,
"o3": 44.03199970066547,
"so2": 0.576000000834465,
"pm2_5": 11.303999965190888,
"pm10": 15.640000002384186,
"us-epa-index": 1,
"gb-defra-index": 1
},
{
"co": 321.37199829101564,
"no2": 11.343999919891358,
"o3": 66.14799993515015,
"so2": 0.300000008046627,
"pm2_5": 9.58399995803833,
"pm10": 12.631999950408936,
"us-epa-index": 1,
"gb-defra-index": 1
}
]
HA code:
- resource_template: >
{% set api_key = "removed" %}
{% set location = "removed" %}
https://api.weatherapi.com/v1/forecast.json?key={{ api_key }}&q={{ location }}&days=3&aqi=yes&alerts=no
scan_interval: "00:30:00"
sensor:
- unique_id: air_quality_index_forecast
name: Air Quality Index Forecast
value_template: >
{{ value_json['forecast']['forecastday'][0]['day']['air_quality']['gb-defra-index'] }}
state_class: measurement
device_class: aqi
json_attributes_path: "$.forecast.forecastday.*.day"
json_attributes:
- air_quality
HA state:
So instead having array of 3 sets of attributes I only get 1.