Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95468

Value template to extract JSON value

$
0
0

@sacofpotatoes wrote:

Hello,

I am trying to create a sensor which shows the level of a river with the REST integration and I cannot for the life of me figure out how to do it. Can someone point me in the right direction on how to do this? the sensor is as follows, and I just need help figuring out the value template.

sensor:
  - platform: rest
    resource: https://waterservices.usgs.gov/nwis/iv/?format=json&sites=02037500&parameterCd=00065&siteStatus=all
    value_template: '{{ value_json.values}}'
    name: River Level

and the JSON the link returns is as follows

tievalues{
  "name": "ns1:timeSeriesResponseType",
  "declaredType": "org.cuahsi.waterml.TimeSeriesResponseType",
  "scope": "javax.xml.bind.JAXBElement$GlobalScope",
  "value": {
    "queryInfo": {
      "queryURL": "http://waterservices.usgs.gov/nwis/iv/format=json&sites=02037500&parameterCd=00065&siteStatus=all",
      "criteria": {
        "locationParam": "[ALL:02037500]",
        "variableParam": "[00065]",
        "parameter": []
      },
      "note": [
        {
          "value": "[ALL:02037500]",
          "title": "filter:sites"
        },
        {
          "value": "[mode=LATEST, modifiedSince=null]",
          "title": "filter:timeRange"
        },
        {
          "value": "methodIds=[ALL]",
          "title": "filter:methodId"
        },
        {
          "value": "2020-04-16T18:13:05.081Z",
          "title": "requestDT"
        },
        {
          "value": "ead24380-800d-11ea-a6ce-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": "JAMES RIVER NEAR RICHMOND, VA",
          "siteCode": [
            {
              "value": "02037500",
              "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": 37.5632022,
              "longitude": -77.5469314
            },
            "localSiteXY": []
          },
          "note": [],
          "siteType": [],
          "siteProperty": [
            {
              "value": "ST",
              "name": "siteTypeCd"
            },
            {
              "value": "02080205",
              "name": "hucCd"
            },
            {
              "value": "51",
              "name": "stateCd"
            },
            {
              "value": "51087",
              "name": "countyCd"
            }
          ]
        },
        "variable": {
          "variableCode": [
            {
              "value": "00065",
              "network": "NWIS",
              "vocabulary": "NWIS:UnitValues",
              "variableID": 45807202,
              "default": true
            }
          ],
          "variableName": "Gage height, ft",
          "variableDescription": "Gage height, feet",
          "valueType": "Derived Value",
          "unit": {
            "unitCode": "ft"
          },
          "options": {
            "option": [
              {
                "name": "Statistic",
                "optionCode": "00000"
              }
            ]
          },
          "note": [],
          "noDataValue": -999999,
          "variableProperty": [],
          "oid": "45807202"
        },
        "values": [
          {
            "value": [
              {
                "value": "10.97",
                "qualifiers": [
                  "P"
                ],
                "dateTime": "2020-04-16T13:30:00.000-04:00"
              }
            ],
            "qualifier": [
              {
                "qualifierCode": "P",
                "qualifierDescription": "Provisional data subject to revision.",
                "qualifierID": 0,
                "network": "NWIS",
                "vocabulary": "uv_rmk_cd"
              }
            ],
            "qualityControlLevel": [],
            "method": [
              {
                "methodDescription": "",
                "methodID": 147078
              }
            ],
            "source": [],
            "offset": [],
            "sample": [],
            "censorCode": []
          }
        ],
        "name": "USGS:02037500:00065:00000"
      }
    ]
  },
  "nil": false,
  "globalScope": true,
  "typeSubstituted": false
}

I am just trying to extract the portion which says 10.97 but cannot for the life of me figure out the value template to do it.

Thanks!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 95468

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>