|
Post by papa on Feb 16, 2019 15:51:46 GMT
Introduction
This thread continues how I'm moving to more current versions of OpenHAB 2 & its bindings, previously documented in this thread & this one & this one.
For our DIY Home Automation, weather data is useful. It gives us insight about the context of our homes & life activities. It can be very useful for projects like my automation of garden irrigation.
Until recently I've used the 1.xx Weather binding with data from Weather Underground. As I wrote elsewhere: "Sounds like the Weather Underground service will soon not be available, at least on a cheap basis. Other weather bindings & services are available." OpenWeatherMap is weather data service with a nice free package AND OpenHAB offers a 2.xx OpenWeatherMap Binding. OpenWeatherMap offers most of the data types I was using before from Weather Underground & I could create some of the missing data types by calculating from what was available. In this thread, I will document some of my experience with using the OpenWeatherMap service & binding. I will follow my current approach which works well, if tediously, & I look forward to PaperUI Next Generation which is promoted as improving the experience: I will use PaperUI to install/configure bindings, Things, & Channels. I will use text config files for items, rules, & sitemaps. BTW this seems the approach currently recommended by OpenHAB's official documentation.
Continues
|
|
|
Post by papa on Feb 16, 2019 15:58:01 GMT
|
|
|
Post by papa on Feb 16, 2019 17:48:44 GMT
Install the OpenWeatherMap Binding Configure the Related OpenWeatherMap Account Thing
Go to PaperUI\Addons\Binding\OpenWeatherMap Click Install In your browser refresh PaperUI\Addons\Binding This will eventually generate Two Things: 1) OpenWeatherMap Account & 2) Weather And Forecast OpenWeatherMap Account provides the "Bridge" for this binding. Weather and Forecast provides the binding channels to which our weather items will link.
Go to PaperUI\Inbox Search related to OpenWeatherMap Binding
Click on the OpenWeatherMap Account Channel. Fill in the fields, especially including the API key you received from subscribing at the OpenWeatherMap site (as above). For now, maybe leave the default 60 minute refresh until you are confident with your setup including the channels & items to use. As needed, we can generate a request (or set of requests ?) by rebooting OpenHAB reboots, but maybe avoid this too often. A free plan allows us 60 requests per minute which seems like a lot, but maybe each use of a channel is counted as a request against our limit. Later after happy with my setup, I changed refresh to every 30 minutes. (Apparently, for now anyway, overshooting our limit will cause a warning email. WeatherUnderground had allowed us a limited number of times of overshooting the limits on our subscribed plan.)
To save your OpenWeatherMap Account configuration, click the check mark in a blue disc. Note: The OpenWeatherMap Account Thing will not display "Online" until the Weather And Forecast Thing is configured (see below). The OpenWeatherMap Account Thing seems to go offline sometimes, but rebooting OpenHAB seems to fix that.
Next, Configure Weather And Forecast
|
|
|
Post by papa on Feb 16, 2019 18:12:06 GMT
Configure Weather And Forecast
Go to PaperUI\Inbox Search Add Manually Weather And Forecast
Bridge Selection OpenWeatherMap Account Fill in the fields, including Location of Weather (latitude, longitude).
You can obtain latitude & longitude for your address at this site.
The Weather and Forecast Thing will have many, many channels. We will need to choose the weather data we want & create items to link to some of these channels.
Next, Configuring Items for Weather Data
|
|
|
Post by papa on Feb 17, 2019 14:57:05 GMT
Configuring Items for Weather Data Preparatory NotesFor creating & displaying weather data items, I encourage you to study this Units of Measurement section of official OpenHAB documentation. Items for OpenHAB 2.xx weather bindings can use the same datatypes (String & Number) as with the 1.xx binding. However, if we extend the Number datatype with a "Dimension" (like Length or Temperature), an OpenHAB display will automatically include a unit of measurement label. The default seems to be metric units. To specify Imperial (United States) units of measurement,
go to PaperUI\Configuration\System Regional Settings Click Show More Under "Measurement System" choose Imperial (US). Be sure to click Save in the lower right of the Regional Settings window. You may also need to stop & restart OpenHAB for the change to register.
The above is mostly good, helpful news. The bad news: The units of measurement labels seem actually attached to the output which works fine for textual operations, but not so well for math calculations. If you will be doing math calculations with an item, use the item datatype of Number with out the Dimension extension. Unfortunately for those of us in the U.S. when we remove the Dimension, we also lose the numeric conversion from metric to imperial units of measurement. So if we in the U.S. will be doing math calculations with an item, we'll also need to include the math operation to convert from metric to imperial.
Example of item datatype with the dimension (channel is truncated) Number:Temperature temperature "Outside [%.2f %unit%]" { channel="...:current#temperature" } The value & the units of measurement will adjust to the chosen Measurement System. This works well to display for metric or imperial systems, but not for calculations.
------------------------------------------------------------------------------------
Example of item datatype without the dimension (channel is truncated)
Number temperatureProxy { channel="...:current#temperature" } This item will obtain the raw, metric weather data. Calculations can be made on the state of temperatureProxy
Number temperature "Outside [%.2f °F]" If this value is to be displayed, a rule could postUpdate this item with a value converted from Celsius to Fahrenheit.
|
|
|
Post by papa on Feb 17, 2019 15:34:43 GMT
Configuring Items for Weather DataIn OpenHAB's \conf\items folder, create a file like weather.items To create my items in the file, I matched my weather 1.xx items (mostly) to ones in this list & copied the {2.xx channel ... binding} to my items from the weather 1.xx binding & in some cases, extrapolated items as necessary based on examples in the list. If starting from scratch, choose what you need from the linked list (using some caution on how far you might push what you have available in your OpenWeatherMap plan).
|
|
|
Post by papa on Feb 17, 2019 15:48:01 GMT
Link Weather Data Items to Their Channel & Display the Items on a Sitemap
Goto PaperUI Configuration\Things\Weather And Forecast
Scroll through that VERY long list of channels. For each channel that you created an item, click on the channel's white circle on a blue disc. In the Link Channel window's drop down, choose the item meant for the channel.
On the sitemap, put an entry to display the item. For example, this would display an item named "temperature" ... Text item=temperature
|
|
|
Post by papa on Feb 17, 2019 15:59:54 GMT
Using Rules for Weather Data to Share Display Real EstateI prefer to combine related OpenHAB data within one sitemap slot. For example ...
// Two items gather weather station info from OpenWeatherMap
String Station_Name "Weather Station [%s]" <winddir> { channel="openweathermap:weather-and-forecast:api:local:station#name" } Location StationLocation "Location [%2$s°N %3$s°E]" <globe> { channel="openweathermap:weather-and-forecast:api:local:station#location" }
// One item will be filled with data combined from the two above items String Station "Weather Station [%s]" <globe>
Within OpenHAB's \conf\rules folder, create a file like weather.rules & in it, add a rule like this ...
rule StationInfo when Item Station_Name changed or Item StationLocation changed or Time cron "0 0/1 * * * ?" then var String St_Name = Station_Name.state.toString var String St_Whr = StationLocation.state.toString
// next line fills the Station item with Station_Name & StationLocation
Station.postUpdate(St_Name + "..." + St_Whr)
// Uncomment the next line for debugging info in the log
logInfo("Weather", St_Name + "..." + St_Whr) end
On a .sitemap, add the entry Text item=Station
|
|
|
Post by papa on Feb 23, 2019 19:02:23 GMT
Tutorials on Using OpenWeatherMap BindingOn the OpenHAB Community site, I just noticed a number of threads & tutorials about using the OpenWeatherMap Binding so I thought I'd bookmark that here.
|
|
|
Post by papa on Mar 2, 2019 14:44:43 GMT
More on Using the OpenWeatherMap 2.xx BindingAs reported above, I've been getting weather data from the OpenWeatherMap 2.xx Binding & it is mostly working well. One gap is that (unlike WeatherUnderground) OpenWeatherMap does not provide me today's accumulated liquid precipitation which I use for my irrigation automation. I searched for another way to get that information & found something, at least for us in the United States.
From my weather.items in OpenHab's \conf\items folder:
// OpenWeatherMap stations do not seem to track current precipitation so this now commented item always got zero // Number:Length Precip "Precip rec'd Today [%s %unit%]" <rain> (Weather, Precipitation) { channel="openweathermap:weather:api:local:current#rain" }
// Revised item that the rule below postUpdates with NOAA precipitation data
Number:Length Precip "Precip rec'd Today [%s %unit%]" <rain> (Weather, Precipitation)
Continues ...
|
|
|
Post by papa on Mar 2, 2019 14:49:31 GMT
Using NOAA Weather Data to Supplement
the OpenWeatherMap 2.xx Binding
Update, April 18, 2020: I did not find this method of getting NOAA Weather data to be reliable. I no longer use it.
Although I experimented some with what Rich Koshak offered here (& learned other possibilities), I mostly used it as is.
In Rich's rule (below), I supplied a sample (New Orleans) latitude & longitude & more comments. Hint: You might use the latitude/longitude of your address from here. If that does not get expected data, find the nearest NOAA weather station from your state's list here. Clicking on the [xml] button opposite the Observation Location will get you the location's latitude/longitude & a link for a 2 Day History of data from that location.
This site has links to various documentation & helps on using the NOAA's XML feed. NOAA stations provide hourly precipitation totals. Rich's rule & .xsl file below sum up the hourly reports across a calendar day into a text value.
To Rich's rule, I also added a command to convert the text value to a float value AND a postUpdate command to fill my Precip item with what the noaaPrecip.xsl file & the rule obtain.
Note: Sometimes the call for NOAA data is successful & sometimes not. Perhaps, frequent (every minute) calls get denied sometimes. If so, a less frequent cron trigger in the rule may be more successful. Every 15 minutes or more seems to work better.
Update, March 7, 2019: In the rule below, I set the weather data request to every hour on the hour. At least for the station I use, the data is updated a few minutes before the even hour. Also in the rule below, I added a throw-away request & a one-half minute pause. That may add some to reliability.
|
|
|
Post by papa on Mar 2, 2019 15:01:22 GMT
Using NOAA Weather Data to Supplement the OpenWeatherMap 2.xx Binding: The Needed Transform FileOther than add [@type='liquid'] I used Rich Koshak's .xsl file from here as is: (hint: do NOT put any space or comments above <?xml version=... That causes errors.)
Put this noaaPrecip.xsl file in OpenHAB's \conf\transform folder: Continues...
|
|
|
Post by papa on Mar 2, 2019 15:07:25 GMT
Using NOAA Weather Data to Supplement the OpenWeatherMap 2.xx Binding: The Needed Rules File Updated March 7, 2019
Put this NOAA.rules file in OpenHAB's \conf\rules folder:
|
|
|
Post by papa on Mar 8, 2019 13:51:35 GMT
More on Supplementing OpenWeatherMap Data Pressure/Weather TrendLike WeatherUnderground, OpenWeatherMap (OWM) provides barometric pressure. However, OWM does not provide the trend in barometric pressure, which is one means to predict weather trends. So I developed a way to use OWM barometric pressure data to calculate the trend & display the indicated weather trend.
Note: In order to use states of the following Pressure items for calculation, their type is just Number, not Number:Pressure.
Include in an OpenHAB \conf\ items file (perhaps weather. items): Number CurrentPressure "Current pressure [%d]" <pressure> { channel="openweathermap:weather:api:local:current#pressure" } Number PressureIn6hrs "pressureIn6hrs [%d]" <pressure> { channel="openweathermap:daily-forecast:api:local:forecastHours06#pressure" } String Trend "Pressure Trend [%s]" <question_cloud>
Continues ...
|
|
|
Post by papa on Mar 8, 2019 13:55:51 GMT
More on Supplementing OpenWeatherMap Data Pressure/Weather Trend Include in an OpenHAB \conf\ rules file (perhaps weather. rules): // Barometric pressure trend from now til 6 hours later & the weather the trend may bring rule pressureTrend when Item Item CurrentPressure changed or Item PressureIn6hrs changed or Time cron "0 0/1 * * * ?" // every minute then var Number CPs = CurrentPressure.state var Number P6h = PressureIn6hrs.state var Number pDiff = P6h - CPs // Pressure in 6 hours minus pressure now var String trnd = "steady" var Number fudge = 2 // -fudge & +fudge mark boundaries between "warmer/moister" "steady" & "cooler/drier" // convert calculation to a weather trend if (pDiff <= fudge && pDiff >= -fudge) trnd = "steady" if (pDiff > fudge) trnd = "cooler/drier" if (pDiff < -fudge) trnd = "warmer/moister" Trend.postUpdate(trnd) end
Continues ...
|
|
|
Post by papa on Mar 8, 2019 14:03:13 GMT
More on Supplementing OpenWeatherMap Data Pressure/Weather TrendIf needed, save to OpenHAB's \conf\icons\classic folder:
Include in an OpenHAB \conf\sitemaps file:
Text item=Trend
|
|
|
Post by papa on Apr 19, 2020 18:32:28 GMT
OpenWeatherMap Limitations As I documented in this thread , for openHAB weather data, I am fairly satisfied with OpenWeatherMap (OWM). However, OWM lacks some things I valued that are no longer available from other services. I found some ways to supplement OWM (See above). OWM stations do not seem to track recent precipitation. Although I thought I had a way (via NOAA weather data), so far I am not able to have OH reliable grab recent amounts of liquid precipitation. So I disabled using that data for automated irrigation. Especially for automated irrigation, I had found a way ( Dark Sky via the HTTP Binding) to get the probability of rain for today & tomorrow. The first 1,000 Dark Sky API requests per day have been free. However, when I looked up how to register currently for the Dark Sky API, I found on the Dark Sky blog: So it goes with free access (with limitations) to weather data, it's up & then someone buys it & locks it down. It's too bad that NOAA weather data (paid for by our taxes) is not very accessible via an API other than from one of these on again-off again services. Already registered people like me can access Dark Sky for another 1.75 years. Since new Dark Sky signups are not allowed, I will remove precipitation probability from the irrigation automation & no weather data will influence it unless I find another way.
|
|