|
Post by papa on Oct 4, 2016 19:56:17 GMT
Display Weather Info on OpenHAB’s User Interface (This whole thread was updated & augmented in June 2018)
Update: On Feb. 16, 2019, I began this thread on using an OpenHAB 2.xx weather binding instead of the one just below. Weather information is a nice addition to your OpenHAB User Interface display. Earlier in 2016 (in this thread & here starting Feb 1, 2016 at 1:12pm), I had trouble with OpenHAB’s Weather Binding so I used the Http binding to pull Yahoo Weather info. Then the Yahoo weather approach quit working so here I return to using the Weather Binding. The following aims to document that.
Another thread makes my case for configuring OpenHAB 2 (OH2) with text files instead of PaperUI. The following uses OpenHAB configuration text files to set up for weather data. I recommend you use (free) Notepad++ to edit these text files.
Open addons.cfg in OpenHAB's \services folder Be sure you have these two lines: remote = true legacy = true
In addons.cfg, find the line that has "binding = " near the beginning. For the binding line to be active instead of a comment, remove any "#" that starts the line.
Somewhere after binding = add "weather1" (don't miss the number one at the end)
Precede weather1 with a comma IF weather1 follows another binding's name.
If another binding's name follows weather1 put a comma between weather1 & the next binding's name
My current comma-separated binding list in addons.cfg: binding = http1,mqtt1,weather1,ntp,expire1,astro,network
Adding weather1 to the binding list should generate a weather.cfg file in OpenHAB's /services folder. If not try stopping & restarting your OpenHAB service or rebooting your OpenHAB computer
|
|
|
Post by papa on Oct 4, 2016 20:03:54 GMT
Display Weather Info on OpenHAB’s User Interface (Updated 6/18/2018)
With a text editor like Notepad++, open weather.cfg found in your openhab \services folder.
1) Copy & paste these lines into weather.cfg & save the file, but leave the file open for more additions:
apikey.Wunderground= location.home.name=home location.home.latitude= location.home.longitude= location.home.provider=Wunderground location.home.language=en
location.home.updateInterval=10
Note: updateInterval ^^ is in minutes so weather data will take 10 minutes to change on your OpenHAB User Interface. Caution: Avoid less than 10 minute updates because you may exceed your free allowance with Weather Underground.
3) Put your Wunderground api key following the apikey.Wunderground= that you pasted in.
4) Get your location's latitude & longitude here or for more precision, here. 5) In lines you pasted into weather.cfg, put your location’s latitude number after "latitude=" & longitude number after "longitude=" 6) Save the changed weather.cfg file. The above should get OpenHAB ready to use the Weather Binding to obtain weather info.
|
|
|
Post by papa on Oct 4, 2016 20:13:27 GMT
Display Weather Info on OpenHAB’s User Interface (Updated 6/18/2018)
According to your units of measure, download ONLY ONE of these files & save it in OpenHAB's \items folder:
This will give you several weather items to work with & show you examples. You can open & edit them with Notepad++. Use the following information, including the official documentation, to help you make changes. Note: You may have more than one .items file (with different names) in the \items folder & OpenHAB will load them all. Just don't use item names in more than one .items file or they will conflict.
Download classic.zip from my github & extract it to OpenHAB's \icons\classic folder. For your OpenHAB User Interface display, it will give you several added icons, many from JimKernsJr & some from me.
In either weather*.items file, you can add weather-related items you want to obtain from Weather Underground & display on your OpenHAB User Interface. Go here & see the list of data possibilities. Here is a list of example items that should pull weather info for your location from Weather Underground.
Within the temperature section of example weather items, it says "// min and max values only available in forecasts" Then it lists example items, WITHOUT the forecast property, which do not work for me as is:
Number Temp_Min "Temperature min [%.2f C]" {weather="locationId=home, type=temperature, property=min"} ... etc
These min / max example items do mostly work for me (the needed addition is in bright blue text): Number Weather_Temp_Min "Temperature min [%.2f C]" {weather="locationId=home, forecast=0, type=temperature, property=min"} Number Weather_Temp_Min "Temperature min [%.2f F]" {weather="locationId=home, forecast=0, type=temperature, property=min, unit=fahrenheit"} Number Weather_Temp_Max "Temperature max [%.2f C]" {weather="locationId=home, forecast=0, type=temperature, property=max"} Number Weather_Temp_Max "Temperature max [%.2f F]" {weather="locationId=home, forecast=0, type=temperature, property=max, unit=fahrenheit"}
Note: Sometimes for me, the obtained minimum & maximum temps dipped much below what they actually were. I switched the Weather Underground station that I was using & that seems to have fixed the glitch.
This precipitation item also needs the forecast property to be added to the official documentation example: Number Precip_Probability "Precip probability [%d %%]" <rain> {weather="locationId=home, forecast=0, type=precipitation, property=probability"}
forecast=1 will get tomorrow's min / max temp. forecast=2 will get day after tomorrow ... etc.
These versions of total precipitation items worked better for me than the official examples (changes in bright, blue text): Number Precip "Precip total [%s mm]" <rain> (Weather, Precip) {weather="locationId=home, type=precipitation, property=total"} Number Precip "Precip total [%s in]" <rain> (Weather, Precip) {weather="locationId=home, type=precipitation, property=total, unit=inches"}
|
|
|
Post by papa on Oct 4, 2016 20:14:05 GMT
Display Weather Info on OpenHAB’s User Interface (Continued)
In your OpenHAB's \sitemaps folder, you need a file that ends with ".sitemap" Download ONLY ONE of these sample .sitemap files & save it to OpenHAB's \sitemaps folder: Note its top line is: sitemap Weather label="My Weather" After that is a left curly bracket ( { ) which matches the right curly bracket ( } ) at the end Between those curly brackets OpenHAB expects "Frames" which have their own curly brackets to frame their data
To have your User Interface display the weather information (from the above items), the .sitemap file in OpenHAB's \sitemaps folder has (at a location in the display list), a line like Text item=[item name] For example, to display total inches of precipitation for a day, the line is Text item= Precip
In the weather_Metric.items file above is the item named Precip which reads: Number Precip "Precip total [%s in]" <rain> (Weather, Precip) {weather="locationId=home, type=precipitation, property=total"} ^^ icon
To display an icon pic named rain with the item, make sure the rain icon comes standard with OpenHAB (it does not) OR have the rain.svg file in OpenHAB's \icons\classic folder. If you downloaded classic.zip above & extracted its files to the \icons\classic folder, the rain icon should work for you You could also change the item to: Precip [%s in]" <cloud> {weather="locationId=home, type=precipitation, property=total"} That would display the cloud icon you extracted to the \icons\classic folder
"valuecolor=" colors an item's display text, perhaps according to the item's value.
To show data on the OpenHAB User Interface (if you used the file example name above My.sitemap): In a browser tab on your computer running OpenHAB, enter one of these addresses according to your units of measure:
http://localhost:8080/basicui/app?sitemap=weather_Metric http://localhost:8080/basicui/app?sitemap=weather_English
Note: When you click "Outdoor Temp" on the User Interface screen, the above should display several weather data. The contents of weather_xxx.sitemap (between the outermost curly brackets) could be included in a larger sitemap.
Ahead: Chart some of your weather info. Display Multiple Weather Items on One OpenHAB User Interface Line
|
|
|
Post by papa on Oct 5, 2016 20:15:36 GMT
Configure OpenHAB "Persistence" to Help Chart Weather Info
As I understand it, charting OpenHAB data requires "persistence" to be in operation: 1) Be sure you have or put persistence method(s) in the \services\addons.cfg file, like this line: persistence = rrd4j,mapdb
Note: mapdb stores only the most recent data point of an item, useful to bridge lapses in data. rrd4j persistence stores can store more data, depending on how it is used.
2) Item 1) generates a rrd4j.persist configuration file in OpenHAB's /persistence folder
3) With a text editor like Notepad++, open rrd4j.persist & find "Strategies { ... // for rrd charts, we need a cron strategy" Just after that found text, make sure you have the following three lines: everyMinute : "0 * * * * ?" everyHour : "0 0 * * * ?" everyDay : "0 0 0 * * ?" 4) Still checking / editing in rrd4j.persist, farther down find "Items {" Beneath that & before the curly bracket ( "}" ) at the end of the Items section, make sure you have the following two lines: // to store EVERYTHING & restore them from the stored database at startup, UNcomment the next line * : strategy = everyMinute, restoreOnStartup 5) Important: Look at the contents of OpenHAB's \userdata\persistence\rrd4j folder. if there are any files there (all ending in .rrd), delete them all or persistence & charting may not work. Notes: Step 3) provides three strategies for using persistence. For now, we'll only use the first in Step 4. Step 4) stores everything (all item data) once a minute & when OpenHAB starts or restarts, it will use the stored data, rather than waiting for new data to be generated. This nicely prevents blanks in your user interface that result from items that are not yet defined after OpenHab starts or restarts. Note: Your OpenHAB log may give an error like ...rrd4j... - Removing invalid definition component = null heartbeat = 0 min/max = 0.0/0.0 step = 0 0 archives(s) = [] 0 items(s) = [] From what I've seen, don't worry about that error, especially if it happens only once per OpenHAB run. Looks like it's just a hiccup at OpenHAB start up. Ahead: Display Multiple Weather Items on One OpenHAB User Interface Line
|
|
|
Post by papa on Oct 6, 2016 20:09:20 GMT
Examples of Transformation Files That Help Us Display Weather Data
Download these files & save them to OpenHAB's \transform folder:
The files help OpenHAB transform data from one form to another & will be used below.
Ahead: Display Multiple Weather Items on One OpenHAB User Interface Line
|
|
|
Post by papa on Oct 6, 2016 20:43:37 GMT
Display Multiple Weather Items on One OpenHAB User Interface Line
As I wrote above: [For one way] To have your User Interface display the weather information (from the above items), the .sitemap file in OpenHAB's \sitemaps folder has (at a location in the display list), a line like Text item=[item name]. ..." That puts one item's data on one User Interface screen line. However, putting info from multiple items on one line uses the screen more efficiently. Here are configs to combine three related weather items: Notes: The first three items just below are the "sources," which are transformed & combined (by the rule) into the fourth item (Climate_Out). In the rule Ext_Climate, Time cron "0 0/2 * * * ?" makes the combined item update at least every 2 minutes. Otherwise, we wait until one of the source items changes. Have the following in /items/xxx. items [weather_Metric.items & weather_English.items from above already includes them] Number Weather_Temperature "Outdoor Temperature [%.1f °F]" <temperature> (Weather_Chart, Weather) {weather="locationId=home, type=temperature, property=current"}
note: weather_English.items adds , unit=fahrenheit Number Weather_Humidity "Outside Humidity [%d %%]" <humidity> (Weather_Chart) {weather="locationId=home, type=atmosphere, property=humidity, scale=1" } String Condition "Condition [%s]" <sun_clouds> (Weather) {weather="locationId=home, type=condition, property=text"} String Climate_Out "Climate Outside [%s]" <sun_clouds> (Weather)
weather.rules (3.66 KB) << Download this file & save it in OpenHAB's \rules folder. weather.rules is ready for Celsius data. For Fahrenheit, use Notepad++ to change the first 2 lines to: val String unit = "English" // val String unit = "Metric" // deactivates a line. no // means a line is active
The following rule & others are in OpenHAB's /rules/weather. rulesrule Ext_Climate when Weather_Temperature changed or Weather_Humidity changed or Time cron "0 */2 * * * ?" then var Number HumiW = Weather_Humidity.state var Number TempW = Weather_Temperature.state var Number HumiW_r = (Math::round(HumiW.floatValue)) var Number TempW_r = (Math::round(TempW.floatValue * 10.0 ) /10.0) Climate_Out.postUpdate(TempW_r + "°F... " + HumiW_r + "% " + Condition.state) end To show data on the OpenHAB User Interface (if you used one of the file examples above): In a browser tab on your computer running OpenHAB, enter this address http://localhost:8080/openhab.app?sitemap=weather _Metric.sitemap OR http://localhost:8080/openhab.app?sitemap=weather _English.sitemap
Note: When you click "Outdoor Temp" on the User Interface screen, the above should display several weather data.
Ahead: Display Charted Weather Data (Graphed over Time)
|
|
|
Post by papa on Oct 6, 2016 21:00:19 GMT
Display Charted Weather Data (Graphed over Time)
You probably want to choose numerical data related to each other & that span a reasonable numerical range, like various weather temperature information.
weather _Metric.sitemap & weather _English.sitemap already include a weather chart at the bottom of the display of Outdoor Temp, Outside Humidity, Max Temp, & Miin Temp. This uses the persistence we configured above.
This part of the .sitemap displays the weather chart:
Frame { Switch item=Weather_Chart_Period label="Chart Period" mappings=[0="Hour", 1="Day", 2="Week"] Chart item=Weather_Chart period=h refresh=6000 visibility=[Weather_Chart_Period==0, Weather_Chart_Period=="Uninitialized"] Chart item=Weather_Chart period=D refresh=30000 visibility=[Weather_Chart_Period==1] Chart item=Weather_Chart period=W refresh=30000 visibility=[Weather_Chart_Period==2] } To show data on the OpenHAB User Interface (if you used the file example name above My.sitemap): In a browser tab on your computer running OpenHAB, enter this address http://localhost:8080/openhab.app?sitemap=My
To show data on the OpenHAB User Interface (if you used one of the file examples above): In a browser tab on your computer running OpenHAB, enter this address http://localhost:8080/openhab.app?sitemap=weather _Metric.sitemap OR http://localhost:8080/openhab.app?sitemap=weather _English.sitemap
Note: When you click "Outdoor Temp" on the User Interface screen, the above should display several weather data AND should graph all items in the Weather_Chart group, all the items which include " (Weather_Chart)"
Also ... in OpenHAB's \sitemaps folder, you may have more than one .sitemap file & can open them in different browser tabs.
Next, A Weather Sitemap Displayed in a Browser Tab
|
|
|
Post by papa on Oct 7, 2016 0:08:24 GMT
A Weather Sitemap Displayed in a Browser Tab
Here are User Interface pics showing how I combined 2 or 3 weather data items on one line & displayed a chart of temperature & humidity values over time. Click on the pics for a larger view.
|
|
|
Post by papa on Oct 12, 2016 1:22:13 GMT
Reserved for more info on Displaying weather data.
|
|
pato
New Member
Posts: 8
|
Post by pato on May 13, 2017 11:25:21 GMT
1) Find the section titled “Weather Binding.” 2) Register at Weather underground (Wunderground) & get an api key: Follow the helpful instructions here. Sadly the instructions link is broken.
|
|
|
Post by papa on May 14, 2017 0:45:50 GMT
Thanks, pato, for catching that broken link. Looks like those instructions for getting a wunderground api key is at this location. I've changed the link accordingly in the Oct 4, 2016 post.
Update, June 20, 2018: The corrected link above still works.
|
|
|
Post by papa on May 27, 2017 19:20:16 GMT
This thread gives another example of combining multiple weather items into one item displayed on the User Interface. It also demonstrates troubleshooting an error that arose with this.
|
|
|
Post by papa on Jun 20, 2018 21:09:07 GMT
The above thread was updated & augmented in June 2018.
It was updated to work with OpenHAB 2. It was augmented with more examples & sample files to help get a user started with this topic.
|
|