Using the weather integration
Get current weather conditions for a location selected by the device user. Weather data is provided by WeatherAPI.com.
Contexts
Current conditions
Get current conditions by city (weather)
Gets the current conditions for a city.
{
"weather" : {
"city" : "Copenhagen"
}
}
{
"weather.response" : {
"location" : {
"tz_id" : "Europe/Copenhagen",
"lat" : 55.6761,
"name" : "Copenhagen",
"country" : "Denmark",
"localtime" : "2026-10-07 10:00",
"lon" : 12.5683
},
"current" : {
"temp_c" : 11.4,
"wind_kph" : 15.2,
"humidity" : 82,
"precip_mm" : 0.0,
"is_day" : 1,
"cloud" : 64,
"condition" : {
"code" : 1009,
"text" : "Overcast"
},
"last_updated" : "2026-10-07 10:00",
"feelslike_c" : 9.8,
"wind_degree" : 234
}
}
}
Get current conditions by GPS coordinates (weather)
Gets the current conditions for WGS-84 decimal coordinates. latitude must be
between -90 and 90; longitude must be between -180 and 180.
{
"weather" : {
"latitude" : 55.6761,
"longitude" : 12.5683
}
}
Coordinates are passed directly to WeatherAPI.com as latitude,longitude.
{
"weather.response" : {
"location" : {
"tz_id" : "Europe/Copenhagen",
"lat" : 55.6761,
"name" : "Copenhagen",
"country" : "Denmark",
"localtime" : "2026-10-07 10:00",
"lon" : 12.5683
},
"current" : {
"temp_c" : 11.4,
"wind_kph" : 15.2,
"humidity" : 82,
"precip_mm" : 0.0,
"is_day" : 1,
"cloud" : 64,
"condition" : {
"code" : 1009,
"text" : "Overcast"
},
"last_updated" : "2026-10-07 10:00",
"feelslike_c" : 9.8,
"wind_degree" : 234
}
}
}
Arduino example
The CurrentWeatherJson sketch sends a city request and prints values from the
WeatherAPI.com response. Configure its local offbeat_test_config.h before uploading.
void sendWeatherRequest(WebSocketsClient& socket) {
StaticJsonDocument<192> request;
request["weather"]["city"] = "Copenhagen";
String body;
serializeJson(request, body);
socket.sendTXT(body);
Serial.println("REQUEST_SENT=weather");
}
void handleWeatherResponse(uint8_t* payload, size_t length) {
StaticJsonDocument<2048> response;
DeserializationError error = deserializeJson(response, payload, length);
if (error) {
Serial.println("Unable to parse weather response");
return;
}
JsonObject weather = response["weather.response"];
if (weather.isNull()) {
Serial.println("No weather.response payload");
return;
}
Serial.print("Location: ");
Serial.println(weather["location"]["name"].as<const char*>());
Serial.print("Temperature C: ");
Serial.println(weather["current"]["temp_c"].as<float>());
Serial.print("Wind km/h: ");
Serial.println(weather["current"]["wind_kph"].as<float>());
Serial.print("WeatherAPI condition code: ");
Serial.println(weather["current"]["condition"]["code"].as<int>());
Serial.println("TEST:PASS");
}
Invalid or unavailable requests
Weather information is for general informational purposes only. Forecasts and conditions are probabilistic and may not be accurate for a specific location or time. Do not use this data as the sole basis for personal safety, aviation, marine navigation, emergency planning, or other safety-critical decisions; consult official meteorological services and relevant authorities.
No websocket response is sent for an invalid request, an unknown city, or a temporarily unavailable provider. A device should retain its last valid result and retry later. Server-side provider calls retry transient client failures up to three times.