Announcing OpenWeatherMap binding for Eclipse SmartHome / openHAB

Hi Vincent,
This page still has the incorrect example:

Things

demo.things

bridge openweathermap:weather-api:api "OpenWeatherMap Account" [apikey="AAA", refreshInterval=30, language="de"] {
    Thing weather-and-forecast local "Local Weather And Forecast" [location="XXX,YYY", forecastHours=0, forecastDays=7]
    Thing weather-and-forecast miami "Weather And Forecast In Miami" [location="25.782403,-80.264563", forecastHours=24, forecastDays=0]
}

Perhaps you could check it again? Thanks,

Well, cancel that. Creating the “openweathermap:weather-api” thing takes care of this.
Thought it is more complicated …

Thank you for this. My wunderground API key I’ve had for years finally got shut off. So migrating over to Open Weather Map for this data.

FYI when I added the account and local things through paper UI, it would not connect and kept saying invalid API key. When I created a thing file with the same information, it worked fine immediately.

I have a strange issue.
When I look at the temperature of my city at: https://openweathermap.org it says, let say -6 C

But in the PaperUI under Controls it says -12 C. The temps are always off.

Is this a bug? I can see that the PaperUI is using the same Station ID/Name as on the openweatherMap website but still displays the wrong temperature in openHAB.

Hi Christoph. Great binding, I’m using it with @5iver’s daily forecast and it is a great replacement for Wunderground and at the right time! I have a question about the 1h vs. 3h precipitation (snow/rain). When I hit the rest api for my location, I see a 1h reading (“snow”:{“1h”:0.1}) which means I get station data and not model data. I see in the binding code a call for weatherData.getSnow().get3h() which I assume is looks for the “3h” in the JSON for snow data. Am I reading this correctly? If I add a weatherData.getSnow().get1h() method looking for “1h” would this allow me to return “1h” reading for precipitation?

1 Like

Hi @kjunker,

Yes, that is correct. The binding tries to read the “3h” property and currently ignores the “1h” property.

Yes, it should work like that. It will be a nice litte improvement if we check both values. Will you submit a PR for it? Will be appreciated. Thanks.

I’d like to create a forecast graph in my sitemap from the 3-hour forecast data spanning 72 hours of forecast window.

How could this be achieved?

I wanted to do a similar thing, but using Grafana. I solved it with database views.

First, I created a view on each item table, picking up the latest entry and applying a time shift, for example for the snow prediction:

CREATE DEFINER = 'openhab'@'localhost' VIEW Snow30 AS SELECT  30 AS `hours`,  ADDDATE(  NOW(), INTERVAL 30 HOUR) AS `forecastdate`,  `Item560`.`Value` AS `Value`FROM `Item560`ORDER BY `Item560`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow66 AS SELECT  66 AS `hours`,  ADDDATE(  NOW(), INTERVAL 66 HOUR) AS `forecastdate`,  `Item559`.`Value` AS `Value`FROM `Item559`ORDER BY `Item559`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow18 AS SELECT  18 AS `hours`,  ADDDATE(  NOW(), INTERVAL 18 HOUR) AS `forecastdate`,  `Item558`.`Value` AS `Value`FROM `Item558`ORDER BY `Item558`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow39 AS SELECT  39 AS `hours`,  ADDDATE(  NOW(), INTERVAL 39 HOUR) AS `forecastdate`,  `Item557`.`Value` AS `Value`FROM `Item557`ORDER BY `Item557`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow57 AS SELECT  57 AS `hours`,  ADDDATE(  NOW(), INTERVAL 57 HOUR) AS `forecastdate`,  `Item556`.`Value` AS `Value`FROM `Item556`ORDER BY `Item556`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow54 AS SELECT  54 AS `hours`,  ADDDATE(  NOW(), INTERVAL 54 HOUR) AS `forecastdate`,  `Item555`.`Value` AS `Value`FROM `Item555`ORDER BY `Item555`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow21 AS SELECT  21 AS `hours`,  ADDDATE(  NOW(), INTERVAL 21 HOUR) AS `forecastdate`,  `Item554`.`Value` AS `Value`FROM `Item554`ORDER BY `Item554`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow27 AS SELECT  27 AS `hours`,  ADDDATE(  NOW(), INTERVAL 27 HOUR) AS `forecastdate`,  `Item553`.`Value` AS `Value`FROM `Item553`ORDER BY `Item553`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow42 AS SELECT  42 AS `hours`,  ADDDATE(  NOW(), INTERVAL 42 HOUR) AS `forecastdate`,  `Item552`.`Value` AS `Value`FROM `Item552`ORDER BY `Item552`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow33 AS SELECT  33 AS `hours`,  ADDDATE(  NOW(), INTERVAL 33 HOUR) AS `forecastdate`,  `Item551`.`Value` AS `Value`FROM `Item551`ORDER BY `Item551`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow45 AS SELECT  45 AS `hours`,  ADDDATE(  NOW(), INTERVAL 45 HOUR) AS `forecastdate`,  `Item550`.`Value` AS `Value`FROM `Item550`ORDER BY `Item550`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow69 AS SELECT  69 AS `hours`,  ADDDATE(  NOW(), INTERVAL 69 HOUR) AS `forecastdate`,  `Item549`.`Value` AS `Value`FROM `Item549`ORDER BY `Item549`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow15 AS SELECT  15 AS `hours`,  ADDDATE(  NOW(), INTERVAL 15 HOUR) AS `forecastdate`,  `Item548`.`Value` AS `Value`FROM `Item548`ORDER BY `Item548`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow48 AS SELECT  48 AS `hours`,  ADDDATE(  NOW(), INTERVAL 48 HOUR) AS `forecastdate`,  `Item547`.`Value` AS `Value`FROM `Item547`ORDER BY `Item547`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow63 AS SELECT  63 AS `hours`,  ADDDATE(  NOW(), INTERVAL 63 HOUR) AS `forecastdate`,  `Item546`.`Value` AS `Value`FROM `Item546`ORDER BY `Item546`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow24 AS SELECT  24 AS `hours`,  ADDDATE(  NOW(), INTERVAL 24 HOUR) AS `forecastdate`,  `Item545`.`Value` AS `Value`FROM `Item545`ORDER BY `Item545`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow60 AS SELECT  60 AS `hours`,  ADDDATE(  NOW(), INTERVAL 60 HOUR) AS `forecastdate`,  `Item544`.`Value` AS `Value`FROM `Item544`ORDER BY `Item544`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow36 AS SELECT  36 AS `hours`,  ADDDATE(  NOW(), INTERVAL 36 HOUR) AS `forecastdate`,  `Item543`.`Value` AS `Value`FROM `Item543`ORDER BY `Item543`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow51 AS SELECT  51 AS `hours`,  ADDDATE(  NOW(), INTERVAL 51 HOUR) AS `forecastdate`,  `Item542`.`Value` AS `Value`FROM `Item542`ORDER BY `Item542`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow3 AS SELECT  3 AS `hours`,  ADDDATE(  NOW(), INTERVAL 3 HOUR) AS `forecastdate`,  `Item541`.`Value` AS `Value`FROM `Item541`ORDER BY `Item541`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow9 AS SELECT  9 AS `hours`,  ADDDATE(  NOW(), INTERVAL 9 HOUR) AS `forecastdate`,  `Item540`.`Value` AS `Value`FROM `Item540`ORDER BY `Item540`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow12 AS SELECT  12 AS `hours`,  ADDDATE(  NOW(), INTERVAL 12 HOUR) AS `forecastdate`,  `Item539`.`Value` AS `Value`FROM `Item539`ORDER BY `Item539`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow6 AS SELECT  6 AS `hours`,  ADDDATE(  NOW(), INTERVAL 6 HOUR) AS `forecastdate`,  `Item538`.`Value` AS `Value`FROM `Item538`ORDER BY `Item538`.`Time` DESC LIMIT 1;
CREATE DEFINER = 'openhab'@'localhost' VIEW Snow0 AS SELECT  0 AS `hours`,  ADDDATE(  NOW(), INTERVAL 0 HOUR) AS `forecastdate`,  `Item537`.`Value` AS `Value`FROM `Item537`ORDER BY `Item537`.`Time` DESC LIMIT 1;

Then I made a union view to pull each record of the above views in one query:

Create DEFINER = 'openhab'@'localhost' VIEW SnowForecast AS
select hours, forecastdate, Value from Snow0 union
select hours, forecastdate, Value from Snow3 union
select hours, forecastdate, Value from Snow6 union
select hours, forecastdate, Value from Snow9 union
select hours, forecastdate, Value from Snow12 union
select hours, forecastdate, Value from Snow15 union
select hours, forecastdate, Value from Snow18 union
select hours, forecastdate, Value from Snow21 union
select hours, forecastdate, Value from Snow24 union
select hours, forecastdate, Value from Snow27 union
select hours, forecastdate, Value from Snow30 union
select hours, forecastdate, Value from Snow33 union
select hours, forecastdate, Value from Snow36 union
select hours, forecastdate, Value from Snow39 union
select hours, forecastdate, Value from Snow42 union
select hours, forecastdate, Value from Snow45 union
select hours, forecastdate, Value from Snow48 union
select hours, forecastdate, Value from Snow51 union
select hours, forecastdate, Value from Snow54 union
select hours, forecastdate, Value from Snow57 union
select hours, forecastdate, Value from Snow60 union
select hours, forecastdate, Value from Snow63 union
select hours, forecastdate, Value from Snow66 union
select hours, forecastdate, Value from Snow69

I did the same for rain and temperature, and use these three as data sources for a Grafana chart. Unfortunately we are not expecting rain or snow in the coming days, so my chart is pretty boring right now:

1 Like

I see. You’re using MySQL views to generate the data set to graph through Grafana.

At the moment I’m experimenting with InfluxDB and hence I’m still sorting my way into getting the same result. Persisting all forecast data is already a first precondition that I can easily satisfy. Once I have my first forecast data stored, I’ll then be able to experiment in Grafana.

Lots of good information in the entire posting! Being a noobe, I did figure out how to get OpenWeatherMap installed and setup along with the transform file for the wind direction. I guess since I have a free license I can only get the current weather information. The only other thing I’m looking for is how to change the wind speed from km\h to miles per hour.

Thank you
John Frankforther

You can get forecasts too. Set forecastHours to 120 (or however many you’d like in increments of 3) and forecastDays to 0. 120 forecastHours gives you 5 days of forecasts. This will require >600 Items, so you may want to check out…

Do it in your Item definition - change this:

Number:Speed localCurrentWindSpeed "Current wind speed [%.1f km/h]" <wind> { channel="openweathermap:weather-and-forecast:api:local:current#wind-speed" }

to

Number:Speed localCurrentWindSpeed "Current wind speed [%.1f mph]" <wind> { channel="openweathermap:weather-and-forecast:api:local:current#wind-speed" }

I just found that in the docs. I’m still new to OH and learning things daily even though I only have 1 switch connected to the system.

Thank you!!

John Frankforther

As I was looking over the sitemap at the weather readings, I noticed a number next to the Current Condition. What does the 800 represent?

John Frankforther

The ConditionIDs are listed here… https://openweathermap.org/weather-conditions

Thanks Scott! So would you put all those conditions in a transform file like for the wind direction?

John

No need… the binding does it for you in the Condition Item. The ConditionID does not have much use. It looks like your Condition Item is setup for the ConditionID.

Where would I change that at? In the Items file?

Yes, if you have one. If not, and you have Simple Mode turned on, turn it off. Then modify the Item in Paper UI.

I’m using this binding, but I’m having an issue using the temperature in a rule. Can someone please point me in the correct direction?

item file:

Number:Temperature localCurrentTemperature "Current temperature [%.1f %unit%]" 						  <temperature> 	(Weather)	{ channel="openweathermap:weather-and-forecast:c5e7a131:local:current#temperature" }
Number:Temperature localDailyForecastTodayMinTemperature "Minimum temperature for today [%.1f %unit%]" <temperature> 	(Weather)	{ channel="openweathermap:weather-and-forecast:c5e7a131:local:forecastToday#min-temperature" }
Number:Temperature localDailyForecastTodayMaxTemperature "Maximum temperature for today [%.1f %unit%]" <temperature> 	(Weather)	{ channel="openweathermap:weather-and-forecast:c5e7a131:local:forecastToday#max-temperature" }

Rules:

rule "Summertime"
 when
 	Item localCurrentTemperature changed
 	
 then
	val localTemp = localCurrentTemperature.state as DecimalType

 	if(localTemp as Number > 79)  {
 		sendCommand(Summer, ON)
 		logInfo("Summer", "It is hot outside!")
 		}
 	else sendCommand(Summer, OFF)
end

Error log:

2019-02-19 15:53:31.209 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Summertime': Could not cast 85.424 °F to org.eclipse.smarthome.core.library.types.DecimalType; line 736, column 18, length 44

I would really like to use the max daily temp to drive my virtual switch, but my understanding is that those only return on paid accounts.

Thanks in advance!