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!
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/owm_daily_forecast.py’: NameError: global name ‘DateTime’ is not defined in at line number 263
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 links.py module, and updated items.py 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/log.py”, 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/owm_daily_forecast.py’: ImportError: cannot import name add_item in at line number 272
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/links.py”, line 28, in add_link
channel_uid = validate_channel_uid(channel_uid)
File “/openhab/conf/automation/lib/python/core/links.py”, 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
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.
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.
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/owm_daily_forecast.py’: ImportError: cannot import name JythonItemProvider in at line number 282
That looks like a problem… but it’s something else that I haven’t seen. It looks like somehow owm_daily_forecast.py 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.