Weather binding in Openhab2

THX,
that makes sense!

That’s it. I have tested it and now after creation of one item the error message “no binding available” is gone. Thanks a lot

I have tried most things in this thread and other threads but I cannot get the Weather binding to work. Always get the “Disabling weather locationId ‘myhome’, no binding available” error in the log. Often in combination with “ghost” locations from previous config files.

Have performed a number of clean installations and diffrent config files from nice people who have posted online but nothing works.

I have a number of other items and bindings working so this is the only addon I have run into this much problem with. The last update on Github from this addon are about 4 months old and are not yet adapted to OH2.

My question is if there is any other way (preferably supported or atleast adapted to OH2) to get weatherdata into OH2? I am currently using Wunderground but can get an account at other site if needed.

Do you have any item that uses the location “myhome”?

I have items in my myhome.items that looks like below:

Number Weather_Temperature “Outside Temperature [%.1f °C]” (Weather, Weather_Chart) {weather=“locationId=myhome, type=temperature, property=current”}

I have corresponding items in my sitemap config.

Just got an idea. May it be so that you need to have other items (not from the weather binding) that also use the same location and sitemap? I have so far tried mostly with only having Weather binding installed. I have the gut feeling that the Weather binding may read files and configs in the wrong order when running in OH2 compared to OH1. This may force it to disable itselfs before it gets to the file with the right settings.

I also have the problem with ghost "locationId"s and so far the only way I have found to remove the old "locationId"s is to make a clean install of OH2.

To remove “ghost” stuff from OH2:

For example (for the weather binding):

config:list "(service.pid=org.openhab.weather)"
config:delete org.openhab.weather

Then, OH2 will re-read your /etc/openhab2/services/weather.cfg flat config file and load up the correct info (no need to do a clean install)

4 Likes

Thanks for the pointers Dim. Will try it out next time I see the ghosting.

Another thing regarding the Weather binding. When installing the Weather binding on a clean OpenHab2 installation (on Windows 10 64 bit) I get a warning in the log file:

14:23:46.393 [WARN ] [.weather.internal.bus.WeatherBinding] - Unable to find any configuration settings for weather binding. Check openhab.cfg.

This makes me suspect that the Weather binding is not liking OH2 that much.

On installation it creates the file “openhab\conf\services\weather.cfg”. Once modification is done to the weather.cfg a file named “weather.config” is places in “userdata\config\org\openhab” containing just the active lines. Is this just a backup or is it used by OH2 or the bindings in some way?

Wow, those command really deserve to go into the karaf console docu:

http://docs.openhab.org/administration/console.html

Managed to get my weatherbinding working by following this thread:

Seams most of my problems was due to problems with the .items file.

Is there a known problem? That the min and max temperature is not shown in WUnderground? For OpenWeatherMap i get a result…

Number Weather_Temp_Max			"Tages Maximum [%.2f °C]"		<temperature_hot> 	(gWeather, gWeather_Chart) {weather="locationId=home, type=temperature, property=max"}

Number Weather_Temp_Min			"Tages Minimum [%.2f °C]"		<temperature_cold> 	(gWeather, gWeather_Chart) {weather="locationId=home, type=temperature, property=min"}

# location configuration, you can specify multiple locations
location.home.name=Bous, Germany
location.home.latitude=49.28
location.home.longitude=6.82
#location.home.woeid=      (required for Yahoo provider)
location.home.provider=Wunderground
location.home.language=de
location.home.updateInterval=10

Wunderground provides min and max only at the forecast.

off_topic: For German language you must use DL instead of DE. See the api.

Number Temp_Max0 "Temp_Max0 [%.2f °C]" (grp_Weather) {weather="locationId=s, forecast=0, type=temperature, property=max"}

1 Like

Hi guys please help me out:
my weather.cfg: (I used both Yahoo and OpenWeatherMap):

# The apikey for the different weather providers, at least one must be specified
# Note: Hamweather requires two apikeys: client_id=apikey, client_secret=apikey2
#apikey.ForecastIo=
apikey.OpenWeatherMap=xxxxx
#apikey.WorldWeatherOnline=
#apikey.Wunderground=
#apikey.Hamweather=
#apikey2.Hamweather=
#apikey.Meteoblue=

# location configuration, you can specify multiple locations
location.home.name=home
#location.<locationId1>.latitude=   (not required for Yahoo provider)
#location.<locationId1>.longitude=  (not required for Yahoo provider)
location.home.woeid=xx     (required for Yahoo provider)
location.home.provider=Yahoo
location.home.language=en
location.home.updateInterval=10

location.work.name=work
location.work.latitude=xx  (not required for Yahoo provider)
location.work.longitude=xx  (not required for Yahoo provider)
location.work.woeid=xx      (required for Yahoo provider)
location.work.provider=OpenWeatherMap
location.work.language=en
location.work.updateInterval=10

item:


String      Condition_Id    "Weather is [%s]"(Weather)       { weather="locationId=work, type=condition, property=id" }
Number   Temperature_test       "Temperature [%.2f °C]"
{weather="locationId=work, type=temperature, property=current"}
Number   	Humidity_test   "Humidity [%d %%]"	{weather="locationId=work, type=atmosphere, property=humidity"}
Number   	Pressure_test   "Pressure [%.2f mb]" {weather="locationId=work, type=atmosphere, property=pressure"}

I tried to alter the locationId between “home” and “work” but none of that works although I reboot the system soooo many time. The only result I received is “-” on my OH2 sitemap :frowning:
Please help me out! Very frustrating with weather binding in Oh2. In the past when I used this binding with OH1.8.3 everything worked quite smoothly!

You obscured your id as well as the used woeid and Locations. Additionally you Show the “(required for Yahoo provider)”, do you have that in the file as well? Either remove it or mark it as a comment!

1 Like

This looks like a sample .cfg file. Could you show us your actual file (you can change the coordinates to only 1 or 2 decimals of you like for privacy).

Any way, the text “(not required for Yahoo provider)” shouldn’t be in the file.

1 Like

Oh How stupid I am
Indeed it was because of the (not require…) part
I got it done now
However it seems that android app can not display the weather webview
any idea?

I overcame that by displaying a picture of the webview.
However, if you only Show the values of the linked channels (like actual temp, actual weather, …) without the Icons, there is no need for a webview!

OK you mean like:

Image url="/weather?locationId=home&layout=example&iconset=colorful" height=5 refresh=1000

Unfortunately I can’t see the image

No, it’s not that easy!
You Need to have a seperate Software that takes a “screenshot” of your webview, saves it and you display that image.
Sounds to complicated, just show the item states with no (weather-)icons.

After hour of searching I figure this out, I’m really happy to share, explanation is below, I hope this would help someone:

  1. sudo apt-get install xvfb (googling if you do not know what is it)
  2. sudo apt-get install python-qt4
  3. copy this code:
#! /usr/bin/python
import sys
import time
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
from shutil import copyfile

class Screenshot(QWebView):
    def __init__(self):
        self.app = QApplication(sys.argv)
        QWebView.__init__(self)
        self._loaded = False
        self.loadFinished.connect(self._loadFinished)

    def capture(self, url, output_file):
        self.load(QUrl(url))
        self.wait_load()
        # set to webpage size
        frame = self.page().mainFrame()
        self.page().setViewportSize(frame.contentsSize())
        # render image
        image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
        painter = QPainter(image)
        frame.render(painter)
        painter.end()
       # print 'saving', output_file
        image.save(output_file)

    def wait_load(self, delay=0):
        # process app events until page loaded
        while not self._loaded:
            self.app.processEvents()
            time.sleep(delay)
        self._loaded = False

    def _loadFinished(self, result):
        self._loaded = True

s = Screenshot()
filename='website.png'
s.capture('http://localhost:8080/weather?locationId=home&layout=example&iconset=colorful', filename)
copyfile('/home/pi/'+filename,'/etc/openhab2/html/'+filename)
os.remove('/home/pi/'+filename)

and save under /etc/openhab2/scripts. Then:

sudo chmod a+rwx /etc/openhab2/scripts/screenshot.py

to get rid of the error “permission denied” (just for sure)
You might want to know that s.capture is used for capturing image from your weather webpage

  1. Create the rule:
rule "Periodically update weather-data"
when
   Time cron Time cron "0 */5 * * * ?" or
   System started
then
        val String results = executeCommandLine("sudo xvfb-run python /etc/openhab2/scripts/screenshot.py", 300000) 
end

NOTE:
After the line:

 val String results = executeCommandLine("sudo xvfb-run python /etc/openhab2/scripts/screenshot.py", 300000) 
end

your website.png (the screenshot image from weather webpage) will be stored under the root directory (the place on the terminal interface when you power up your system), I’m using raspberry pi 3 so you can see my source directory is /home/pi. Change this to adapt your system. This is very important because the website.png is saved under the root directory by default due to the command executeCommandLine(“sudo xvfb-run python /etc/openhab2/scripts/screenshot.py”, 300000) is executed under the root directory.

And the lines:

copyfile('/home/pi/'+filename,'/etc/openhab2/html/'+filename)
os.remove('/home/pi/'+filename)

just merely cut the website.png from destination to source directory, you can change these lines if you know any command can directly cut a file to a desiring path. In my case, I couldn’t find out that command so I had to do this. It’s quite clumsy but it did work after all!
Furthermore, you might want to change the destination path to satisfy yourself.
Personally, I’d like to put website.png under /etc/openhab2/html

In sitemap:

Image url="http://localhost:8080/static/website.png" refresh=10000

The only problem remaining is the resolution of the image is too large, anyway to resize it down ? I do not want to use python code anymore to resize the image, you know, it’s quite complicated and slow to do this way
@opus I hope you can share yours and suggest how can I improve mine, thanks very much

I’ve just installed a weather station and have it sending data to wunderground, which is all working OK there.

My weather.cfg uses the exact same lat/long that is used for the station at wunderground, but i can’t get my own weather station to be the weather station that openhab2 uses … is there any way to force it, please?