Moon information from One Call (openweathermap)

If I understand this information (One Call API: weather data for any geographical coordinate - OpenWeatherMap) correctly, the One Call API (so the free version) supports moon information (moonrise, moonset and moon_phase).

Is that something that might be incorporated in the binding? I would think that’s not much more than some copy-pasting with some alterations? But that’s of course my layman estimation, and of course with respect to everyone’s time. And not meant as a minimization of any effort that goes into all of this. I might be entirely wrong with my estimation. :slight_smile:

I tried looking at the github to found out where exactly the API is “addressed”, but figure it out…

Nothing speaks against it if someone contributes it.

More or less yes, I think. But I haven’t looked into the API implementation, only in the Thing handler implementations. The DTO also needs to be updated, but that shouldn’t be much work.

You can find the binding in the addon repo: openhab-addons/bundles/org.openhab.binding.openweathermap at main · openhab/openhab-addons · GitHub

Either try it yourself or create a new issue and request the addition of the moon data, so we don’t forget it. I will probably have a look when I extend time series support in the binding.

I opened up all files, and searched for substring sunri. Based on that thinking, it looks like in the following files something needs to be added:

  1. https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/dto/onecall/Daily.java
  2. https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/dto/weather/Sys.java
  3. https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHandler.java
  4. https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHistoryHandler.java
  5. https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/OpenWeatherMapBindingConstants.java
  6. https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/i18n/openweathermap.properties
  7. https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/thing/channel-types.xml
  8. https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/thing/thing-types.xml
  9. https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/update/instructions.xml

How would I go about trying to contribute to this quest? I’ve never done something like it, and always like to learn something new. :slight_smile: And this seems like something I’m capable of…

As you linked to the OneCall API docs, you will have to modify the OneCall Weather and Forecast Thing:

  1. Looking at the API docs, moon data is only available on the daily object, so you only need to modify: https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/dto/onecall/Daily.java
  2. Create channel types for moonrise, moonset and moonphase in the lines below here: https://github.com/openhab/openhab-addons/blob/e68897c0a1c6d2912bf4ac3a8f8b468aa459acaf/bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/thing/channel-types.xml#L408
  3. Then add new channels to the oneCallDailyTimeseries and oneCallDaily channel group types.
  4. Add constants for the channel names to https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/OpenWeatherMapBindingConstants.java#L25
  5. Update the OpenWeatherMapOneCallHandler: Add moon stuff to https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHandler.java#L654 and to https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHandler.java#L629
  6. Run mvn i18n:generate-default-translations -pl :org.openhab.binding.openweathermap to regenerate the default translations (the .properties files in i18n folder)
  7. Add update instructions in https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/update/instructions.xml to have the new channels added

In case you need any help, open a draft PR to openhab-addons and ping me @florian-h05 so I can have a look.

I’m afraid I’m missing the first step: where do I do the modifications? Do I download the files and modify them on my pc?

I’m not discouraging pursuing this, but it’s worth noting that the Astro binding has a moon thing that provides all the same information.

3 Likes

Don’t you mean line 297? In function updateCurrentChannel I see something about ‘sunrise’, but not in function getDailyForecastState…?

@florian-h05, where should I run this? And where should which files be located? :slight_smile:

Hi,

I want to emphasize this information! Everything is easily available (including moonPhase translations for most languages).
I have the openweathermap-binding and astro-binding running in parallel. With the astro-binding even a triggering of the events (sunrise, sunset…) is possible.

1 Like

You have to clone the openhab-addons repo GitHub - openhab/openhab-addons: Add-ons for openHAB to your PC and create a new branch, where you can do the required changes. Please read both the README and the CONTRIBUTING files in the root of the repo. Also read Developer Guide | openHAB.

updateCurrentChannel updates the channels with the current data, and looking at the OpenWeatherMap API docs you linked above, there is no moon data for current, only a daily forecast.
In line 663 inside getDailyForecastState is the handling for the daily sun forecast channels.

Once you have set up your local dev environment and cloned the repo and changed the channel-types.xml, you can run this command from the command line from the repo root.

Sure, but OpenWeatherMap provides daily forecast data for those moon data, which might be interesting as well … however I am not sure which data @ErikDB actually wants.

I quoted the wrong function… You directed me to line 629, but I don’t see anything adaptable in function updateDailyForecastTimeSeries.

In Windows command I navigated to C:\Users\[some more foldering until the folder in which I cloned the github]\openhab-addons\bundles. There I executed mvn i18n:generate-default-translations -pl :org.openhab.binding.openweathermap. This led to several minutes of things happening:

[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/openhab/openhab-super-pom/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/openhab/openhab-super-pom/maven-metadata.xml (521 B at 547 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/openhab/openhab-super-pom/1.0.6/openhab-super-pom-1.0.6.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/openhab/openhab-super-pom/1.0.6/openhab-super-pom-1.0.6.pom (6.6 kB at 205 kB/s)
Downloading from openhab-snapshot: https://openhab.jfrog.io/openhab/libs-snapshot/org/openhab/tools/sat/sat-extension/0.15.0/sat-extension-0.15.0.pom
Downloading from central: https://repo1.maven.org/maven2/org/openhab/tools/sat/sat-extension/0.15.0/sat-extension-0.15.0.pom
Downloaded from central: https://repo1.maven.org/maven2/org/openhab/tools/sat/sat-extension/0.15.0/sat-extension-0.15.0.pom (2.8 kB at 17 kB/s)
Downloading from openhab-snapshot: https://openhab.jfrog.io/openhab/libs-snapshot/org/openhab/tools/sat/pom/0.15.0/pom-0.15.0.pom
Downloading from central: https://repo1.maven.org/maven2/org/openhab/tools/sat/pom/0.15.0/pom-0.15.0.pom

(etc, but I need to trim down the characters in order to get this message posted...)

But then it ended with:

Downloaded from central: https://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream/1.4.20/xstream-1.4.20.jar (645 kB at 8.3 MB/s)
Downloading from central: https://repo1.maven.org/maven2/io/github/x-stream/mxparser/1.2.2/mxparser-1.2.2.jar
Downloading from central: https://repo1.maven.org/maven2/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar
Downloading from central: https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar
Downloaded from central: https://repo1.maven.org/maven2/io/github/x-stream/mxparser/1.2.2/mxparser-1.2.2.jar (30 kB at 824 kB/s)
Downloaded from central: https://repo1.maven.org/maven2/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar (7.2 kB at 109 kB/s)
Downloaded from central: https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar (258 kB at 2.3 MB/s)
[INFO] Reading: C:\Users\[some more foldering until the folder in which I cloned the github]\openhab-addons\bundles\org.openhab.binding.openweathermap\src\main\resources\OH-INF\addon\addon.xml
[INFO] Reading: C:\Users\[some more foldering until the folder in which I cloned the github]\openhab-addons\bundles\org.openhab.binding.openweathermap\src\main\resources\OH-INF\addon\desktop.ini
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:29 min
[INFO] Finished at: 2024-01-29T20:36:59+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openhab.core.tools:i18n-maven-plugin:4.2.0-SNAPSHOT:generate-default-translations (default-cli) on project org.openhab.binding.openweathermap: Execution default-cli of goal org.openhab.core.tools:i18n-maven-plugin:4.2.0-SNAPSHOT:generate-default-translations failed.: StreamException: ParseError at [row,col]:[1,1]
[ERROR] Message: Content is not allowed in prolog.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

…?

Yeah you are right, my fault. You only need to update getDailyForecastState.

Please try out from the repo root (without cding into bundles).

What exactly do you mean with “repo root”?
If I went up one level, this happened:

[INFO] Scanning for projects...
[INFO]
[INFO] ---< org.openhab.addons.bundles:org.openhab.binding.openweathermap >----
[INFO] Building openHAB Add-ons :: Bundles :: OpenWeatherMap Binding 4.2.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- i18n:4.2.0-SNAPSHOT:generate-default-translations (default-cli) @ org.openhab.binding.openweathermap ---
[INFO] Reading: C:\Users\[blabla]\openhab-addons\bundles\org.openhab.binding.openweathermap\src\main\resources\OH-INF\addon\addon.xml
[INFO] Reading: C:\Users\[blabla]\openhab-addons\bundles\org.openhab.binding.openweathermap\src\main\resources\OH-INF\addon\desktop.ini
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.178 s
[INFO] Finished at: 2024-01-29T21:28:15+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openhab.core.tools:i18n-maven-plugin:4.2.0-SNAPSHOT:generate-default-translations (default-cli) on project org.openhab.binding.openweathermap: Execution default-cli of goal org.openhab.core.tools:i18n-maven-plugin:4.2.0-SNAPSHOT:generate-default-translations failed.: StreamException: ParseError at [row,col]:[1,1]
[ERROR] Message: Content is not allowed in prolog.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

One more level up:

[INFO] Scanning for projects...
[ERROR] [ERROR] Could not find the selected project in the reactor: :org.openhab.binding.openweathermap @
[ERROR] Could not find the selected project in the reactor: :org.openhab.binding.openweathermap -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MavenExecutionException

C:\Users[some more foldering until the folder in which I cloned the github]\openhab-addons

That desktop.ini might be the problem, I wonder where it comes from (blame Windows). Seems that the i18n plugin tries to read it.

Anyway, ignore the i18n plugin for now and continue with the „real“ code changes.
Once you are finished and have opened a PR, I can take care of the translations if it still does not work on your system then.

I had put it all in a Google Drive file. The mvn command now seems to have worked. It did give only some 7 lines of output. Is that possible? (I stupidly closed the window without copying them.)

I’ll figure out what a PR is and how that works tomorrow :wink:

@florian-h05, I installed the Github CLI, and read up on the documentation (Creating a pull request - GitHub Docs). Although I don’t quite understand how that CLI knows to which repository I want to send this pull request… But I assumed that’ll become clear during the process.

But this gave me the following error:

Warning: 6 uncommitted changes
must be on a branch named differently than "main"

image

@florian-h05, I think I did it!

It did involve a lot of shots in the dark, so I’m not 100 % sure I did everything right. But it looks like I did “enough” to make it work, from where I sit. :wink:

1 Like

I didn’t know that.

I already had the openweathermap binding installed, as it’s used in the semantichomemenu I’ve embraced. So maybe I can integrate this moon information in the widget somehow.

And it looked like a feasible goal for a first try at doing something with Github. :slight_smile:

You would just link the same moon Items to the Astro Channels instead of the OWM channels.

Again, I’m not discouraging adding this to OWM. I just wanted to point out that OWM doesn’t provide any information that Astro doesn’t already offer too (after all lunar events are deterministic and not subject to weather conditions and the like).

1 Like

OWM provides moon data in the future, e.g. moonrise in ten days. I haven’t found that yet in the Astro binding.