Read the statement by Michael Teeuw here.
How can I add more time periods for MMM-compliments?
-
So I know MMM-Compliments has 3 time periods by default (morning, afternoon and evening). I want to know, is it possible to add 1 or 2 more time periods like night and dusk?
I really enjoy being able to customize the compliments that come up, and would love to have more time slots that I could customize. -
@dæmoneyes That shouldn’t be too difficult.
complimentArray: function() { var hour = moment().hour(); var compliments = null; if (hour >= 3 && hour < 12) { compliments = this.config.compliments.morning; } else if (hour >= 12 && hour < 17) { compliments = this.config.compliments.afternoon; } else { compliments = this.config.compliments.evening; } ..... },Here is the function calling the hour of the day in MMM-Compliments.js.
You can easily give this a more precise sorting with more cases.
However, you would need to change the logic to a switch function, because there can only be one “else if” in an “if” statement.Fork the module, try it out!
-
@lavolp3 said in How can I add more time periods for MMM-compliments?:
owever, you would need to change the logic to a switch function, because there can only be one “else if” in an “if” statement.
not true, you can have as many as u want…
switch sometimes makes things more clear, but not always
-
This is actually my first time programming ever, so I don’t actually know what are logic or switch functions.
This is what I attempted, but it didn’t work, and instead the compliments module just didn’t load up when starting MM:
   -
@dæmoneyes your changes didn’t show
use the three back-tics before and after your code
on keyboard, left of the number 1 key -
@sdetweil Here are all the changes I tried: https://imgur.com/a/wbYQclq
-
@dæmoneyes start the mirror with
npm start devand in the white developers window, select the console tab,
scroll up/down to find any errors (red text)…I can’t see all your code, but its probably a missing quote, paren or brace
-
@sdetweil Did that, found some red related to compliments and also to openweather
Here is the full console tab: https://imgur.com/a/Lrn8kVH -
@dæmoneyes compliments.js:48 syntax error
that means on line 48 of the complements.js file the compiler found an error…
-
@sdetweil Once again, I owe you my thanks sdetweil! It works now!
What should I do about the red related to the openweathermap?
-
@dæmoneyes openweathermap… I do not know… sorry…
-
@sdetweil hey no problem, it seems to be working fine, so I guess I shouldn’t worry about it.
If I may ask one more question, should I do anything about the yellow warning ‘Electron Security Warning’?
-
@dæmoneyes if your mirror was open to the internet, then I would say yes
-
@sdetweil Hmm ok, besides weather and quote of the day, I’m not really connecting to the net for anything so I guess that’s fine.
Thanks again for helping me solve this! -
@DæmonEyes you only make changes in
MagicMirror/modules/default/compliments/MMM-Compliments.js
and of corse in the
MagicMirror/config/config.js?Can your Post your changes here in the Forum?
Here is a nice “HowTo” post a code into the Forum for better reading https://forum.magicmirror.builders/topic/4247/how-to-post-code-on-the-forum-for-absolute-beginnersThank you
-
@saschasp Actually I only had to make changes in the
MMM-compliments.jsand not theconfig.js
I just had to make changes at those 3 places that I showed in the imgur link I had posted and it works great.
sdetweil helped my find the missing comma that was causing the problem with thenpm start devprompt and now it works great.I now have 5 time periods and 3 compliments for each period. If I think of more compliments, I’ll probably add a 4th compliment for each period.
-
Is it normal for the default modules to reset to factory settings when updating MM?
Just did the MM update to 2.7.1 and noticed my compliments module has reset to its original compliments and time periods. -
yes, the default modules are part of the base… and will be reset… altho you should have been warned by git
if u did a git stash, then u can get those changes back
-
@sdetweil Oh ok, I just did my first stash now.
So let’s say I had done a stash before I had updated; how would I retrieve it after updating?(So I know what to do next time)
-
@DæmonEyes git stash pop
i don’t know if you can pop one file at a time
(ps… google is your friend!)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login