OpenWeatherMap location config issue

Hey :slight_smile:

Running openhabian on snapshot #136 but problem was also on #131 (maybe earlier too)

I figured a problem with the OWM binding yesterday…I was wondering why I dont get updated data for the owm items… so I checked and noticed that i’ve got a error in my logs…

2020-06-01 10:57:36.150 [DEBUG] [nWeatherMapWeatherAndForecastHandler] - Update weather and forecast data of thing 'openweathermap:weather-and-forecast:f163c326:local'.
2020-06-01 10:57:36.159 [hingStatusInfoChangedEvent] - 'openweathermap:weather-and-forecast:f163c326:local' changed from OFFLINE (BRIDGE_OFFLINE) to OFFLINE (CONFIGURATION_ERROR): Der Parameter Ort muss konfiguriert werden.

“the parameter location must be configured”

This is my .things file:

Bridge openweathermap:weather-api:api "OpenWeatherMap Konto" @ "Accounts" [apikey ="APIKEY", refreshInterval =10, language ="de"] {
    Thing weather-and-forecast xx "OpenWeatherMap - Wetter xX" @ "Wetter" [location ="LAT.14Digits,LONG.15Digits,ALT", forecastHours =24, forecastDays =0]
}

This was working fine for quite a while… but dont know when exactly it stopped working and what have been changed in the last couple of days/weeks.

I also delete the things/items files… uninstalled the binding… cleaned cache and did a new install of the binding and thing config via PaperUI… Also no success…

Does anyone else have this problem too… do you have a clue what happend here @cweitkamp

Thanks for any help…
/Holger

Hi @kugelsicha,

The OWM binding uses a PointType for storing the user-defined location. I am not sure if it can handle latitude / longitude with such a number of digits. While looking into the code I realized that the binding swallows silently IAEs thrown by the PointType constructor. I will add a TRACE log for such cases.

To check if your location is the problem I suggest to create a PointType manually (e.g. in a Rule) passing the same location as String and eventually you will see the exception. If that will work nicely we have to dig deeper.

1 Like

Okay thanks for your reply… But it was working just fine days/weeks before with the exakt same location values… thats why i was wondering…

Will check later your suggesstion

Thanks

Hi,
I have the same problem. I guess the error came with commit

[openweathermap] bridge / thing handling (#7692)

The Weather & Forecast Thing is only initialized with the location when the bridge is online. The bridge is only online when a thing is using it (I’m not sure about that, but it looks like that to me).
Looks like a chicken / egg problem to me :smiley:

Code Snippet before the commit:

public void initialize() {
    OpenWeatherMapLocationConfiguration config = getConfigAs(OpenWeatherMapLocationConfiguration.class);

    boolean configValid = true;
    if (StringUtils.trimToNull(config.getLocation()) == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                "@text/offline.conf-error-missing-location");
        configValid = false;
    }

    try {
        location = new PointType(config.getLocation());
    } catch (IllegalArgumentException e) {
        location = null;
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                "@text/offline.conf-error-parsing-location");
        configValid = false;
    }
[...]

and after:

private void initializeThing(@Nullable ThingStatus bridgeStatus) {
    Bridge bridge = getBridge();
    BridgeHandler bridgeHandler = bridge != null ? bridge.getHandler() : null;
    if (bridgeHandler != null && bridgeStatus != null) {
        if (bridgeStatus == ThingStatus.ONLINE) {
            OpenWeatherMapLocationConfiguration config = getConfigAs(OpenWeatherMapLocationConfiguration.class);

            boolean configValid = true;
            if (StringUtils.trimToNull(config.getLocation()) == null) {
                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                        "@text/offline.conf-error-missing-location");
                configValid = false;
            }

            try {
                location = new PointType(config.getLocation());
            } catch (IllegalArgumentException e) {
                location = null;
                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                        "@text/offline.conf-error-parsing-location");
                configValid = false;
            }
	[...]

@cweitkamp I don’t think it’s the PointType, because that hasn’t changed.

1 Like

Thanks for spotting.

@Lolodomo Can you please have a look.

In case bridgeStatusChanged is called before initialize, config will not be set.
config has to be set in initializeThing.

Oups, this is what is done.
So the problem is probably only the bad value of the location setting. Please try with the expected format and tell us if the problem is solved.

@Lolodomo

I don’t think that’s the problem (although I haven’t seen the representation of the location from @kugelsicha yet).

My Location looks like e.g. 48.8588017508614,2.3990725335516894. I have also tried it with less decimal places and with/without altitude.

The problem is that the bridge status depends on the “child” things (from OpenWeatherMapAPIHandler.java):

private void determineBridgeStatus() {
    ThingStatus status = ThingStatus.OFFLINE;
    for (Thing thing : getThing().getThings()) {
        if (ThingStatus.ONLINE.equals(thing.getStatus())) {
            status = ThingStatus.ONLINE;
            break;
        }
    }
    updateStatus(status);
}    

For the Weather & Forecast thing to read the location from the config, the bridge must be online (see Code Snippet above), and the bridge only goes online when Weather & Forecast thing is online. Which only goes online when the bridge is online… and so on :smiley:

Or am I missing something?

Ok, that looks like a bad implementation. The bridge status should not depend on its children. It is the reverse that is expected.
I will have a look.

1 Like

Yeah, I have to agree with you there. I don’t know why it has been implemented like that.

Maybe this is to show the user that it is not enough to just add the Account/Bridge, but that you also need to add a thing that uses the bridge.

By the way, this is the same with the Dark Sky Binding.

I implemented it that way back in the days because I wanted to have a feedback from OWM API about valid apikey and / or location, etc… The binding itself only checks if parameters are set correctly and are compliant with openHAB standard. The rest has to be done by the OWM API. I guess there is a better way to set / determine the bridge status like my approach. I can have have a look too - if you like.

2 Likes

Maybe my PR has to be undone.

@cweitkamp : my PR was clearly pushed too fast, I did not see the unusual status management done on the bridge handler. My changes are not relevant considering the code in the bridge handler. I propose to simply undo my PR.

This is now reverted to previous handling.

1 Like

@Lolodomo

Many thanks, it works again as expected in Version 2.5.6 Build #137. :slightly_smiling_face:

Yes, can confirm this too… working again with snapshot #137

Thanks!