MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Wind Direction (Compass Points)

    Scheduled Pinned Locked Moved Utilities
    2 Posts 1 Posters 3.2k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • zydecat74Z Offline
      zydecat74
      last edited by KirAsh4

      One aspect of the weather module I found was missing was the wind direction. Open Weather produces a wind direction as a number in degrees, however I prefer the compass points.

      For anyone interested in my code in the currentweather.js file:

      1. For the main display of wind speed and direction (I’ve also got rid of the Beaufort speeds and changed it back to km/h) my code is as follows:
      var windSpeed = document.createElement("span");
      windSpeed.innerHTML = " " + this.windSpeed + "km/h " + this.windDirection;
      small.appendChild(windSpeed);
      
      1. In the “processWeather” function I have the following:
      processWeather: function(data) {
      		this.temperature = this.roundValue(data.main.temp);
      		this.windSpeed = this.roundValue((data.wind.speed)* 60 * 60 / 1000);
      		this.windDeg = data.wind.deg;
      		this.windDirection = this.deg2dir(this.windDeg);
      		this.weatherType = this.config.iconTable[data.weather[0].icon];
      

      From this function I removed the coversion to the Beaufort scale and added a windSpeed variable to convert metres per second to km/h. Then I have two lines, one giving me the current wind direction in degrees (windDeg) and windDirection which I convert below…

      1. My deg2dir function is a simple nested array which converts the numerical degrees value into a compass point direction:
      deg2dir: function(windDeg) {
      		var degrees = [[11.25,"N"],[33.75,"NNE"],[56.25, "NE"],[78.75, "ENE"],[101.25, "E"], [123.75,"ESE"], [146.25,"SE"],[168.75, "SSE"],[191.25,"S"],[213.75, "SSW"],[236.25, "SW"],[258.75, "WSW"],[281.25,"W"],[303.75,"WNW"],[326.25,"NW"],[348.75,"NNW"],[360, "N"]];
      			for (var i=0; i<degrees.length; i++) {
      			var direction = degrees[i][0];
      			if (direction > windDeg) {
      				return degrees[i][1];
      			}
      		}
      		return "";
      	},
      

      Hope this is of use to someone who is looking for alternative data to display.

      Cheers,

      Mat

      Note from Moderator: Please use Markdown on code snippets for easier reading.

      Te audire non possum. Musa sapientum fixa est in aure.

      1 Reply Last reply Reply Quote 1
      • zydecat74Z Offline
        zydecat74
        last edited by

        It seems that since I have updated my mirror to the live version 2 (was working on v2-beta for some time) that there has been very similar code included in the latest version to cater for wind direction, as well as the option to not use the Beaufort scale for wind speed.

        I’ll have to come up with some new code to blow your minds with…

        Cheers,

        Mat

        Te audire non possum. Musa sapientum fixa est in aure.

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Enjoying MagicMirror? Please consider a donation!
        MagicMirror created by Michael Teeuw.
        Forum managed by Sam, technical setup by Karsten.
        This forum is using NodeBB as its core | Contributors
        Contact | Privacy Policy