Snow amount on weather forecast



  • Re: Weather Forecast Snow Amounts
    Please mark as solved.

    you can duplicate the rain amount like this:

    var nw = new Date(); // var new get error
            	if ((nw.getMonth() > = 0 && nw.getMonth() < = 2) || (nw.getMonth() > = 10 && nw.getMonth() < = 11)) { // snow amount show only in winter months
    				if (this.config.showSnowAmount) {
    					var snowCell = document.createElement("td");
    					if (isNaN(forecast.snow)) {
    						snowCell.innerHTML = "no snow";
    					} else {
    						if(config.units !== "imperial") {
    							snowCell.innerHTML = parseFloat(forecast.snow).toFixed(1).replace(".", this.config.decimalSymbol) + " mm";
    						} else {
    							snowCell.innerHTML = (parseFloat(forecast.snow) / 25.4).toFixed(2).replace(".", this.config.decimalSymbol) + " in";
    						}
    					}
    					snowCell.className = "align-right xsmall snow";
    					row.appendChild(snowCell);
    				}
    			}
    

    on processWeather you add:

    		day: day,
    		icon: this.config.iconTable[forecast.weather[0].icon],
    		maxTemp: this.roundValue(forecast.temp.max),
    		minTemp: this.roundValue(forecast.temp.min),
    		rain: this.processRain(forecast, data.list),
    		snow: this.processSnow(forecast, data.list) // snow amount
    

    then after processRain you add processSnow:

    processSnow: function(forecast, allForecasts) {
    		//If the amount of snow actually is a number, return it
    		if (!isNaN(forecast.snow)) {
    			return forecast.snow;
    		}
    
    		//Find all forecasts that is for the same day
    		var checkDateTime = (!!forecast.dt_txt) ? moment(forecast.dt_txt, "YYYY-MM-DD hh:mm:ss") : moment(forecast.dt, "X");
    		var daysForecasts = allForecasts.filter(function(item) {
    			var itemDateTime = (!!item.dt_txt) ? moment(item.dt_txt, "YYYY-MM-DD hh:mm:ss") : moment(item.dt, "X");
    			return itemDateTime.isSame(checkDateTime, "day") && item.snow instanceof Object;
    		});
    
    		//If no snow this day return undefined so it wont be displayed for this day
    		if (daysForecasts.length == 0) {
    			return undefined;
    		}
    
    		//Summarize all the snow from the matching days
    		return daysForecasts.map(function(item) {
    			return Object.values(item.snow)[0];
    		}).reduce(function(a, b) {
    			return a + b;
    		}, 0);
    	}
    

    also on defaults you can add:

    showSnowAmount: true, // only for winter months
    

    result:

    https://github.com/hangorazvan/smartmirror/blob/master/modules/forecast/Screenshot (4).png


  • Project Sponsor

    @hango Please answer in the question thread instead of creating a new one.



  • @broberg OK, sorry
    When I wanted to reply in the thread I got this suggestion:

    The topic you are replying to is quite old. Would you like to create a new topic instead, and reference this one in your reply?


  • Project Sponsor

    @hango nevertheless, easier to keep things in one thread. That questions is there so one don’t accidentally brings up a dead thread.