OpenWeatherMap daily forecast using the free API

I found some time playing with this again; @5iver maybe you could take a look at a few suspicious log entries?

2019-02-09 08:50:38.753 [DEBUG] [.automation.jsr223.jython.core.items] - Item added: [Forecast_IconID_120 (Type=StringItem, State=NULL, Label=Forecast (120): Icon ID [%s], Category=null, Tags=[OpenWeatherMap])]
2019-02-09 08:50:38.769 [ERROR] [.automation.jsr223.jython.core.links] - Traceback (most recent call last):
  File "/openhab/conf/automation/lib/python/core/links.py", line 33, in add_link
channel_uid = validate_channel_uid(channel_uid)
  File "/openhab/conf/automation/lib/python/core/links.py", line 27, in validate_channel_uid
raise Exception("\"{}\" is not a valid Channel".format(channel_uid))
Exception: "openweathermap:weather-and-forecast:api:local:forecastHours120#icon-id" is not a valid Channel

A similar logentry is genereated for every third forcast (e.g. openweathermap:weather-and-forecast:api:local:forecastHours114#icon-id,
openweathermap:weather-and-forecast:api:local:forecastHours117#icon-id, etc.)

And another one at the end of an execution:

2019-02-09 08:50:41.734 [DEBUG] [tomation.jsr223.jython.core.triggers] - when: target=[Item Current_Timestamp changed], target_type=Item, trigger_target=Current_Timestamp, trigger_type=changed, old_state=None, new_state=None
2019-02-09 08:50:41.746 [DEBUG] [tomation.jsr223.jython.core.triggers] - when: Created item_trigger: [Item-Current_Timestamp-changed]
2019-02-09 08:50:41.811 [DEBUG] [pse.smarthome.automation.module.core] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.events.EventSubscriber}={service.id=451, service.bundleid=248, service.scope=singleton, event.topics=smarthome/items/Current_Timestamp/*} - org.eclipse.smarthome.automation.module.core
2019-02-09 08:50:42.043 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/community/openweathermap/owm_daily_forecast.py': java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Invalid format: "NULL" in <script> at line number 393
2019-02-09 08:50:42.044 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: community/openweathermap/owm_daily_forecast.py

icon_id has only been added to the binding after the 2.4 release. So you will need a milestone or snapshot version for it. I commented the rew lines in the script to disregard this for now.

2 Likes

ā€˜timestampā€™ recently changed to ā€˜time-stampā€™ too, and the max/min of the city was added. Iā€™ll add in some more checksā€¦ maybe an OH version check, which have been discussed here.

What I intended to do eventually, is to iterate over the Channels of the OWM Thing, and create the Items from the definitions provided in the binding. Iā€™d like to make this into a module that could be used in other scripts too. This is essentially rebuilding SimpleMode functionality, for a specific binding, in a Jython module. I have it partially built, but Iā€™m thinking it makes more sense to propose this as a feature in openhab-core.

Let me please ask another question. For me the unit of Current_WindSpeed is m/s, but for the forecasts it is km/h. Is there any chance to make thoose equal?

Sorry, I missed your post. UoM is using km/h as the default unit for speed, and the script is just using the defaults.You could definitely modify your version of the script for this by using m/s instead of %unit%.

@5iver no problem. Good to know I can change the unit by myself, but unfortunately, I couldnā€™t explain the problem properly. What confused me is that I get two different units from one execution. Current is m/s and the forecasts are km/h. I would like to use the default km/h for all of them. I didnā€™t modify your script so far.

A second question arise in the meantime. When I first start your script only current data is available. After some while forecast temps and wind speed are available. No icons and conditions. As I had icons and conditions before, my guest is that after some more time those items are updated too. Is that the behavior you would expect?

I changed Configuration> System> Regional Settings> Measurement System from Imperial to Metric, uncommented removeOWMItems, saved/ran the script, and I see what you meanā€¦

This looks more like an issue in UoM/group aggregation or possibly the binding, and does not occur when using Imperial units (but I donā€™t know if there is an in/s unit in UoM). Iā€™ll try to track this down and report an issue for it.

No. When I use removeOWMItems, everything is populated immediately, which is what I would expect. Do you use persistence, and if so, which one? Worst case, everything should be populated after the bridgeā€™s refresh interval, which defaults to 10 minutes.

Have you left the removeOWMItems() function call uncommented? For normal use, this should be commented out.

One question: How did you do max / min?
My assumtion was that max should be around 12 pm and min possibly around 4 am (sometime before sunrise).
Do you work with similar approximations or do you check for max within the next 12 hrs if itā€™s around 6 am for instance?

Do you mean max and min for the day, or for the city? I havenā€™t implemented max/min for the city yet, but it will be done in the same way, using group aggregation functions. The rule is triggered by one of the timestamp Items changing, and the rule shifts the Items in the groups, based on their times. This makes much more sense by looking at the screenshots. Anyhow, the max and min are two groups that hold the same Items, but use different aggregation functions.

Doing it this way, there are no approximations needed, since you are getting the max value for all of the forecasts within that day. Or partial day for the remainder of forecasts in the current day, which I really like, since the calculation only uses the remaining temps left in the day, with no consideration for the previous temps.

That sounds excellent. I light come back using you solution, but I first need to finish my learning session.
Right now I do an approximation to use the min / max of the entire day at 6 am (which is close enough, I assume). I do this by taking max and min for 3, 6, ā€¦ for the current day and 24, ā€¦ for the next and so on.

I donā€™t care for the max of the city as long as itā€™s in my area :wink:

I need some help with this. Iā€™ve followed the instructions to install Jython and had the HelloWorld script running.

Loaded the owm_daily_forecast.py into the jr223/python/community folder.

My log is showing the following and Iā€™m not sure what it means and/or how to fix it:

2020-01-29 07:23:21.840 [INFO ] [me.core.service.AbstractWatchService] - Loading script ā€˜python/community/owm_daily_forecast.pyā€™

2020-01-29 07:23:21.843 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language ā€˜pyā€™ with identifier: file:/etc/openhab2/automation/jsr223/python/community/owm_daily_forecast.py

2020-01-29 07:23:21.858 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ā€˜file:/etc/openhab2/automation/jsr223/python/community/owm_daily_forecast.pyā€™: java.io.IOException: java.io.IOException: Mark invalid

Any help would be really appreciated!

Glad to help!

Is there a stack trace in the log? @mstormi reported something similar, but I donā€™t recall how/if it was resolved. Have you restarted OH? Which version of OH are you running? Which version of Jython?

In looking at the trace that Markus provided, I suspect this could be due to an issue with the SD card. Are you using an SD card, is it old, and have you tested it lately?

Stack trace in the log? Iā€™m learning as I go so Iā€™m not sure what to look for to determine that.

Yesā€¦using the command
sudo systemctl restart openhab2.service

Iā€™m on OH 2.5.1-2

Jython 2.7.0 standalone version.

Yes, Iā€™m using an SD card. It was taken out of the packaging last week when I decided to rebuild my RPi/OH server but it may have been bought sometime last year.
I havenā€™t tested it at all.

No problemā€¦ take a look at the logs in the post I linked to earlier. There is a full stack trace (lots of error message). The log you posted looks to be one line. Was there more in the log file?

Did the error show up a second time, or did everything startup properly? If you still got the error, try saving the file again and see if it launches. If the error still happens, try posting your log file somewhere that I can get to it.

I did just post one line. The rest of the log seems to read normal but itā€™s available at this link for you to peruse.

The error happens every time I reboot.

You have a LOT of errors! Wow!

This concerns meā€¦

2020-01-28 23:58:00.376 [INFO ] [me.core.service.AbstractWatchService] - ScriptEngine for crdownload not available
2020-01-28 23:58:01.042 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/community/owm_daily_forecast.py'
2020-01-28 23:58:01.045 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/community/owm_daily_forecast.py
2020-01-28 23:58:01.105 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/community/owm_daily_forecast.py'
2020-01-28 23:58:01.110 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/community/owm_daily_forecast.py
2020-01-28 23:58:01.155 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/community/owm_daily_forecast.py': java.io.IOException: java.io.IOException: Mark invalid
2020-01-28 23:58:02.200 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/community/owm_daily_forecast.py'
2020-01-28 23:58:02.207 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/community/owm_daily_forecast.py
2020-01-28 23:58:02.234 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/community/owm_daily_forecast.py': java.io.IOException: java.io.IOException: Mark invalid

How did you download the script? The entire repository should be downloaded as a zip file (step 7), extracted, and then the files copied to directories per the instructions. Thisā€¦

2020-01-28 23:58:00.376 [INFO ] [me.core.service.AbstractWatchService] - ScriptEngine for crdownload not available

ā€¦ looks like you were downloading the fileā€¦ possibly not the raw file but the html of the page that it is on, directly to the community directory. Open the file and see if it looks like Python and what you see here. I think you have an issue with that file from not following the installation instructions.

I downloaded the script from the page that it was on (right click on owm_daily_forecast.py and save link as) and not the entire repo, but when I open it, it does look just like the one you posted.

I will download the repo and extract the files and reinstall from there.

As far as I can tell the errors keep repeating themselves in the log not so? I didnā€™t open the log files I sent so Iā€™m not sure how far back they go, but I was experimenting with different methods of control over the past week as part of the rebuild which may account for some of the errors.

EDIT: I just tapped on the link you provided

I did follow the instructions and therefore download that repo as a zip as per step 7. When I get back to my computer I will go through to make sure.

That is the problem then. You canā€™t save files from Github like you describe. You can download the whole repo or go to the file, choose the raw (like the link I sent), and copy/paste the contents into a file. Right clicking and saving link as will include html content. I think you will get it this time!

The reinstall did it! I realized my file path was also incorrect - I put the owm_daily_forecast.py directly into the community folder (as you pointed out) and not in its own folder. Rookie mistake :woozy_face:

1 Like

Thanks @5iver! Youā€™re a prince among men! Hahaha

1 Like