Create graph/automation based on river level

Can you send me the exact sensor code please? Alos in the above example can you tell me the two values you would want (latest value and time) … it is likely the first or last entry I would assume.

I’d rather not share my location so let’s pretend I’m using the Russian River gage URL like in your example above:

##
## water.weather.gov
## 
- platform: rest
  name: Creek Level
  scan_interval: 600
  resource: 
https://water.weather.gov/ahps2/hydrograph_to_xml.php?gage=guec1&output=xml
  value_template: "{{ now() }}"
  json_attributes_path: site
  json_attributes:
    - observed

Yes, in the example above I’m trying to pull the first (most recent) reported value of 1.60ft and have it shown as a sensor reading at the reported datetime (2023-04-19T23:20:00-00:00 UTC).

Thanks!

You could just create a template sensor that reads just the first values into attributes like this (of course use your own sensor name here):

###
### Test for chezzo
###
  - name: Flood Values
    unique_id: sensor.flood_values
    state: "{{ states('sensor.russian_river_level') }}"
    attributes:
        dtstamp: "{{ state_attr('sensor.russian_river_level','observed').datum[1].valid['#text'] }}"
        level: "{{ state_attr('sensor.russian_river_level','observed').datum[1].primary['#text'] }}"

So this would change whenever you main sensor changes and it has just the datetime and the observed value of the first entry. For graphical purposes I would stick to just having the number (1.60) and not combine with 'ft". You can always set units elsewhere in graph and I doubt they will change reporting from ‘ft’ to ‘in’.

1 Like

I’m looking to get the current reading only. For example, it is currently 24.14M

https://wateroffice.ec.gc.ca/report/real_time_e.html?stn=02OA107

Awesome, thank you! I’ve made a couple of tweaks, including adding the unit directly to the sensor. This is now working perfectly:

- sensor:
  - name: Flood Values
    unique_id: sensor.flood_values
    state: "{{ state_attr('sensor.russian_river_level','observed').datum[1].primary['#text'] }}"
    unit_of_measurement: "ft"
    attributes:
        dtstamp: "{{ state_attr('sensor.russian_river_level','observed').datum[1].valid['#text'] }}"

I had thought about trying to reflect the datetime from the XML as the “last updated” value for the sensor. But on reflection having it as an attribute works just as well and I assume is easier to implement.

I wanted to give my solution. I just wanted to see the current level of the river. Just change the gage identifier in the url and it will give the current level

sensor:
  - platform: rest
    name: Willamette Level
    scan_interval: 600
    resource: https://water.weather.gov/ahps2/hydrograph_to_xml.php?gage=prto3&output=xml
    value_template: "{{ value_json.site.observed.datum[0].primary['#text'] }}"
1 Like