I’m trying to create a REST sensor to pull data about the river conditions near my home.
The URL I’m using is http://waterservices.usgs.gov/nwis/iv/?sites=13206305¶meterCd=00060&format=json
The data returned by that GET request is in the following format:
{
"name": "ns1:timeSeriesResponseType",
"declaredType": "org.cuahsi.waterml.TimeSeriesResponseType",
"scope": "javax.xml.bind.JAXBElement$GlobalScope",
"value": {
"queryInfo": {
"queryURL": "http://waterservices.usgs.gov/nwis/iv/sites=13206305¶meterCd=00060&format=json",
"criteria": {
"locationParam": "[ALL:13206305]",
"variableParam": "[00060]",
"parameter": []
},
"note": [{
"value": "[ALL:13206305]",
"title": "filter:sites"
}, {
"value": "[mode=LATEST, modifiedSince=null]",
"title": "filter:timeRange"
}, {
"value": "methodIds=[ALL]",
"title": "filter:methodId"
}, {
"value": "2016-12-03T07:00:13.669Z",
"title": "requestDT"
}, {
"value": "237d2a40-b926-11e6-a4b5-6cae8b6642f6",
"title": "requestId"
}, {
"value": "Provisional data are subject to revision. Go to http://waterdata.usgs.gov/nwis/help/?provisional for more information.",
"title": "disclaimer"
}, {
"value": "caas01",
"title": "server"
}]
},
"timeSeries": [{
"sourceInfo": {
"siteName": "BOISE RIVER SOUTH CHANNEL AT EAGLE ID",
"siteCode": [{
"value": "13206305",
"network": "NWIS",
"agencyCode": "USGS"
}],
"timeZoneInfo": {
"defaultTimeZone": {
"zoneOffset": "-07:00",
"zoneAbbreviation": "MST"
},
"daylightSavingsTimeZone": {
"zoneOffset": "-06:00",
"zoneAbbreviation": "MDT"
},
"siteUsesDaylightSavingsTime": true
},
"geoLocation": {
"geogLocation": {
"srs": "EPSG:4326",
"latitude": 43.67527778,
"longitude": -116.353611
},
"localSiteXY": []
},
"note": [],
"siteType": [],
"siteProperty": [{
"value": "ST",
"name": "siteTypeCd"
}, {
"value": "17050114",
"name": "hucCd"
}, {
"value": "16",
"name": "stateCd"
}, {
"value": "16001",
"name": "countyCd"
}]
},
"variable": {
"variableCode": [{
"value": "00060",
"network": "NWIS",
"vocabulary": "NWIS:UnitValues",
"variableID": 45807197,
"default": true
}],
"variableName": "Streamflow, ft³/s",
"variableDescription": "Discharge, cubic feet per second",
"valueType": "Derived Value",
"unit": {
"unitCode": "ft3/s"
},
"options": {
"option": [{
"name": "Statistic",
"optionCode": "00000"
}]
},
"note": [],
"noDataValue": -999999.0,
"variableProperty": [],
"oid": "45807197"
},
"values": [{
"value": [{
"value": "204",
"qualifiers": ["P"],
"dateTime": "2016-12-02T23:30:00.000-07:00"
}],
"qualifier": [{
"qualifierCode": "P",
"qualifierDescription": "Provisional data subject to revision.",
"qualifierID": 0,
"network": "NWIS",
"vocabulary": "uv_rmk_cd"
}],
"qualityControlLevel": [],
"method": [{
"methodDescription": "",
"methodID": 47585
}],
"source": [],
"offset": [],
"sample": [],
"censorCode": []
}],
"name": "USGS:13206305:00060:00000"
}]
},
"nil": false,
"globalScope": true,
"typeSubstituted": false
}
I’m trying to get the value of 204 extracted out.
My sensor looks like this:
sensor river:
- platform: rest
name: River Flow
resource: http://waterservices.usgs.gov/nwis/iv/? sites=13206305¶meterCd=00060&format=json
value_template: '{{ value_json.value.timeSeries.[0].values.[0].value.[0].value }}'
unit_of_measurement: "CFS"
I can’t see an error with it, but it spits this out in the home-assistant.log file:
homeassistant.bootstrap: Invalid config for [sensor.rest]: invalid template (TemplateSyntaxError: expected name or number) for dictionary value @ data[‘value_template’]. Got ‘{{ value_json.value.timeSeries.[0].values.[0].value.[0].value }}’. (See ?:?). Please check the docs at https://home-assistant.io/components/sensor.rest/
Can anyone help me understand what I’ve got incorrect?