Get Lake Level from JSON object

I’m, pretty new, trying to extract data that shows the water level of a lake. It is available in JSON format, I’d like to get the most recent level as a sensor value. the JSON is a public endpoint at: https://waterservices.usgs.gov/nwis/dv/?format=json&sites=02187010

not sure where to start.

Step 1: Create a sensor. This would get all the value entries:

###
### USGS
###
- platform: rest
  name: USGS Water Level
  scan_interval: 3600
  unique_id: sensor.usgs_water_level
  resource: https://waterservices.usgs.gov/nwis/dv/?format=json&sites=02187010
  value_template: "{{ now() }}"
  json_attributes:
    - value

So now I have this:

But what do you want? just the water level of one lake? Or ? All the data is there but you may want to reach deeper if you only want a small piece of information.
You have not provided us with anything beyond that, so there is a sensor that has in attributes all the information.

If you only wanted the timeSeries, you would use:

###
### USGS
###
- platform: rest
  name: USGS Water Level
  scan_interval: 3600
  unique_id: sensor.usgs_water_level
  resource: https://waterservices.usgs.gov/nwis/dv/?format=json&sites=02187010
  value_template: "{{ now() }}"
  json_attributes_path: "$.value"
  json_attributes:
    - timeSeries

But if you are only looking for one number and not all the data for plotting graphs or something, then you can use the same method to pluck out what you want or a template sensor that gets that data from this sensor.

1 Like

All I really need is the one value for the mean water level, and probably/maybe a timestamp. i don’t need the historical values, HA will create that over time anyway if i want to make a chart of the values once i have a few days/weeks of daily readings on the sensor

so in my case I’d only need Elevations: 660.11 with the timestamp 2024-05-02T00:00:00.000

I’ve created sensors for both the options above, and see a TON of data and values. I don’t need anywhere near all of the what seems to be really repetitive data that JSON provides, as i said above, I’m only targeting the mean level and timestamp.

1 - how can I create an entity/template that just looks at the mean level value along with the timestamp on it? to display on a ashboard

2 - can I do something with the intial query to scope down 90% of the extra data it is returning?

Play with this in the template editor, and with reference to tools like JSON Viewer Online Best and Free

What a horribly convoluted data structure that is!

First line is the JSON response minified to a single line.
Second line pulls out the first elevation item.
Third and fourth lines get the data you want from that.

{% set value_json = {"name":"ns1:timeSeriesResponseType","declaredType":"org.cuahsi.waterml.TimeSeriesResponseType","scope":"javax.xml.bind.JAXBElement$GlobalScope","value":{"queryInfo":{"queryURL":"http://waterservices.usgs.gov/nwis/dv/format=json&sites=02187010","criteria":{"locationParam":"[ALL:02187010]","variableParam":"ALL","parameter":[]},"note":[{"value":"[ALL:02187010]","title":"filter:sites"},{"value":"[mode=LATEST, modifiedSince=null]","title":"filter:timeRange"},{"value":"methodIds=[ALL]","title":"filter:methodId"},{"value":"2024-05-03T14:13:34.149Z","title":"requestDT"},{"value":"539eb750-0957-11ef-9788-2cea7f58f5ca","title":"requestId"},{"value":"Provisional data are subject to revision. Go to http://waterdata.usgs.gov/nwis/help/?provisional for more information.","title":"disclaimer"},{"value":"vaas01","title":"server"}]},"timeSeries":[{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00021","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807074,"default":true}],"variableName":"Temperature, air, °F","variableDescription":"Temperature, air, degrees Fahrenheit","valueType":"Derived Value","unit":{"unitCode":"deg F"},"options":{"option":[{"value":"Maximum","name":"Statistic","optionCode":"00001"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807074"},"values":[{"value":[{"value":"80.9","qualifiers":["P"],"dateTime":"2024-05-01T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126700}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00021:00001"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00021","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807074,"default":true}],"variableName":"Temperature, air, °F","variableDescription":"Temperature, air, degrees Fahrenheit","valueType":"Derived Value","unit":{"unitCode":"deg F"},"options":{"option":[{"value":"Minimum","name":"Statistic","optionCode":"00002"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807074"},"values":[{"value":[{"value":"60.8","qualifiers":["P"],"dateTime":"2024-05-01T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126701}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00021:00002"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00021","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807074,"default":true}],"variableName":"Temperature, air, °F","variableDescription":"Temperature, air, degrees Fahrenheit","valueType":"Derived Value","unit":{"unitCode":"deg F"},"options":{"option":[{"value":"Mean","name":"Statistic","optionCode":"00003"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807074"},"values":[{"value":[{"value":"70.1","qualifiers":["P"],"dateTime":"2024-05-01T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126702}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00021:00003"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00035","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807109,"default":true}],"variableName":"Wind speed, mph","variableDescription":"Wind speed, miles per hour","valueType":"Derived Value","unit":{"unitCode":"mph"},"options":{"option":[{"value":"Maximum","name":"Statistic","optionCode":"00001"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807109"},"values":[{"value":[{"value":"8.1","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126704}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00035:00001"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00035","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807109,"default":true}],"variableName":"Wind speed, mph","variableDescription":"Wind speed, miles per hour","valueType":"Derived Value","unit":{"unitCode":"mph"},"options":{"option":[{"value":"Minimum","name":"Statistic","optionCode":"00002"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807109"},"values":[{"value":[{"value":"0.2","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126705}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00035:00002"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00035","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807109,"default":true}],"variableName":"Wind speed, mph","variableDescription":"Wind speed, miles per hour","valueType":"Derived Value","unit":{"unitCode":"mph"},"options":{"option":[{"value":"Mean","name":"Statistic","optionCode":"00003"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807109"},"values":[{"value":[{"value":"2.7","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126706}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00035:00003"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00036","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807110,"default":true}],"variableName":"Wind direction, degrees clockwise from north","variableDescription":"Wind direction, degrees clockwise from true north","valueType":"Derived Value","unit":{"unitCode":"Deg"},"options":{"option":[{"value":"Maximum","name":"Statistic","optionCode":"00001"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807110"},"values":[{"value":[{"value":"356","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126707}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00036:00001"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00036","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807110,"default":true}],"variableName":"Wind direction, degrees clockwise from north","variableDescription":"Wind direction, degrees clockwise from true north","valueType":"Derived Value","unit":{"unitCode":"Deg"},"options":{"option":[{"value":"Minimum","name":"Statistic","optionCode":"00002"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807110"},"values":[{"value":[{"value":"0","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126708}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00036:00002"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00036","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807110,"default":true}],"variableName":"Wind direction, degrees clockwise from north","variableDescription":"Wind direction, degrees clockwise from true north","valueType":"Derived Value","unit":{"unitCode":"Deg"},"options":{"option":[{"value":"Mean","name":"Statistic","optionCode":"00003"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807110"},"values":[{"value":[{"value":"173","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126709}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00036:00003"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00045","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807140,"default":true}],"variableName":"Precipitation, total, in","variableDescription":"Precipitation, total, inches","valueType":"Derived Value","unit":{"unitCode":"in"},"options":{"option":[{"value":"Sum","name":"Statistic","optionCode":"00006"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807140"},"values":[{"value":[{"value":"0.00","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126703}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00045:00006"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00052","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807168,"default":true}],"variableName":"Relative humidity, percent","variableDescription":"Relative humidity, percent","valueType":"Derived Value","unit":{"unitCode":"%"},"options":{"option":[{"value":"Maximum","name":"Statistic","optionCode":"00001"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807168"},"values":[{"value":[{"value":"96.1","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126697}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00052:00001"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00052","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807168,"default":true}],"variableName":"Relative humidity, percent","variableDescription":"Relative humidity, percent","valueType":"Derived Value","unit":{"unitCode":"%"},"options":{"option":[{"value":"Minimum","name":"Statistic","optionCode":"00002"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807168"},"values":[{"value":[{"value":"33.5","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126698}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00052:00002"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00052","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807168,"default":true}],"variableName":"Relative humidity, percent","variableDescription":"Relative humidity, percent","valueType":"Derived Value","unit":{"unitCode":"%"},"options":{"option":[{"value":"Mean","name":"Statistic","optionCode":"00003"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807168"},"values":[{"value":[{"value":"69.4","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126699}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00052:00003"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00062","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807199,"default":true}],"variableName":"Elevation of reservoir water surface above datum, ft","variableDescription":"Elevation of reservoir water surface above datum, feet","valueType":"Derived Value","unit":{"unitCode":"ft"},"options":{"option":[{"value":"Maximum","name":"Statistic","optionCode":"00001"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807199"},"values":[{"value":[{"value":"660.15","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126710}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00062:00001"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00062","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807199,"default":true}],"variableName":"Elevation of reservoir water surface above datum, ft","variableDescription":"Elevation of reservoir water surface above datum, feet","valueType":"Derived Value","unit":{"unitCode":"ft"},"options":{"option":[{"value":"Minimum","name":"Statistic","optionCode":"00002"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807199"},"values":[{"value":[{"value":"660.05","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126711}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00062:00002"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"00062","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":45807199,"default":true}],"variableName":"Elevation of reservoir water surface above datum, ft","variableDescription":"Elevation of reservoir water surface above datum, feet","valueType":"Derived Value","unit":{"unitCode":"ft"},"options":{"option":[{"value":"Mean","name":"Statistic","optionCode":"00003"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"45807199"},"values":[{"value":[{"value":"660.11","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126712}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:00062:00003"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"62608","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":51413493,"default":true}],"variableName":"Total solar radiation (direct + diffuse radiation on a horizontal surface), watts/m²","variableDescription":"Total solar radiation (direct + diffuse radiation on a horizontal surface), watts per square meter","valueType":"Derived Value","unit":{"unitCode":"W/m2"},"options":{"option":[{"value":"Maximum","name":"Statistic","optionCode":"00001"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"51413493"},"values":[{"value":[{"value":"761","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126713}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:62608:00001"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"62608","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":51413493,"default":true}],"variableName":"Total solar radiation (direct + diffuse radiation on a horizontal surface), watts/m²","variableDescription":"Total solar radiation (direct + diffuse radiation on a horizontal surface), watts per square meter","valueType":"Derived Value","unit":{"unitCode":"W/m2"},"options":{"option":[{"value":"Minimum","name":"Statistic","optionCode":"00002"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"51413493"},"values":[{"value":[{"value":"10","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126714}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:62608:00002"},{"sourceInfo":{"siteName":"HARTWELL LAKE NEAR ANDERSON, SC","siteCode":[{"value":"02187010","network":"NWIS","agencyCode":"USGS"}],"timeZoneInfo":{"defaultTimeZone":{"zoneOffset":"-05:00","zoneAbbreviation":"EST"},"daylightSavingsTimeZone":{"zoneOffset":"-04:00","zoneAbbreviation":"EDT"},"siteUsesDaylightSavingsTime":true},"geoLocation":{"geogLocation":{"srs":"EPSG:4326","latitude":34.5083333,"longitude":-82.8552778},"localSiteXY":[]},"note":[],"siteType":[],"siteProperty":[{"value":"LK","name":"siteTypeCd"},{"value":"03060103","name":"hucCd"},{"value":"45","name":"stateCd"},{"value":"45007","name":"countyCd"}]},"variable":{"variableCode":[{"value":"62608","network":"NWIS","vocabulary":"NWIS:UnitValues","variableID":51413493,"default":true}],"variableName":"Total solar radiation (direct + diffuse radiation on a horizontal surface), watts/m²","variableDescription":"Total solar radiation (direct + diffuse radiation on a horizontal surface), watts per square meter","valueType":"Derived Value","unit":{"unitCode":"W/m2"},"options":{"option":[{"value":"Mean","name":"Statistic","optionCode":"00003"}]},"note":[],"noDataValue":-999999,"variableProperty":[],"oid":"51413493"},"values":[{"value":[{"value":"207","qualifiers":["P"],"dateTime":"2024-05-02T00:00:00.000"}],"qualifier":[{"qualifierCode":"P","qualifierDescription":"Provisional data subject to revision.","qualifierID":0,"network":"NWIS","vocabulary":"uv_rmk_cd"}],"qualityControlLevel":[],"method":[{"methodDescription":"","methodID":126715}],"source":[],"offset":[],"sample":[],"censorCode":[]}],"name":"USGS:02187010:62608:00003"}]},"nil":false,"globalScope":true,"typeSubstituted":false} %}
{% set i = value_json['value']['timeSeries']|selectattr('variable.variableDescription','contains','Elevation')|list|first %}
Timestamp: {{ i['values'][0]['value'][0]['dateTime'] }}
Elevation: {{ i['values'][0]['value'][0]['value'] }}

So you could do this for the elevation sensor:

value_template: >
  {% set i = value_json['value']['timeSeries']|selectattr('variable.variableDescription','contains','Elevation')|list|first %}
  {{ i['values'][0]['value'][0]['value'] }}

Better still, use the RESTful integration to get both from a single call, discarding everything else:

rest:
  - scan_interval: 3600
    resource: https://waterservices.usgs.gov/nwis/dv/?format=json&sites=02187010
    sensor:
      - name: "Lake elevation"
        value_template: >
          {% set i = value_json['value']['timeSeries']|selectattr('variable.variableDescription','contains','Elevation')|list|first %}
          {{ i['values'][0]['value'][0]['value'] }}
        unit_of_measurement: 'ft'
      - name: "Lake elevation timestamp"
        value_template: >
          {% set i = value_json['value']['timeSeries']|selectattr('variable.variableDescription','contains','Elevation')|list|first %}
          {{ i['values'][0]['value'][0]['dateTime'] }}

Heh. I’m getting quite good at this:

1 Like

Urgh, it’s even more complex than I thought: there are Maximum, Minimum and Mean values.

If you want the Mean, use:

{% set i = value_json['value']['timeSeries']
           |selectattr('variable.variableDescription','contains','Elevation')
           |selectattr('variable.options.option.0.value','==','Mean')
           |list|first %}

as the first line of both value_templates above.

I was just about to reply, not to be a stickler but… and then you beat me to it. retesting - please hold.

1 Like

That was it exactly! thank you guys so much for the help! i would have never been able to parse that data myself.

1 Like

Alright, one final question. Now that this has been working for a few days, i can see historical data in the graph if I browse, it but when i try and add it to Statistics Graph Card i have in my dashboard it doesn’t give me data. Any ideas?