OpenWeatherMap daily forecast using the free API

/etc/default/openhab2

#########################
## JAVA OPTIONS
## Additional options for the JAVA_OPTS environment variable.
## These will be appended to the execution of the openHAB Java runtime in front$
## 
## A couple of independent examples:
##   EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0"
##   EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyS0:/dev/tt$
##   EXTRA_JAVA_OPTS="-Djna.library.path=/lib/arm-linux-gnueabihf/ -Duser.timez$

EXTRA_JAVA_OPTS="-Xbootclasspath/a:/etc/openhab2/automation/jython/jython-stand$

EXTRA_JAVA_OPTS="-Xms250m -Xmx350m"

#########################

Looks like that got truncated a bit
 paste the first line into a post (put 4 spaces in front of it). Also, I do not believe you can have multiple EXTRA_JAVA_OPTS lines, so the second may be wiping out the first. Try putting them all in one, like this


EXTRA_JAVA_OPTS="-Xbootclasspath/a:/etc/openhab2/automation/jython/jython-standalone-2.7.0.jar -Dpython.home=/etc/openhab2/automation/jython -Dpython.path=/etc/openhab2/automation/lib/python -Xms250m -Xmx350m"

think it works.

17:59:52.437 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'community/openweathermap/owm_daily_forecast.py'
18:00:03.488 [DEBUG] [.automation.jsr223.jython.addOWMItems] - Scale transformation service is already installed
18:00:03.806 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/community/OpenWeatherMap/automation/jsr223/community/openweathermap/owm_daily_forecast.py': ImportError: cannot import name JythonItemProvider in <script> at line number 393
18:00:03.809 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: community/openweathermap/owm_daily_forecast.py
18:00:03.814 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/000_startup_delay.py'
18:00:03.901 [INFO ] [utomation.jsr223.jython.startup_delay] - Checking for initialized context
18:00:03.917 [INFO ] [utomation.jsr223.jython.startup_delay] - Context initialized... waiting 30s before allowing scripts to load
18:00:33.929 [INFO ] [utomation.jsr223.jython.startup_delay] - Complete
18:00:33.938 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/000_startup_delay.py
18:00:33.942 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/100_DirectoryTrigger.py'
18:00:34.089 [INFO ] [223.jython.core.DirectoryEventTrigger] - TriggerHandler added
18:00:34.097 [INFO ] [223.jython.core.DirectoryEventTrigger] - TriggerType added
18:00:34.099 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/100_DirectoryTrigger.py
18:00:34.101 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/100_OsgiEventTrigger.py'
18:00:34.808 [INFO ] [n.jsr223.jython.core.OsgiEventTrigger] - TriggerHandler added
18:00:34.818 [INFO ] [n.jsr223.jython.core.OsgiEventTrigger] - TriggerType added
18:00:34.821 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/100_OsgiEventTrigger.py
18:00:34.823 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/100_ShutdownTrigger.py'
18:00:34.878 [INFO ] [on.jsr223.jython.core.ShutdownTrigger] - TriggerHandler added [jsr223.ShutdownTrigger]
18:00:34.889 [INFO ] [on.jsr223.jython.core.ShutdownTrigger] - TriggerType added [jsr223.ShutdownTrigger]
18:00:34.892 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/100_ShutdownTrigger.py
18:00:34.895 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/100_StartupTrigger.py'
18:00:34.975 [INFO ] [ion.jsr223.jython.core.StartupTrigger] - TriggerHandler added [jsr223.StartupTrigger]
18:00:34.984 [INFO ] [ion.jsr223.jython.core.StartupTrigger] - TriggerType added [jsr223.StartupTrigger]
18:00:34.988 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/100_StartupTrigger.py
18:00:34.992 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonBindingInfoProvider.py'
18:00:35.133 [DEBUG] [se.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.binding.BindingInfoProvider}={service.id=448, service.bundleid=239, service.scope=singleton} - org.eclipse.smarthome.automation.module.script
18:00:35.145 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/200_JythonBindingInfoProvider.py
18:00:35.148 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonExtensionProvider.py'
18:00:36.030 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/200_JythonExtensionProvider.py
18:00:36.034 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonItemChannelLinkProvider.py'
18:00:36.154 [DEBUG] [se.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.thing.link.ItemChannelLinkProvider}={service.id=449, service.bundleid=239, service.scope=singleton} - org.eclipse.smarthome.automation.module.script
18:00:36.171 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/200_JythonItemChannelLinkProvider.py
18:00:36.175 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonItemProvider.py'
18:00:36.244 [DEBUG] [se.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.items.ItemProvider}={service.id=450, service.bundleid=239, service.scope=singleton} - org.eclipse.smarthome.automation.module.script
18:00:36.264 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/200_JythonItemProvider.py
18:00:36.269 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonThingProvider.py'
18:00:36.341 [DEBUG] [se.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.thing.ThingProvider}={service.id=451, service.bundleid=239, service.scope=singleton} - org.eclipse.smarthome.automation.module.script
18:00:36.347 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/200_JythonThingProvider.py
18:00:36.351 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonThingTypeProvider.py'
18:00:36.470 [DEBUG] [se.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.thing.binding.ThingTypeProvider}={service.id=452, service.bundleid=239, service.scope=singleton} - org.eclipse.smarthome.automation.module.script
18:00:36.477 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/200_JythonThingTypeProvider.py
18:00:36.486 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'core/components/200_JythonTransform.py'
18:00:36.618 [DEBUG] [se.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.transform.TransformationService}={service.id=453, service.bundleid=239, service.scope=singleton, smarthome.transform=JYTHON} - org.eclipse.smarthome.automation.module.script
18:00:36.634 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: core/components/200_JythonTransform.py
18:00:36.642 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'personal/hello_world.py'
18:00:38.536 [DEBUG] [utomation.jsr223.jython.core.triggers] - when: target=[Time cron 0/10 * * * * ?], target_type=Time, trigger_target=cron, trigger_type=0/10 * * * * ?, old_state=None, new_state=None
18:00:41.807 [DEBUG] [utomation.jsr223.jython.core.triggers] - when: Created cron_trigger: [Cron-hellowWorldDecoratorCron-03cbe3cf289611e9b9427bf04be4ac54]
18:00:41.928 [DEBUG] [mer.handler.GenericCronTriggerHandler] - Scheduled cron job '0/10 * * * * ?' for trigger 'Cron-hellowWorldDecoratorCron-03cbe3cf289611e9b9427bf04be4ac54'.
18:00:41.935 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: personal/hello_world.py
18:00:41.938 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'test.py'
18:00:41.959 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: test.py
18:00:41.981 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'tt.py'
18:00:41.995 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: tt.py
18:00:50.073 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The trigger 'Cron-hellowWorldDecoratorCron-03cbe3cf289611e9b9427bf04be4ac54' of rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is triggered.
18:00:50.094 [INFO ] [hon.Hello World cron rule (decorator)] - This is a 'hello world!' from a Jython rule (decorator): Cron
18:00:50.099 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is executed.
18:01:00.032 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The trigger 'Cron-hellowWorldDecoratorCron-03cbe3cf289611e9b9427bf04be4ac54' of rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is triggered.
18:01:00.035 [INFO ] [hon.Hello World cron rule (decorator)] - This is a 'hello world!' from a Jython rule (decorator): Cron
18:01:00.046 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is executed.
18:01:10.018 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The trigger 'Cron-hellowWorldDecoratorCron-03cbe3cf289611e9b9427bf04be4ac54' of rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is triggered.
18:01:10.024 [INFO ] [hon.Hello World cron rule (decorator)] - This is a 'hello world!' from a Jython rule (decorator): Cron
18:01:10.027 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is executed.
18:01:20.017 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The trigger 'Cron-hellowWorldDecoratorCron-03cbe3cf289611e9b9427bf04be4ac54' of rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is triggered.
18:01:20.021 [INFO ] [hon.Hello World cron rule (decorator)] - This is a 'hello world!' from a Jython rule (decorator): Cron
18:01:20.027 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is executed.
18:01:30.015 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The trigger 'Cron-hellowWorldDecoratorCron-03cbe3cf289611e9b9427bf04be4ac54' of rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is triggered.
18:01:30.022 [INFO ] [hon.Hello World cron rule (decorator)] - This is a 'hello world!' from a Jython rule (decorator): Cron
18:01:30.024 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is executed.
18:01:40.006 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The trigger 'Cron-hellowWorldDecoratorCron-03cbe3cf289611e9b9427bf04be4ac54' of rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is triggered.
18:01:40.010 [INFO ] [hon.Hello World cron rule (decorator)] - This is a 'hello world!' from a Jython rule (decorator): Cron
18:01:40.016 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is executed.
18:01:50.011 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The trigger 'Cron-hellowWorldDecoratorCron-03cbe3cf289611e9b9427bf04be4ac54' of rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is triggered.
18:01:50.014 [INFO ] [hon.Hello World cron rule (decorator)] - This is a 'hello world!' from a Jython rule (decorator): Cron
18:01:50.018 [DEBUG] [tomation.core.internal.RuleEngineImpl] - The rule '6959d8af-d52f-4389-a1c3-db666ce02f1b' is executed.


Except for this. I forgot
 a problem has been identified in the order of script loading, and I plan to fix in the OH-core. As a work around, save the OWM script again so that the Items get created, or rename /automation/jsr223/core to /automation/jsr223/000_core, so that these scripts load first. I’ll update the repo so that this stops affecting people, but all the docs will need to be updated too :roll_eyes:.

dit that. this is the log.

19:08:05.785 [DEBUG] [e.automation.jsr223.jython.core.items] - Item added: [Forecast_RainVolume_120 (Type=NumberItem, State=NULL, Label=Forecast (120): Rain volume [%.1f %unit%], Category=Rain, Tags=[OpenWeatherMap])]
19:08:05.806 [ERROR] [e.automation.jsr223.jython.core.links] - Traceback (most recent call last):
  File "/etc/openhab2/automation/lib/python/core/links.py", line 33, in add_link
    channel_uid = validate_channel_uid(channel_uid)
  File "/etc/openhab2/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#rain" is not a valid Channel

19:08:05.815 [DEBUG] [e.automation.jsr223.jython.core.items] - Item added: [Forecast_SnowVolume_120 (Type=NumberItem, State=NULL, Label=Forecast (120): Snow volume [%.1f %unit%], Category=Snow, Tags=[OpenWeatherMap])]
19:08:05.835 [ERROR] [e.automation.jsr223.jython.core.links] - Traceback (most recent call last):
  File "/etc/openhab2/automation/lib/python/core/links.py", line 33, in add_link
    channel_uid = validate_channel_uid(channel_uid)
  File "/etc/openhab2/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#snow" is not a valid Channel

19:08:08.241 [DEBUG] [utomation.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
19:08:08.259 [DEBUG] [utomation.jsr223.jython.core.triggers] - when: Created item_trigger: [Item-Current_Timestamp-changed]
19:08:08.350 [DEBUG] [ipse.smarthome.automation.module.core] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.events.EventSubscriber}={service.id=454, service.bundleid=237, service.scope=singleton, event.topics=smarthome/items/Current_Timestamp/*} - org.eclipse.smarthome.automation.module.core
19:08:08.477 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/Community/OpenWeatherMap/automation/jsr223/community/openweathermap/owm_daily_forecast.py': java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Invalid format: "NULL" in <script> at line number 393
19:08:08.480 [DEBUG] [ort.internal.loader.ScriptFileWatcher] - Script loaded: community/openweathermap/owm_daily_forecast.py

where does it add it?

This looks like you may not have the Thing created and configured. I’ll add a check to make sure the Thing exists, and then log and break if it is not there. Do you have a ‘Local Forecast and Weather’ Thing?

I have this in my weather.thing

Bridge openweathermap:weather-api:api "OpenWeatherMap Account" [apikey="##############", refreshInterval=60, language="en"] {
    Thing weather-and-forecast local "Local Weather And Forecast" [location="-25.78, 29.46", forecastHours=0, forecastDays=7]
    Thing uvindex local "Local UV Index" [location="-25.78, 29.46", forecastDays=7]
}```

I bet if you check in Paper UI, that it is not online. I use managed Things, but used this in testing (note the forecastHours and forecastDays)


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

Once you get the Thing sorted, you will need to uncomment the removeOWMItems line, to start with a clean slate for the Items.

2019-02-04 19:48:30.367 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'weather.things'

==> /var/log/openhab2/events.log <==

2019-02-04 19:48:30.445 [hingStatusInfoChangedEvent] - 'openweathermap:weather-and-forecast:api:local' changed from ONLINE to UNKNOWN

==> /var/log/openhab2/openhab.log <==

2019-02-04 19:48:30.491 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.thingUpdated()' on 'org.eclipse.smarthome.binding.openweathermap.internal.handler.OpenWeatherMapWeatherAndForecastHandler@36f5bac7': Duplicate channels openweathermap:weather-and-forecast:api:local:forecastHours03#time-stamp

java.lang.IllegalArgumentException: Duplicate channels openweathermap:weather-and-forecast:api:local:forecastHours03#time-stamp

	at org.eclipse.smarthome.core.thing.util.ThingHelper.ensureUniqueChannels(ThingHelper.java:159) ~[?:?]

	at org.eclipse.smarthome.core.thing.util.ThingHelper.ensureUniqueChannels(ThingHelper.java:151) ~[?:?]

	at org.eclipse.smarthome.core.thing.util.ThingHelper.ensureUniqueChannels(ThingHelper.java:147) ~[?:?]

	at org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder.withChannel(ThingBuilder.java:74) ~[?:?]

	at org.eclipse.smarthome.binding.openweathermap.internal.handler.OpenWeatherMapWeatherAndForecastHandler.initialize(OpenWeatherMapWeatherAndForecastHandler.java:153) ~[?:?]

	at org.eclipse.smarthome.core.thing.binding.BaseThingHandler.thingUpdated(BaseThingHandler.java:208) ~[?:?]

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]

	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]

	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]

	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [102:org.eclipse.smarthome.core:0.10.0.oh240]

	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [102:org.eclipse.smarthome.core:0.10.0.oh240]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

	at java.lang.Thread.run(Thread.java:748) [?:?]

==> /var/log/openhab2/events.log <==

2019-02-04 19:48:30.520 [me.event.ThingUpdatedEvent] - Thing 'openweathermap:weather-and-forecast:api:local' has been updated.

==> /var/log/openhab2/openhab.log <==

2019-02-04 19:48:44.603 [WARN ] [mon.registry.AbstractManagedProvider] - Could not update element with key openweathermap:weather-and-forecast:api:local in ManagedThingProvider, because it does not exists.

got it 


I’m not sure what you’re saying :slight_smile:. The error is ugly
 what change did you make to the Thing file? Maybe a bug with unmanaged Things? Remove the file and create it Paper UI?

Without the forecastDays set to 0, the free API key will not work. Without forecastHours set to 120, the script won’t work.

OK, cool!

now this. just need to get them on mi sitemap. and the scale :
I removed the thing on paperui and recreated it.
I also changed the the days to 0 and hours to 120

2019-02-04 19:55:53.780 [WARN ] [ui.internal.items.ItemUIRegistryImpl] - Exception while formatting value '117.5 °' of item localCurrentWindDirection with format 'SCALE(windDirection.scale):%s [%.0f %unit%': Format specifier '%.0f'```

This Item did not come from the script. But the name looks familiar
 like SimpleMode was enabled and the name was pulled from the binding, but that wouldn’t have added the transform part and the incorrect formatting. Did you create this one?

For sitemap, you can quickly just add


Group item=gOpenWeatherMap

Not sure what you mean by scale. You should have copied the windDirection.scale file to your transform directory. The script will install the Scale transformation service for you, if needed,

thank you. all works just need the rest of the days to update. current and todays is working.

They all come in at the same time, so something is likely not right yet. Someone reported an issue in GH with basically the same problem. I think it is that there were setup issues, but the removeOwmItems function wasn’t used to remove the Items so that the Links could be created. If you look at the Thing in Paper UI, click Show More, then scroll all the way to the bottom. Do you see Links for all the Channels?

Hearing that makes it all worth it! You are very welcome!

how do I use the removeOWMItems.
maby it can pull the links corect.

Just remove the comment from the beginning of the line and save the file. When the Items are removed, there will be a lot of debug messages, and then more as they are added back in. When it is done, put the comment back and save.

one more question might be little dum .

I want to have a item that states the total mm of rain for the day. week and also for the month. and then one for the total for the year.
the day one has to reset every 24 hrs.
the month one every end of the month.
and the year one every 12 month (yearly)

Can that be done ?

Best to start a new topic for that, but yes, it can be done using persistence. I do something similar for house and car charging energy meters.

thank You will do that.