Magicmirror: New weather module: forecast and forecast/daily support

Created on 5 Jan 2019  路  11Comments  路  Source: MichMich/MagicMirror

Hi everybody,
I implemented the support for forecast and forecast/daily using openweathermap in PR #1514. As I did not have a apiKey to test the forecast/daily part, I downloaded a sample file from their website and included it in my testing. I am not sure if all cases are handled well, please do check, if you find any other issues.

Thank you very much @fewieden and @vincep5 for you hints and support!

Also before merging my code, we should discuss, if my code is looking as it should:

This part appears twice in the hourly forecast part and a third time (similarly) in the daily forecast part.

minTemp.push(forecast.main.temp_min);
maxTemp.push(forecast.main.temp_max);

if (forecast.hasOwnProperty("rain")) {
    if (this.config.units === "imperial" && !isNaN(forecast.rain["3h"])) {
        rain += forecast.rain["3h"] / 25.4;
    } else if (!isNaN(forecast.rain["3h"])){
        rain += forecast.rain["3h"];
    } else {
        rain += 0;
    }
} else {
    rain += 0;
}

Have a nice weekend!

wontfix

Most helpful comment

Rain values of 0 should not be displayed anymore, also I simplified the code. One appearance of the code mentioned above was not required!

All 11 comments

Thanks, looks great. I took the code and put in directly in my directory. It works for my /forecast/daily. Just 1 small thing. When the rain is 0 we should hide it from displaying: in weather.js line 201 : we can put if (isNaN(value) || value == 0) {

Rain values of 0 should not be displayed anymore, also I simplified the code. One appearance of the code mentioned above was not required!

I've been trying to get the forecast to work with the new weather module. Weather works fine (for openweathermap not darksky), but if I add config for "forecast" in using either openweathermap or darksky I get "Loading …" as the header above the daily forecast.

        {
            module: "weather",
            position: "top_right",
            config: {
                // See 'Configuration options' for more information.
                type: 'forecast',
                weatherProvider: "openweathermap",
                location: "Holliston",
                locationID: "4939693",  
                apiKey: mykeyxxx,
                weatherEndpoint: "/forecast",
                useBeaufort: false,
                roundTemp: true
            }
        },
        {
            module: "weather",
            position: "top_right",
            config: {
                type: "forecast",
                weatherProvider: "darksky",
                apiBase: 'https://cors-anywhere.herokuapp.com/https://api.darksky.net',
                apiKey: mykeyxxx,
                lat: 42.184,
                lon: -71.431,
                weatherEndPoint: "/forecast"
            }
        },

Any suggestions for how to research this further??

Are you on the dev-branch? If not, the "/forecast"-Endpoint will not work until the next release.

@fwitte thanks, no I was not. I'll give it a try again.

i try this new module , and i have same problem "Loading …"
when i want forecast with openwatermap:
module: "weather", position: "top_right", config: { // See 'Configuration options' for more information. type: 'forecast', colored: true, apiKey: "myapiKey", }

Else, i think it's better if you change in weather.css
line-height: 65px; by
line-height: 30px;

I've pulled down the latest update from the develop branch (#1538). This cleans up the Loading … but now just shows Loading .... I can get the forecast from darksky, but not from openweathermap. I uncommented the line in forecast.njk to show the dump of forecast, but this just returns null. My config entry looks like:

        {
            module: "weather",
            position: "top_left",
            config: {
                type: 'forecast',
                weatherProvider: "openweathermap",
                locationID: "4939693",  
                apiKey: "mykeyxxx",
                weatherEndpoint: "/forecast"
            }
        },

What should I look at next?

Try browsing to your MM via IP address and check the developer toolbar or similar in your browser. It might have some JS errors or more information

Thanks, I see this error:

openweathermap.js:55 Could not load data ...  TypeError: Cannot read property '3h' of undefined
    at Class.generateWeatherObjectsFromForecast (openweathermap.js:139)
    at fetchData.then.data (openweathermap.js:51)

Okay, I played around with the config settings. I looked at the API and it recommended only passing the location ID to insure an accurate result. Although not shown above apparently I also had location: . I removed it as above and it is now returning a result. Sorry for the distraction. Although, you may want to consider removing location: from config settings. @vincep5 Thanks for your help.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shadowtag picture shadowtag  路  6Comments

sharmmoh1983 picture sharmmoh1983  路  12Comments

vvzvlad picture vvzvlad  路  7Comments

ostfilinchen picture ostfilinchen  路  5Comments

3vidar picture 3vidar  路  6Comments