How to get precipitation/UV index value from openweathermap api?

I need to get precipitation/UV index values from openweathermap api.

I managed to read data from one call 3 (https://openweathermap.org/api/one-call-3#example)

Problem is that in resulting data nothing like “precipitation” or “UV index” - but I see them in response description in link above.

and I asked at support-centre :

Retrieving data with one call 3 I wonder

  1. wich level of precipitation is considered as dangerous ? But actually I do not see “precipitation” key in “current” data I retrieve
  2. wich level of UV index(I suppose that “uvi” index in “current” data I retrieve) is considered as dangerous ?

And the answer of the bot :

The OpenWeather One Call API 3.0 does not directly specify which level of precipitation is
considered dangerous within the documentation provided. Since the “precipitation” key is not
explicitly mentioned in the “current” data section of the One Call API 3.0 documentation, it
might not be directly available or might be included under different conditions or parameters.
For assessing dangerous levels of precipitation, it typically depends on the context, such
as the rate of precipitation over time and the specific conditions of an area (e.g., prone
to flooding). It’s advisable to consult local weather advisories for specific thresholds of
dangerous precipitation levels.

Regarding the UV index (“uvi” in the “current” data), the UV Index scale recommended by
the World Health Organization is as follows:

Low: 0 to 2
Moderate: 3 to 5
High: 6 to 7
Very High: 8 to 10
Extreme: 11+
A UV index of 6 or above is generally considered “high” and can be dangerous, especially
without proper skin protection. Prolonged exposure during times when the UV index is 6
or higher can increase the risk of skin damage and other harmful effects. It’s recommended
to take protective measures such as wearing sunscreen, sunglasses, and protective clothing
when the UV index reaches high levels.

For more information on how to interpret the UV index and take appropriate
precautions, it’s advisable to refer to health or meteorological organizations’ guidelines.

For more detailed information and to access the full documentation, please visit: this link

With request I got next data :


stdClass Object
(
    [dt] => 1735127066
    [sunrise] => 1735113933
    [sunset] => 1735142145
    [temp] => 282.26
    [feels_like] => 280.26
    [pressure] => 1033
    [humidity] => 92
    [dew_point] => 281.03
    [uvi] => 0.58
    [clouds] => 100
    [visibility] => 10000
    [wind_speed] => 3.6
    [wind_deg] => 250
    [weather] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 804
                    [main] => Clouds
                    [description] => overcast clouds
                    [icon] => 04d
                )

        )

)

I have “uvi” key with value and no “precipitation”/“rain” keys. From the bot answer that is not clear in which cases these keys “precipitation”/“rain”
are in returned data.

I am trying to google “Weather 25 december high precipitation” - trying to find a city with high precipitation - but
no success yet.

A lot of links to my city : https://prnt.sc/1EdrQmCKHnNV

Any hints how to find a city with high precipitation in a world?
Then I would use in one call 3 request…

What request are you making? (hide your api key)

  1. That is openweathermap api (I provided a link to it in my topic) .
  2. I do not show my api key anywhere. Where did you see it ?

there are multiple example calls on that page, and you havent told us which one you used to get your result.

I made request :


        $s = 'https://api.openweathermap.org/data/3.0/onecall?lat=' . $lat . '&lon=' . $lng . '&exclude={part}&appid=' . $openWeatherMapKey . '&units=metric';

the bits that you told it to exclude… did you perhaps tell it to exclude the section of informatiin where the precipitation should be?

I did not exclude any data

your url says otherwise. what happens if you remove that parameter from the url.

1 Like

Poor for me, that I did not remove formal parameter from url string, but removing it nothing was changed.
Say today I got data :

 stdClass Object
(
    [dt] => 1735402336
    [sunrise] => 1735373168
    [sunset] => 1735401483
    [temp] => 4.66
    [feels_like] => 2.44
    [pressure] => 1027
    [humidity] => 95
    [dew_point] => 3.93
    [uvi] => 0
    [clouds] => 100
    [visibility] => 10000
    [wind_speed] => 2.57
    [wind_deg] => 260
    [weather] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 804
                    [main] => Clouds
                    [description] => overcast clouds
                    [icon] => 04n
                )
        )
)

so when i go to
https://api.openweathermap.org/data/3.0/onecall?lat=48.922778&lon=24.710556&appid=[MYAPIKEY]&units=metric
I get the full JSON.

What you seem to be seeing is the contents of the “current” element of the result.

How are you parsing this in PHP?

I use code :

        $s = 'https://api.openweathermap.org/data/3.0/onecall?lat=' . $lat . '&lon=' . $lng . '&appid=' . $openWeatherMapKey . '&units=metric';
        $response = Http::get($s);
        $data = json_decode($response->body());
        dd($data->current);

I check current subarray - it has no any precipitation key

Well yes, because if you look at the API, the precipitation isnt in the “current” key.

Because precipitation doesnt make sense as an instant-read value. Precipitation is a measure of volume over time. (Well strictly, of depth over time, but you get the point.)

Temperature is a momentary value. At a specific moment, temperature is a given value. UVI is a momentary value. Precipitation is not. You’ll need to look at the other data in the result depending on if you want information about the precipitation over the last minute, hour, or day.

1 Like