OpenWeatherMap daily forecast using the free API

The OpenWeatherMap binding can be used with a free API, but this does not provide daily forecasts. So, I wrote a JSR223-Jython rule using the openhab2-jython modules to take the hourly data and add/remove the Items into groups that provide the daily forecast information. Since there are about 600 groups and Items that are needed, I included their creation in the rule too. The script file contains more details.

I think this is pretty much final, so I’ll start working on a Habpanel widget!


I think this could be very useful. But how to use it?

Perfect, thanks for sharing with the community!

To everyone, who wants to get started with Jython, this repository helped me out quite alot:

thanks to @5iver for taking the time to make it! :slight_smile:

Follow the link to the openhab2-jython repository and follow the instructions in the documentation for setting up JSR223-Jython. Then just copy/paste the transform file and script. If you have trouble with getting it setup, just create a post tagged with jsr223… if you have trouble with the script, reply back here!


thanks for sharing this script. But I got an error.

2019-01-09 20:39:55.605 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/etc/openhab2/automation/jsr223/community/openweathermap/’: NameError: global name ‘DateTime’ is not defined in at line number 263

Any ideas?

1 Like

Arg… thank you for reporting this… I have an import for org.joda.time.DateTime
that I use for other rules in my script. I forgot to include in the example. This is now update, so grab the latest!

@5iver: I tried your script too (thanks by the way for your work), but had to add another import:

import math

Beside that my items are not populated. I can see that the script gets executed as I can see

2019-01-10 18:29:23.711 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script ‘community/openweathermap/’
2019-01-10 18:29:23.955 [INFO ] [erMap Items to daily forecast groups] - currentHour=[18], forecastsLeftInDay=[2]

in the log, but nothing else happens.Maybe you could lend me a helping hand?

That’s just embarrassing… fixed! :blush:

During testing, I was sure I checked that the links were being created properly… but I must not have been, since they are not getting created. And my persistence was populating values for the Items, so nothing looked out fo the ordinary. The problem is that there is no provider for the links, so I’ve made a JythonItemChannelLinkProvider component script, a module, and updated to use these when Items are removed.

Please upgrade to the latest files in the repo, including the OWM script, and let me know how it works now. You will likely need to delete your old items, by uncommenting out the ‘last resort’ section of the removeOWMItems function, just make sure you don’t have any other Items with names starting with Forecast_ or Current_.

I hope that this time the mistake is on my side but:

2019-01-11 19:00:05.600 [ERROR] [e.smarthome.automation.jsr223.jython] - Traceback (most recent call last):
File “/openhab/conf/automation/lib/python/core/”, line 43, in wrapper
return fn(*args, **kwargs)
File “”, line 52, in removeOWMItems
ImportError: cannot import name remove_item


2019-01-11 19:00:05.726 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/openhab/conf/automation/jsr223/community/openweathermap/’: ImportError: cannot import name add_item in at line number 272

Did you update the modules (I updated many of them, and added a couple), and have you restarted OH?

Sorry, I missed the restart, modules should be there.
After the restart I get a lot of

2019-01-11 20:58:03.782 [ERROR] [.automation.jsr223.jython.core.links] - Traceback (most recent call last):
File “/openhab/conf/automation/lib/python/core/”, line 28, in add_link
channel_uid = validate_channel_uid(channel_uid)
File “/openhab/conf/automation/lib/python/core/”, line 22, in validate_channel_uid
raise Exception(“The ‘channel_uid’ argument must be a string or an existing ChannelUID”)
Exception: The ‘channel_uid’ argument must be a string or an existing ChannelUID


Another thing I can find in the logs:

Could not update element with key openweathermap:weather-and-forecast:api:local in ManagedThingProvider, because it does not exists.

I was able to fetch data before the script update, but am not sure if this entry was there before

Check in Paper UI and makes sure your OWM Things (both Account and Weather and Forecast) are configured properly. This error seems to mean that you do not have an API key configured. The script wouldn’t have changed that. This would also explain the other error, since the Channels would not exist. I’ll update he script to provide the Channel in that log entry, for some more info. My guess is that it would have come through as None.

That was my first guess, but I double checked it. I’ve added a manual item for the owm thing without any problems.

I just made an update that replaces the temperature forecast (Forecast_Temperature_X), which was the high temp, with Forecast_Temperature_High_X and Forecast_Temperature_Low_X.

There are also updates to core.items and core.links to add better logging and validation of Items and Channels (don’t forget to restart OH after updating). Hopefully, this will shed some more light on your issue. I’ve tested everything and can’t recreate your problem.

What was the Channel you used in the Item that you made? The rule is expecting a ThingUID like…


… but the ThingID (local) will be detected. If you uncomment the log entry currently at line 107, which logs the owmThingID, it would be helpful to know if it is being detected correctly.

owm.log (165.2 KB)

Still no luck. Here is my thing config:

Bridge openweathermap:weather-api:api “OpenWeatherMap Account” [apikey=“abcd”, refreshInterval=30, language=“de”] {
Thing weather-and-forecast local “Local Weather And Forecast” [location=“51.0000, 6.0000”, forecastHours=120, forecastDays=0]

Interesting… I haven’t tested this yet with an unmanaged Thing…

OK… I have reproduced it…

Try the latest version, it should now work with unmanaged Things (did for me!)…

Perfect, first test with xxx_1 worked! Thanks a lot!

One thing I could see in the log is that

2019-01-12 13:10:44.833 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/openhab/conf/automation/jsr223/community/openweathermap/’: ImportError: cannot import name JythonItemProvider in at line number 282

is printed ~30s before

2019-01-12 13:11:15.524 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script ‘core/components/’

Would you say this is a problem or ignorable?

That looks like a problem… but it’s something else that I haven’t seen. It looks like somehow is loading before the component scripts… which shouldn’t be possible. So, this was after a restart? If your Items and links aren’t all there, try resaving the script file, and it will run again. May need to use the removeOWMItems function too. Hopefully, you will at least get everything created and not have to mess with the creation part again. But I’ll look into how this could have happened.

I am seeing nearly the same errors, see my comment on github.