ariela
(Andrea Riela)
April 25, 2022, 10:00am
41
But I have another question @Wolfgang1966
Considering the weather warnings, and type/level (that now are both included in the “event” item) is there any other option than use a transformation for having split event and level of warning?
thanks
Andrea
Hi @ariela ,
I’m afraid that trying to semantically interpret the “event” wording is more that error prone. The weather alerts come from multiple sources ( One Call API: weather data for any geographical coordinate - OpenWeatherMap ). Depending on the source wording might be different, so I think a transformation based on the specific alerts you receive is the best way to handle them. The alerts API Global Weather Alerts - OpenWeatherMap provides a more detailed response with the attributes you need but unfortunately is not available for free and not (yet?) supported by the binding.
2 Likes
ariela
(Andrea Riela)
April 25, 2022, 2:44pm
43
Playing with some features in the sitemap, I’ve perhaps found a good compromise
Let me know what you think
my items:
String OpenWeatherMap_Alerts1_Event "[%s]" (gWeather) { channel="openweathermap:onecall:api:local:alerts1#event" }
String OpenWeatherMap_Alerts1_Description "[%s]" (gWeather) { channel="openweathermap:onecall:api:local:alerts1#description" }
DateTime OpenWeatherMap_Alerts1_Onset "[%1$td/%1$tm - %1$tH:%1$tM]" (gWeather) { channel="openweathermap:onecall:api:local:alerts1#onset" }
DateTime OpenWeatherMap_Alerts1_Expires "[%1$td/%1$tm - %1$tH:%1$tM]" (gWeather) { channel="openweathermap:onecall:api:local:alerts1#expires" }
String OpenWeatherMap_Alerts1_Source "[%s]" (gWeather) { channel="openweathermap:onecall:api:local:alerts1#source" }
String Converted_OpenWeatherMap_Alerts1_Duration "[%s]" (gWeather)
the item “Converted_OpenWeatherMap_Alerts1_Duration” is just the result of a concat rule (onset + expires).
my sitemap:
Text item=Converted_OpenWeatherMap_Alerts1_Duration label="Moderate" icon="meteoalarm_thunder2" visibility=[OpenWeatherMap_Alerts1_Event=="Yellow Thunderstorm Warning"]
Text item=Converted_OpenWeatherMap_Alerts1_Duration label="Severe" icon="meteoalarm_thunder3" visibility=[OpenWeatherMap_Alerts1_Event=="Orange Thunderstorm Warning"]
Text item=Converted_OpenWeatherMap_Alerts1_Duration label="Extreme" icon="meteoalarm_thunder4" visibility=[OpenWeatherMap_Alerts1_Event=="Red Thunderstorm Warning"]
in this way you have enough flexibility how the “event” wording is done from the specific source of your Country.
The result is not that bad
edit: I’m using a orange/red/purple scheme for my icons, as the yellow is not visible enough
ariela
(Andrea Riela)
April 26, 2022, 5:28am
44
I’m sorry, but it seems the issue stands.
Not sure what I’m missing but I have always a UNDEF value for each item. But if I try to check via a normal http request (like: https://api.openweathermap.org/data/2.5/onecall?lat=45.465051&lon=9.094615&&appid=xxxxxxxxxx ) I can see now data in eg. alerts.0.event (Yellow Thunderstorm Warning).
Here my items:
String OpenWeatherMap_Alerts1_Event "[%s]" (gWeather) { channel="openweathermap:onecall:api:local:alerts1#event" }
String OpenWeatherMap_Alerts1_Description "[%s]" (gWeather) { channel="openweathermap:onecall:api:local:alerts1#description" }
DateTime OpenWeatherMap_Alerts1_Onset "[%1$td/%1$tm - %1$tH:%1$tM]" (gWeather) { channel="openweathermap:onecall:api:local:alerts1#onset" }
DateTime OpenWeatherMap_Alerts1_Expires "[%1$td/%1$tm - %1$tH:%1$tM]" (gWeather) { channel="openweathermap:onecall:api:local:alerts1#expires" }
String OpenWeatherMap_Alerts1_Source "[%s]"
here my things file:
Bridge openweathermap:weather-api:api "OpenWeatherMap Account" @ "Accounts" [apikey="xxxxxxxxxxxxxxxxxxxxx", refreshInterval=10, language="en"] {
Thing onecall local "Weather And Forecast - Local" @ "Outdoor" [location="45.465051,9.094615", forecastHours=24, forecastDays=6, numberOfAlerts=5]
}
What I’m missing?
Andrea
ariela
(Andrea Riela)
April 26, 2022, 7:31am
45
Now I see the first warning correctly, and matching what I can see with a HTTP request (yellow thunderstorm warning).
But, with the HTTP request I can see also the second warning … that is not visible via binding (yellow rain warning).
of course the second group of items is identical
String OpenWeatherMap_Alerts2_Event "[%s]" (gWeather) { channel="openweathermap:onecall:api:local:alerts2#event" }
String OpenWeatherMap_Alerts2_Description "[%s]" (gWeather) { channel="openweathermap:onecall:api:local:alerts2#description" }
DateTime OpenWeatherMap_Alerts2_Onset "[%1$td/%1$tm - %1$tH:%1$tM]" (gWeather) { channel="openweathermap:onecall:api:local:alerts2#onset" }
DateTime OpenWeatherMap_Alerts2_Expires "[%1$td/%1$tm - %1$tH:%1$tM]" (gWeather) { channel="openweathermap:onecall:api:local:alerts2#expires" }
String OpenWeatherMap_Alerts2_Source "[%s]" (gWeather) { channel="openweathermap:onecall:api:local:alerts2#source" }
String Converted_OpenWeatherMap_Alerts2_Duration "[%s]" (gWeather)
boehan
(Hans Böhm)
May 6, 2022, 9:11am
46
@ariela
I had a quick look at the code and probably found the issue.
In the following if
statement it should be alerts.size() >= count
instead. Otherwise, I think, the last alert in the API response is always ignored (or not updated, respectively).
*
* @param channelUID the id identifying the channel to be updated
* @param count
*/
private void updateAlertsChannel(ChannelUID channelUID, int count) {
String channelId = channelUID.getIdWithoutGroup();
String channelGroupId = channelUID.getGroupId();
OpenWeatherMapOneCallAPIData localWeatherData = weatherData;
List<Alert> alerts = localWeatherData != null ? localWeatherData.alerts : null;
State state = UnDefType.UNDEF;
if (alerts != null && alerts.size() > count) {
Alert alert = alerts.get(count - 1);
switch (channelId) {
case CHANNEL_ALERT_EVENT:
state = getStringTypeState(alert.event);
break;
case CHANNEL_ALERT_DESCRIPTION:
state = getStringTypeState(alert.description);
break;
case CHANNEL_ALERT_ONSET:
state = getDateTimeTypeState(alert.start);
@Wolfgang1966 what do you think?
2 Likes
boehan
(Hans Böhm)
May 7, 2022, 4:04pm
47
I submitted a PR that should fix the issue
openhab:main
← boehan:owm_fix_alerts
opened 04:02PM - 07 May 22 UTC
Signed-off-by: Hans Böhm <h.boehm@gmx.at>
<!--
Thanks for contributing to th… e openHAB project!
Please describe the goal and effect of your PR here.
Pay attention to the below notes and to *the guidelines* for this repository.
Feel free to delete any comment sections in the template (starting with "<!--").
ATTENTION: Don't use "git merge" when working with your pull request branch!
This can clutter your Git history and make your PR unuseable.
Use "git rebase" instead. See this forum post for further details:
https://community.openhab.org/t/rebase-your-code-or-how-to-fix-your-git-history-before-requesting-a-pull/129358
Add one or more appropriate labels to make your PR show up in the release notes.
E.g. enhancement, bug, documentation, new binding
This can only be done by yourself if you already contributed to this repo.
If your PR's code is not backward compatible with previous releases (which
should be avoided), add a message to the release notes by filing another PR:
https://github.com/openhab/openhab-distro/blob/main/distributions/openhab/src/main/resources/bin/update.lst
# Title
Provide a short summary in the *Title* above. It will show up in the release notes.
For example:
- [homematic] Improve communication with weak signal devices
- [timemachine][WIP] Initial contribution
# Description
Please give a few sentences describing the overall goals of the pull request.
Give enough details to make the improvement and changes of the PR understandable
to both developers and tech-savy users.
Please keep the following in mind:
- What is the classification of the PR, e.g. Bugfix, Improvement, Novel Addition, ... ?
- Did you describe the PRs motivation and goal?
- Did you provide a link to any prior discussion, e.g. an issue or community forum thread?
- Did you describe new features for the end user?
- Did you describe any noteworthy changes in usage for the end user?
- Was the documentation updated accordingly, e.g. the add-on README?
- Does your contribution follow the coding guidelines:
https://www.openhab.org/docs/developer/guidelines.html
- Did you check for any (relevant) issues from the static code analysis:
https://www.openhab.org/docs/developer/bindings/#include-the-binding-in-the-build
- Did you sign-off your work:
https://www.openhab.org/docs/developer/contributing.html#sign-your-work
# Testing
Your pull request will automatically be built and available under the following folder:
https://openhab.jfrog.io/ui/native/libs-pullrequest-local/org/openhab/addons/bundles/
It is a good practice to add a URL to your built JAR in this pull request description,
so it is easier for the community to test your Add-on.
If your pull request contains a new binding, it will likely take some time
before it is reviewed and processed by maintainers.
That said, consider submitting your Add-on in the Marketplace:
https://community.openhab.org/c/marketplace/69
Don't forget to submit a thread about your Add-on in the openHAB community:
https://community.openhab.org/c/add-ons
-->
This fixes an issue where the last alert in the API response is always ignored. Also discussed in [the forum](https://community.openhab.org/t/openweathermap-new-one-call-api/101419/45).
EDIT: seems it was just quick enough to make it into OH 3.3 M5
2 Likes
ariela
(Andrea Riela)
May 8, 2022, 8:12am
48
Thank you guy appreciated
Andrea
ariela
(Andrea Riela)
May 9, 2022, 2:58pm
49
@boehan unfortunately it seems not fixed yet on 3.3.M5. Now there is a warning in openweathermap, but this is not reflected in the binding
Andrea
boehan
(Hans Böhm)
May 10, 2022, 8:18am
50
Hmm… I will check in the evening, but I’m actually not sure if the fix really made it into the M5 release. Even though it is listed in the release notes , I can’t find it in the build summary . @Kai could you please confirm if the release notes for M5 are correct and #12697 made it into the release?
@ariela you could try to install the fixed binding manually → JAR file: JFrog
ariela
(Andrea Riela)
May 10, 2022, 8:19am
51
I’ll do and back to you as soon as I’ll see other warnings here
Kai
(Kai Kreuzer)
May 11, 2022, 7:52pm
52
I can confirm that the release notes are NOT correct as I have just checked the listed changes on our Jenkins at openhab-milestone 3.3.0.M5 (#51) Changes [Jenkins] and this PR does not turn up there. It must have been merged slightly after the add-ons build started and just before I compiled the release notes.
I have now corrected the release notes and have to ask for your patience as the fix will then only be in M6.
1 Like
boehan
(Hans Böhm)
May 12, 2022, 6:18am
53
Thanks for confirmation, at least we know now why binding behavior is unchanged
Actually, I wouldn’t have expected it to make it into release when I made the PR if it wasn’t merged so surprisingly fast and listed in the release notes…
1 Like
ariela
(Andrea Riela)
May 12, 2022, 3:11pm
54
@Kai @boehan thanks for your support here really appreciated
Andrea
ariela
(Andrea Riela)
June 6, 2022, 10:08am
55
I’m happy to say, 3.3.0 M6 fixed the issue, and now it works like a charm
thanks Hans for your support here
Andrea