Create graph/automation based on river level

Here is an alternative that may prove better depending on your use. NOAA also provides raw CSV with just the graphical data for the chart. Using a command_line sensor and jq, you can process that to a more simplistic structure. Here is my example as of now. I am going to strip some characters out ("\r") and add names to the fields to make it easier to graph the data.

NOTE: This is a simplistic approach and could fail if the CSV data has quotes in it or something like that. I believe it works in many/most all NOAA cases though.

##
## water.weather.gov CSV
##
- platform: command_line
  scan_interval: 3600
  name: Russian River CSV
  command: "curl -s 'https://www.cnrfc.noaa.gov/graphicalRVF_csv.php?id=GUEC1' | jq --raw-input '{data: [inputs | split(\",\") | {datapoint: [.]} ]| .[2:999] }'"
  value_template: "{{ now() }}"
  json_attributes:
    - data

This using the NOAA CSV now to process it to JSON using ‘jq’ which should be in your installation. This sensor yields this:

You can download the original CSV from their website. For the sensor I excluded the the first line as it has the headers.

And now updated. This adds field names and converts the level to a number for charting purposes.

##
## water.weather.gov CSV
##
- platform: command_line
  scan_interval: 3600
  name: Russian River CSV
  command: "curl -s 'https://www.cnrfc.noaa.gov/graphicalRVF_csv.php?id=GUEC1' | jq --raw-input '{data: [inputs | split(\",\") | {datapoint: [ {issued: .[0], valid: .[1], level: .[2]  | tonumber, trend: .[3], status: .[4], mode: .[5] | gsub(\"[\\r]\"; \"\") } ]} ]| .[2:999] }'"
  value_template: "{{ now() }}"
  json_attributes:
    - data

With this, one would get this output with field names and no return characters:

That sensor contains all the data to be able to draw this:

Looking through that data, I see this:

  - datapoint:
      - issued: 01/11/2023 08:27 AM
        valid: 01/12/2023 08 AM
        level: 31.6
        trend: +
        status: Above Monitor
        mode: Forecast
  - datapoint:
      - issued: 01/11/2023 08:27 AM
        valid: 01/12/2023 09 AM
        level: 31.9
        trend: +
        status: Above Monitor
        mode: Forecast
  - datapoint:
      - issued: 01/11/2023 08:27 AM
        valid: 01/12/2023 10 AM
        level: 32.1
        trend: +
        status: Above Flood
        mode: Forecast
  - datapoint:
      - issued: 01/11/2023 08:27 AM
        valid: 01/12/2023 11 AM
        level: 32.3
        trend: +
        status: Above Flood
        mode: Forecast
  - datapoint:
      - issued: 01/11/2023 08:27 AM
        valid: 01/12/2023 12 PM
        level: 32.4
        trend: +
        status: Above Flood
        mode: Forecast

So at 1/12/2023 at 10:00am Pacific, my river is forecasted to hit flood.

Hopefully @Glitchen with the above you have all you need. Someone could really turn this into standard sensor as the URLs are known (like mine is GUEC1). That would be the only variable.

Another update:

In order to make this easy, I have gone this route for the data. This makes it much easier for charting and flex-table. This is just a slight change to flatten the JSON generated from the CSV.

##
## water.weather.gov CSV
##
- platform: command_line
  scan_interval: 3600
  name: Russian River Flood Data
  command: "curl -s 'https://www.cnrfc.noaa.gov/graphicalRVF_csv.php?id=GUEC1' | jq --raw-input '{flooddata: [inputs | split(\",\") | {issued: .[0], valid: .[1], level: .[2] | tonumber, trend: .[3], status: .[4], mode: .[5] | gsub(\"[\\r]\"; \"\")  }]| .[2:999] }'"
  value_template: "{{ now() }}"
  json_attributes:
    - flooddata
2 Likes