Parsing online weather info from VisualCrossing.com

My z-wave rain gauge needed new batteries last week. Upon replacing them I noticed that the electronics and battery connections were starting to rust. Although it is working fine with the new batteries, this motivivated me to find an online replacement for the rain gauge. My reasoning was that an online replacement reduces my need for batteries and its one less piece of equipment to maintain.

After searching around I found a weather service that offers historical data, rather than forecast data like most sites, visualcrossing.com. After creating a free account I played around with their online data viewing capabilities. One option was to display the api call needed to return the data I had manually requested. I used the api call in a rule that I set to run on a chron trigger, and it is working fine. I will be comparing its results with my rain gauge to determine accuracy, but first impression is good.

Here is the javascript for the rule:

const url = "https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/<yourlocation>/last24hours?unitGroup=metric&include=days&key=<yourAPIkey>&contentType=json";

try {
      // Fetch JSON data
    const response = actions.HTTP.sendHttpGetRequest(url, 10000);
    const json = JSON.parse(response);

    // Extract precipitation (example: today's precipitation)
    const precipitation = json?.days?.[0]?.precip ?? 0; // mm of rain

    // Update openHAB Item
    items.getItem("Rain_Accumulation_24hr").postUpdate(precipitation.toString());

    console.log(`Precipitation updated: ${precipitation} mm`);
  } catch (error) {
      console.error("Error fetching weather data:", error);
    };

Thanks for posting!

dIf this proves to be less accurate or you want to compare, the OpenWeatherMap binding will provide historical data. It’s free but you must provide a credit card to sign up.

I once tried to do the same as you with the NOAA weather service. But they make it a bit harder by breaking the measured precipitation up into separate variable length chunks (so much between 08:12 and 08:25, aother amount between 13:01 and 13:05, and so on). My goal was to do this without a rule and only use the HTTP binding, so I abandoned the project for now.

But that brings up the fact that you could replace this rule with the HTTP binding as well. It’s a straight forward JSONPATH transformation so it should work just fine.

Neither approach is better or worse, just mentioning options.

There is also VisualCrossing - Bindings | openHAB

I use openweathermap for weather forecasts, but from what I have read, and correct me if I’m wrong, the historical data requires a paid account.

I had a look at the visual crossing binding. It offers a long, long, looong list of channeled for current weather and forecast conditions, but nothing for historical data. The created thing was so big it really bogged down my system. This http call is quick and lightweight.

You may be right. I’ve not used it myself, just knew it was available.

It shouldn’t have done that. In general (though I can’t speak to this binding in particular) no processing is done for any Channel not linked to an Item. The number of Channels should have minimal impact on the system, unless they are all linked to an Item which, for Things like that, is often not expected.

I may have misinterpreted the symptoms. I slowed down my browser, and openHAB was not responding, but it could have just been the browser only.

I stand corrected. Openweathermap’s api does provide historical weather information in their free tier. It only offers specific days, which is not necessarily bad. VisualCrossing offers a running “past 24hr” dataset, which I find useful for rainfall accumulation.

OK. I guess the binding could use an update to support time series, so that history and forecasts could be published with timestamps rather than having a bunch of channels (per hour). Cc @magx2 in case this suggestion is of interest to you.

Hey, thanks for the ping.

Are the historical data for free?

It seems up to 1000 records per day are for free: The Easiest Weather API | Visual Crossing