• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.

Need help for a module who give advice because of the weather

Scheduled Pinned Locked Moved Development
4 Posts 3 Posters 157 Views 3 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.
  • X Offline
    Xx_Codeur_xX
    last edited by Apr 4, 2025, 1:32 PM

    So I’m building a magic mirror and I am trying to create my first module which could give advice to people according to the weather, but It’s my first time coding and I don’t understand how to collect the weather data from OpenCallWeather API and use it in my code. And I also don’t understand how to create a module from the start, I looked the MMM-Template but I don’t understand where I need to put my code.

    Thank you in advance for the time you’ll give me

    S M 3 Replies Last reply Apr 4, 2025, 1:54 PM Reply Quote 0
    • S Away
      sdetweil @Xx_Codeur_xX
      last edited by sdetweil Apr 4, 2025, 10:21 PM Apr 4, 2025, 1:54 PM

      @Xx_Codeur_xX

      use my sample module
      https://github.com/sdetweil/SampleModule

      and see the documentation on creating modules
      https://docs.magicmirror.builders/development/introduction.html

      there are lots of modules that use the openweather api,
      including the default weather module. you can examine those for the specifics

      a module creates a small section of web content. typically part of the body section of a web page

      MagicMirror will call the function getDom() to get this content
      if you want to update the content at a later time, you inform MagicMirror by calling updateDom(), and MagicMirror will call again at getDom()

      everything else in the module is about getting the info needed to supply getDom() with the info it needs

      a web browser (electron, chrome, firefox, edge…) cannot read files directly or access hardware, for security reasons.
      so MagicMirror provides support for a helper (node_helper.js) that runs outside the browser, and functions to send a message to it and receive a response
      the helper is optional

      the latest browsers have built in fetch() so that one can request data from other web sites directly without needing the helper

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • S Away
        sdetweil @Xx_Codeur_xX
        last edited by Apr 6, 2025, 1:46 PM

        @Xx_Codeur_xX one way to develop is to create a standalone web page, xxx.html and use the browser to view that

        this gets all your css and script dependencies worked out

        then you take the smallest section of the body that makes your content visible (div, table, canvas…)

        and make document. crreateElement(type) js api calls to create each

        because you so that do much, in one of my modules i created a little function

        createEl : function (type, id, className, parent, value) {
        		var el= document.createElement(type)
        		if(id)
        			el.id = id
        		if(className)
        			el.className = className
        		if(parent)
        			parent.appendChild(el)
        		if(value) {
        			var e = document.createTextNode(value)
        			el.appendChild(e)
        		}
        		return el
        	},
        

        which lets you do all the things at once create it fill in class names, attach to parent (building the tree of elements), set a value

        see the bottom of my birthday list module for how i used it

        https://github.com/sdetweil/birthdaylist/blob/master/birthdaylist.js

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • M Offline
          mumblebaj Module Developer @Xx_Codeur_xX
          last edited by Apr 6, 2025, 2:10 PM

          @Xx_Codeur_xX You could have a look at some of the modules that already does this. They get the weather from the default weather module, no need to redo this as it is already available.

          See either of the below.
          https://github.com/fruestueck/MMM-WeatherDependentClothes
          or
          https://github.com/Lavve/MMM-WeatherOutfit/tree/main

          Check out my modules at: https://github.com/mumblebaj?tab=repositories

          1 Reply Last reply Reply Quote 2
          • 1 / 1
          1 / 1
          • First post
            1/4
            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