Getting data from URL

I am trying to create a sensor that extracts data from a URL. I know this is JSON data, but dont quite get how to process it, can someone give me some advice on this, the URL is

https://api.melbournewater.com.au/rainfall-river-level/228357A/rain/live

and the data that it returns looks like

{
  "liveRainfallLevelsData" : [ {
    "dateTime" : "2020-10-22 23:18:00",
    "currentRainfallLevel" : 0.00,
    "cumulativeRainfallLevel" : 0.00
  }, {
    "dateTime" : "2020-10-22 23:12:00",
    "currentRainfallLevel" : 0.00,
    "cumulativeRainfallLevel" : 0.00
  }
(lots more of them)
 ]
}

I really just want the 3 pieces of data from the first one, which is the newest entry

Try like this:

sensor:
  - platform: rest
    resource: "https://api.melbournewater.com.au/rainfall-river-level/228357A/rain/live"
    name: Current Rainfall Level
    value_template: '{{ value_json.liveRainfallLevelsData[0].currentRainfallLevel }}'

Thanks, It creates the sensor, but it doesnt return any data image

Thereā€™s a typo in my post should be liveRainfallLevels not liveRainFallLevels, I corrected my post, please try again.

Yep that does it. I see how it works now, thanks again.

One last question, what would I add to get the timestamp as an attribute?

You could create a REST sensor that contains the three data points (current, cumulative, timestamp) instead of just the current level. And then extract them with a separate template sensor.

Sorry for crashing this thread hereā€¦
Iā€™m a absolute beginner with Home Assistant.
Could you give me some hints where to add this ā€œrest sensorā€.
I have a very similar case and like to read some data from a api url string (hope this description is correct) but my use case look very similar the the one explaned here in this threat.

I like to read all 6 variables from this url (like open, temp, etc).

Not sure if I have to use developer mode or to change any config file inside home assistant. Hope you could support me.
Thanks !
BR Matze

That post is 4 years old. It is better to start a new topic on what you want to do.

1 Like