Met.no weather API plugin

The Content-Length and Content-Encoding are not necessary in this plugin. Just reporting it because they are standard headers and missing them could indicate that something is not right handling the responses. I just tested also with Android 3.19 and got the same undefined results…

But then other issue: the weather service which this plugin is querying is requesting to use If-Modified-Since header. If the server has new data it will respond with status 200 but if the data has not been changed since the date in this header the server response will be 304 status.

So my plugin should check that if response status is 200 then update values and if response status is 304 then do nothing. But now when testing if the response status is 304 then console shows message

Response status code does not indicate success: 304 (Not Modified).

and my plugin code is not executed anymore.
So is this intended behavior that plugin cannot receive all status responses or should it be able to receive all?

304 status is an error code. Those generate exceptions which will exit your code block. If you want to suppress those, you need to wrap your calls in a try-catch.

try {
    var response = http.get("http://eu.httpbin.org/gzip");
    console.log("Content-Encoding: " + response.headers["Content-Encoding"]);
    console.log("Content-Length: " + response.headers["Content-Length"]);
    console.log("Content-Type: " + response.headers["Content-Type"]);
} catch (error) {
    var errorResponse = error.response;
    if (error.status == 304) {
        console.log("304 code received");
    }
}

OK, thanks, using try-catch allows the plugin code to continue execution. For the catched object I can see only keys ‘message’ and empty ‘response’, no status code directly…

Anyways, I have now the Expires header and will work with that one to time the queries to API.

I’ve added the Plugin to THR, In the settings I’ve put the latitude, longitude and altitude, and I’ve downloaded and added all the images, but I cannot work out how to do the last bit and add it to my Home page. Thanks for any help.

The plugin creates a “Metno1” device with variables which can be used in dashboard whichever way user wants.

For example create a label and put weekday and temperature in two rows:

image

Or create image and point it to an icon:

image

I tried both examples several times but nothing appears, would it be possible for you to send me a small hrp test file to see if something appears. Thanks

OK, here the simplest example. One label with current weather conditions.

In plugin settings set latitude and longitude (I believe these are for London UK):
image

For label multibinding define what values will be displayed, here the current conditions

The result:
image

Make sure the latitude and longitude are given using point, not comma.

hrexample.hrp (814.8 KB)

Thank you very much. I could not understand what I done wrong because mine was identical to yours, the only difference I could find was I added an altitude so I set it back to 0 and bingo it started working. Thanks for a great plugin and the help.

Hi, is it possible for you to add the High weekday temps, Thanks.

I’ll have a look, should be simple. But will take some time because traveling this week.

Thanks Vpow, I did have a look myself but realised I was a little bit out of my depth messing around with the code.

I have now made available updated version with daily high and low temperatures. It is available in github development branch:

And the new attributes are:
"tempmin1","tempmin2","tempmin3","tempmin4","tempmin5","tempmin6","tempmin7", "tempmax1","tempmax2","tempmax3","tempmax4","tempmax5","tempmax6","tempmax7"

1 Like

Hi Vpow, thanks for the update.

Hi Vpow, is it possible to have the wind direction displayed with an arrow?

Well, in the plugin there is attribute winddirection_now which gives direction in degrees. And looks like icons can be rotated. So I would say it is possible.

Hi,I have been using wind direction now and it just displays a 360 degrees number, how would I attach an arrow icon to that number?

I investigated more how to create a wind direction arrow. While it is probably possible to use icon or image and somehow update the rotation property, I made other solution available directly in the plugin. (It is in the github development branch.)

The plugin now has new attribute “winddirection_now_arrow” which returns direction arrow as ascii character. The eight main directions are used. So now you can make a label and put “winddirection_now_arrow” as text value there.

image

EDIT: I got the arrows in wrong order in the beginning, now fixed.

1 Like

Hi Vpow, Wow that was quick, you certainly know your coding, thanks once again for the help and a great weather app

Hi, I tried looking for the development branch but was unable to find any files, would it be possible to give me a direct link to the file, Thanks.

The development branch is here:

And the file is right there:

1 Like