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.

    Not updating at midnight...

    Scheduled Pinned Locked Moved Solved Troubleshooting
    24 Posts 3 Posters 1.8k 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.
    • M Offline
      MMRIZE @BKeyport
      last edited by

      @BKeyport
      Your DOM might not be rendered yet on “start” imo. I think manipulating DOM after “DOM_OBJECT_CREATED” notification would be safer.

      S 1 Reply Last reply Reply Quote 1
      • S Offline
        sdetweil @MMRIZE
        last edited by

        @MMRIZE

        Yes the documented flow is, as I recall on my phone,

        Init
        Getstyles
        Getscripts
        GetTemplates
        Start
        Notification received
        AllModulesStarted
        DOMobjectsCreated
        getDOM

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        BKeyportB 1 Reply Last reply Reply Quote 0
        • BKeyportB Online
          BKeyport Module Developer @sdetweil
          last edited by

          @sdetweil @MMRIZE so, should I move the initial call somewhere else?

          The "E" in "Javascript" stands for "Easy"

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @BKeyport
            last edited by

            @BKeyport after the notification

            From the doc

            DOM_OBJECTS_CREATED - All dom objects are created. The system is now ready to perform visual changes.

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            BKeyportB 1 Reply Last reply Reply Quote 0
            • BKeyportB Online
              BKeyport Module Developer @sdetweil
              last edited by BKeyport

              @sdetweil said in Not updating at midnight...:

              DOM_OBJECTS_CREATED - All dom objects are created. The system is now ready to perform visual changes

              start: function () {
                  function scheduleMidnightUpdate() {
                      const now = new Date();
                      const nextMidnight = new Date(now);
              
                      // Set the time to midnight
                      nextMidnight.setHours(24, 0, 0, 0);
              
                      // Calculate the time remaining until the next midnight
                      const timeUntilMidnight = nextMidnight - now;
              
                      // Schedule the updateDom method to be called at midnight
                      setTimeout(() => {
                          this.updateDom();
              
                          // Reschedule the update for the next midnight
                          scheduleMidnightUpdate.call(this);
                      }, timeUntilMidnight);
                  }
              },
              
                  notificationReceived: function (notification, payload, sender) {
                      if (notification === 'CALENDAR_EVENTS') {
                          this.storedEvents = JSON.parse(JSON.stringify(payload))
                          this.updateDom();
                      } else if (notification === 'DOM_OBJECTS_CREATED') {
                          // Call the function to start the first schedule
                            scheduleMidnightUpdate.call(this);  
                      }
              

              This is the only source I see in the docs of that - a notification. Is that correct?

              Thanks for the patience after the double misunderstanding.

              The "E" in "Javascript" stands for "Easy"

              S 2 Replies Last reply Reply Quote 0
              • S Offline
                sdetweil @BKeyport
                last edited by

                @BKeyport

                https://docs.magicmirror.builders/development/core-module-file.html

                IMG_0044.png

                you could have done all the initial event calculating in one function

                used interval for the midnights (as it’s a fixed number)

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                S 1 Reply Last reply Reply Quote 0
                • S Offline
                  sdetweil @sdetweil
                  last edited by

                  @BKeyport MODULE_DOM_CREATED means YOUR getDom()/getTemplateData() has been called

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  BKeyportB 1 Reply Last reply Reply Quote 0
                  • BKeyportB Online
                    BKeyport Module Developer @sdetweil
                    last edited by

                    @sdetweil yeah, doing it that way just throws headers with “Undefined” until it triggers. I’m not gonna go down that rabbit hole. It seems to work as is, so I’m gonna release for now.

                    The "E" in "Javascript" stands for "Easy"

                    1 Reply Last reply Reply Quote 1
                    • S Offline
                      sdetweil @BKeyport
                      last edited by sdetweil

                      @BKeyport said in Not updating at midnight...:

                      start: function () {
                      function scheduleMidnightUpdate() {
                      const now = new Date();
                      const nextMidnight = new Date(now);

                          // Set the time to midnight
                          nextMidnight.setHours(24, 0, 0, 0);
                      
                          // Calculate the time remaining until the next midnight
                          const timeUntilMidnight = nextMidnight - now;
                      
                          // Schedule the updateDom method to be called at midnight
                          setTimeout(() => {
                              this.updateDom();
                      
                              // Reschedule the update for the next midnight
                              scheduleMidnightUpdate.call(this);
                          }, timeUntilMidnight);
                      }
                      

                      },

                      I would do it like this , much more straight forward

                           function scheduleMidnightUpdate() {
                               const now = new Date();
                               const nextMidnight = new Date(now);
                       
                               // Set the time to midnight
                               nextMidnight.setHours(24, 0, 0, 0);
                       
                               // Calculate the time remaining until the next midnight
                               const timeUntilMidnight = nextMidnight - now;
                       
                               // Schedule the updateDom method to be called at midnight
                               setTimeout(() => {
                                   // trigger first update on next midnight change
                                   this.updateDom();
                                  // start Recurring midnight change
                                   setInterval(()=>{
                                       this.updateDom()
                                   }, 24*60*60*1000 ) // 24 hours * 60 minutes * 60 seconds * 1000 milliseconds (1 day elapsed in ms)  setInterval delay
                               }, timeUntilMidnight);  // setTimeout delay
                           }
                       },
                      

                      then the system triggers every midnight… not your code

                      Sam

                      How to add modules

                      learning how to use browser developers window for css changes

                      1 Reply Last reply Reply Quote 0
                      • S sdetweil has marked this topic as solved on
                      • 1
                      • 2
                      • 3
                      • 2 / 3
                      • 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