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.

    Is there a way to show specific compliments on specific dates?

    Scheduled Pinned Locked Moved Troubleshooting
    21 Posts 6 Posters 16.5k Views 6 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.
    • C Offline
      CyanKali
      last edited by

      Hi,

      sorry if this is the wrong category for my question but the other categories don´t seem to fit either.

      I want to show messages on specific dates, like “Happy Birthday!” on my birthday. Those messages shall be shown just like regular compliments and in addition to the compliments. Is there an addon for the compliments module to achieve this?

      1 Reply Last reply Reply Quote 0
      • romainR Offline
        romain
        last edited by romain

        I don’t know if there is one but you could very simply modify the compliment module to do so.
        just add

         if (moment().format('MMM D') == 'Apr 27')
             complimentText = "Happy birthday"
        

        to replace compliment by happy birthday on that date.
        In the getDom function under var complimentText = this.randomCompliment(); and you should good to go. just change the date to match your birthday. (it’s always the first 3 letter of the month. the first letter as to be capital. the number is 1 to 31 (not 01 or 02 or 03 etc… directly 1 or 2 or 3 …)

        You can add more if to add more specific message en specific date. you could also creat a new variable in the config array and compare the moment().format directly to that variable so you can set it up from the config file. You could even make that variable an array of date and encapsulate the if into a for and compare each date of that array to the moment().format so you can add as many date as you want.

        C 1 Reply Last reply Reply Quote 0
        • P Offline
          pauabaer
          last edited by pauabaer

          @romain How to integrate the “Happy Birthday”-feature without using the compliments module? I mean i dont want to see such compliments, but on two specific dates i want to see the congratulations. how would i have to configure that module?

          ps:sorry for hijacking ;)

          C 1 Reply Last reply Reply Quote 0
          • C Offline
            CyanKali @romain
            last edited by CyanKali

            @romain said in Is there a way to show specific compliments on specific dates?:

            if (moment().format(‘MMM D’) == ‘Apr 27’)
            complimentText = “Happy birthday”

            Thank you for your help @romain !
            I tried it but it does not work.
            The config file of the compliments module now looks like this:

            // Override dom generator.
               getDom: function() {
               	var complimentText = this.randomCompliment();
            			if (moment().format('MMM D') == 'Apr 27')
               			 complimentText = "Happy birthday"
               	var compliment = document.createTextNode(complimentText);
               	var wrapper = document.createElement("div");
               	wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
               	wrapper.appendChild(compliment);
            
               	return wrapper;
            

            But the mirror shows only the normal compliments.

            Does this code add the birthday message to the normal compliments or does it replace them so that only happy birthday is shown on this day? If it is added, maybe I just need to wait longer until it is shown at random?

            I think I kind of understood what you explained in the last part, but I would not know how to do this, sorry. I think you described how I would be able to add dates in the config file of the mirror instead of the config of the compliments module, didn´t you? I would like to do this, would you mind explaining it a little more detailed?

            Thank you for your help!

            1 Reply Last reply Reply Quote 0
            • C Offline
              CyanKali @pauabaer
              last edited by

              @pauabaer

              as you can see I don´t know much about coding, but have you tried just deleting all the default compliments and then adding the line that romain suggested?

              romainR 1 Reply Last reply Reply Quote 0
              • romainR Offline
                romain @CyanKali
                last edited by

                @CyanKali It should have replace all compliment. At that particular date.
                well, yesterday was the 26 right ? you let the 27 so I guess it just wasn’t the rigth date to activate.
                Try changing the date. (well, today must be the 27 so It should work today ahah).

                @pauabaer you could use the compliment module. add the thing I had and then go on the config.js file and replace all the compliments by empty strings so it will display nothing when not the date

                                {                                                                                                                                                                                                                            
                                        module: "compliments",                                                                                                                                                                                               
                                        position: "lower_third",                                                                                                                                                                                             
                                        header: "",                                                                                                                                                                                                          
                                        config: {                                                                                                                                                                                                            
                                                compliments: {                                                                                                                                                                                               
                                                        anytime: [ "" ],                                                                                                                                                                                                   
                                                        morning: [ "" ],                                                                                                                                                                                                   
                                                        afternoon: [ "" ],                                                                                                                                                                                                   
                                                        evening: [  "" ]                                                                                                                                                                                                    
                                                }                                                                                                                                                                                                            
                                        }                                                                                                                                                                                                                    
                                },
                

                Or you could change the code so the module hide itself when the date isn’t right

                        // Override dom generator.                                                                                                                                                                                                           
                        getDom: function() {
                            var complimentText = this.randomCompliment();
                            if (moment().format('MMM D') == 'Apr 27')
                            {
                                this.show();
                                complimentText = "Happy birthday"
                            }
                            else
                                this.hide();
                            var compliment = document.createTextNode(complimentText);
                            var wrapper = document.createElement("div");
                            wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
                            wrapper.appendChild(compliment);
                
                                return wrapper;
                        },
                
                C 1 Reply Last reply Reply Quote 1
                • P Offline
                  pauabaer
                  last edited by

                  thanks @romain
                  i think the second way will be mine. what do i have to write in the config.js file? how can i integrate a second date?

                  romainR 1 Reply Last reply Reply Quote 0
                  • romainR Offline
                    romain @pauabaer
                    last edited by romain

                    @pauabaer for the config file, you can just use the default one. we didn’t change much with that code.
                    To add another date, just add as many else if () statement as needed. This isn’t a pretty solution but it will work.

                            // Override dom generator.                                                                                                                                                                                                           
                            getDom: function() {
                                var complimentText = this.randomCompliment();
                                if (moment().format('MMM D') == 'Apr 27')
                                {
                                    this.show();
                                    complimentText = "Happy birthday"
                                }
                             else if (moment().format('MMM D') == 'Apr 28') {
                                     this.show();
                                    complimentText = "Happy 28th day"
                    
                             }  else
                                    this.hide();
                                var compliment = document.createTextNode(complimentText);
                                var wrapper = document.createElement("div");
                                wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
                                wrapper.appendChild(compliment);
                    
                                    return wrapper;
                            },
                    

                    It’s not a pretty solution. I could made it prettier by creating a separate function with a while abd set a variable in the config section so you can add as many date as you want by editing the config.js. But I’m lazy so … yeah, not pretty solution.

                    1 Reply Last reply Reply Quote 0
                    • P Offline
                      pauabaer
                      last edited by

                      yeah @romain. sounds for me as if this solution is very easy at all. you dont blow up the code with two more else if-statements.

                      But with a separate function you could pimp up the module.
                      Think about annual festivals like:

                      • eastern --> Happy Eastern
                      • christmas --> Merry Christmas
                      • birthdays --> Happy Birthday

                      etc.

                      Perhaps you can overcome the laziness :grin:

                      romainR 1 Reply Last reply Reply Quote 0
                      • romainR Offline
                        romain @pauabaer
                        last edited by

                        @pauabaer Na, perhaps you can make it youself ;)
                        It’s not that hard, just read about array and function in javascript.
                        The idea is :
                        -You creat a function.
                        -You creat a variable in the config part. the variable should be an array. The easiest thing would be to make it an array of dictionnaries. So you can put a date and a message in each ones.
                        -Inside the function you stock the value of moment().format(‘MMM D’) in a variable
                        -Then you make a for that iterate on each element of the array an compare the value of moment().format(‘MMM D’) that you just got to the date part of each dictionary.
                        -If there is a match, you return the associate message. if not, you just return an empty string.
                        -In the getDom function you call that function instead of the randomCompliment

                        And you should be fine.
                        And hey, if you succeed you’ll could be proud to say you did a module yourself (sort of) !

                        1 Reply Last reply Reply Quote 0
                        • P Offline
                          pauabaer
                          last edited by

                          @romain sounds logic. but i dont have any knowledge about javascript. so i have to start from scratch. i dont know…i think for now your workaround sounds best :D

                          strawberry 3.141S 1 Reply Last reply Reply Quote 0
                          • strawberry 3.141S Offline
                            strawberry 3.141 Project Sponsor Module Developer @pauabaer
                            last edited by

                            @pauabaer as you dont have coding experience I guess you have neither experience with git. By modifying the files you will not be able to easily update the magicmirror.

                            Please create a github issue if you need help, so I can keep track

                            1 Reply Last reply Reply Quote 0
                            • P Offline
                              pauabaer
                              last edited by

                              @strawberry-3-141 you are right. i have read about this and i am aware of that fact. means a default function would be better. so i hope @romain can overcome the laziness :sunglasses:

                              ps @romain i hope you know how i meant this. you do what you want to do. because i dont have any coding experience i can only speak out some wishes/ features to make this project (for more people) a bit more “magically”.

                              romainR 1 Reply Last reply Reply Quote 0
                              • romainR Offline
                                romain @pauabaer
                                last edited by

                                @pauabaer sure, however, I have other projects to work on so I rather focus on them. I don’t have that much knowledge in javascipt either. (I do have some knowledge in other language though). When I do stuff it’s a lot a trial and error until that work (even for the tiny bit of code I made in this post required some research from me. Not a lot of it… but some. I never used the moments() function before)
                                This is your opportunity to gain knowledge.

                                1 Reply Last reply Reply Quote 0
                                • C Offline
                                  CyanKali @romain
                                  last edited by

                                  @romain I live in Germany, at the time I posted it was already the 27th here :) It still does not work, even though now it is the 27th pretty much everywhere in the world. Do you have any idea what might be the reason when you look at the code I posted?

                                  romainR 1 Reply Last reply Reply Quote 0
                                  • romainR Offline
                                    romain @CyanKali
                                    last edited by

                                    @CyanKali I live in french so it should be pretty much the same date. Try debugging.
                                    add the following line just before the if
                                    console.log('The date is : "' + moment().format('MMM D , h:mm a')+'"')
                                    Then run the mirror in dev mode . (go into the MagicMirror folder and run DISPLAY=:0 npm start dev) choose the tab “console”. And wait to see the message “the date is blablabla” apear and copy past the message here so we know what your magic mirror think the date is. Maybe it think your on the united state or something
                                    If that the case I don’t know how to tell moments to check the date from another country. you might want to change the function then.

                                    Search “how to get the date from a specific country in jacascript” on google and you might find the right function to do it.
                                    The only thing you have to know is that the " == " mean “equal”. The if mean that if the left part of the operation is equal to the right part, then you do the line bellow.
                                    So you need to replace the moment thing by another function.

                                    Maybe someone in this forum now how to tell moment the timezone it have to use

                                    1 Reply Last reply Reply Quote 0
                                    • C Offline
                                      CyanKali
                                      last edited by

                                      @romain I figured it out! The console showed me it was April 29 today (which is the right date), but it was written as “Apr. 29”, so with a dot behind the month. I tried writing it like this in the code and now it works!
                                      So it has to be:

                                      if (moment().format('MMM D') == 'Apr. 29')
                                      

                                      and then it works :)
                                      And now I know how to run my mirror in dev mode, which will be useful in the future ;) Thank you!

                                      romainR 1 Reply Last reply Reply Quote 0
                                      • romainR Offline
                                        romain @CyanKali
                                        last edited by

                                        @CyanKali Great =D . I guess that for some reason your moment.js doesn’t print the same thing as mine x) (which is kinda weird but fine)

                                        strawberry 3.141S 1 Reply Last reply Reply Quote 0
                                        • strawberry 3.141S Offline
                                          strawberry 3.141 Project Sponsor Module Developer @romain
                                          last edited by

                                          @romain moment uses different locales for dates and so on based on the language set

                                          Please create a github issue if you need help, so I can keep track

                                          1 Reply Last reply Reply Quote 0
                                          • ItsMeCobra2006I Offline
                                            ItsMeCobra2006
                                            last edited by ItsMeCobra2006

                                            In case someone is still wondering how to simply display set compliments on set days: ```

                                            complimentArray: function() {
                                            		var hour = moment().hour();
                                            		var date = moment().format('DDMM');  \\add this into compliments.js
                                            		var compliments;
                                            
                                            		if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
                                            			compliments = this.config.compliments.morning.slice(0);
                                            		} else if (hour >= this.config.afternoonStartTime && hour < this.config.afternoonEndTime && this.config.compliments.hasOwnProperty("afternoon")) {
                                            			compliments = this.config.compliments.afternoon.slice(0);
                                            		} else if(this.config.compliments.hasOwnProperty("evening")) {
                                            			compliments = this.config.compliments.evening.slice(0);
                                            		}
                                            
                                            		if (typeof compliments === "undefined") {
                                            			compliments = new Array();
                                            		}
                                            		
                                            
                                            		if (this.currentWeatherType in this.config.compliments) {
                                            			compliments.push.apply(compliments, this.config.compliments[this.currentWeatherType]);
                                            		}
                                            
                                              	    if (date in this.config.compliments) {
                                            			compliments.push.apply(compliments, this.config.compliments[date]);
                                            		} \\add these 3 lines into compliments.js
                                            
                                            		compliments.push.apply(compliments, this.config.compliments.anytime);
                                            
                                            		return compliments;
                                            	}, 
                                            

                                            Example:

                                            anytime: [
                                            				"Hey there sexy!"
                                            			],
                                            			morning: [
                                            				"Good morning, handsome!",
                                            				"Enjoy your day!",
                                            				"How was your sleep?"
                                            			],
                                            			afternoon: [
                                            				"Hello, beauty!",
                                            				"You look sexy!",
                                            				"Looking good today!"
                                            			],
                                            			"1005": [
                                            				"Today is May 10th",
                                            				"You look nice!",
                                            				"Hi, sexy!"
                                            			] 
                                            		},
                                            

                                            EDIT:
                                            Anyone know how to show compliments on days without a set date each year, like Christmas, but something like the second Sunday of May, like Mother’s day?

                                            Z 1 Reply Last reply Reply Quote 1

                                            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
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • 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