Read the statement by Michael Teeuw here.
Need help for a module who give advice because of the weather
-
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
-
use my sample module
https://github.com/sdetweil/SampleModuleand see the documentation on creating modules
https://docs.magicmirror.builders/development/introduction.htmlthere are lots of modules that use the openweather api,
including the default weather module. you can examine those for the specificsa 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 optionalthe latest browsers have built in fetch() so that one can request data from other web sites directly without needing the helper
-
@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
-
@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