MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.20.0 is available! For more information about this release, check out this topic.

    Send Notification from one module to another module

    Development
    4
    6
    4041
    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.
    • E
      edubey last edited by

      I have one module which collects user data from somewhere. Once the data is collected how can I send notification to another module.
      I can use MM.getModules().
      But then How can I send notification.

      In Simple terms: Notify module A from module B
      Thanks in advance

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

        @edubey
        modula

        this.sendNotification("NEW_STUFF", {foo: "bar"});
        

        modulb

        notificationReceived: function(notification, payload, sender){
          if(notification === "NEW_STUFF" && sender === "modula"){
            //handle the payload: {foo: "bar"}
          }
        }
        

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

        E SvenSommer 3 Replies Last reply Reply Quote 3
        • E
          edubey @strawberry 3.141 last edited by

          @strawberry-3.141
          Thanks, i got it

          1 Reply Last reply Reply Quote 0
          • E
            edubey @strawberry 3.141 last edited by

            @strawberry-3.141

            Okay, so its more of a broadcast to all modules, not to any specific…right?

            yawns 1 Reply Last reply Reply Quote 0
            • yawns
              yawns Moderator @edubey last edited by

              @edubey said in Send Notification from one module to another module:

              @strawberry-3.141

              Okay, so its more of a broadcast to all modules, not to any specific…right?

              That’s right. This command sends out a broadcast to all modules. As long as you use a broadcast notification no other module reacts on you don’t have any trouble.

              1 Reply Last reply Reply Quote 0
              • SvenSommer
                SvenSommer @strawberry 3.141 last edited by

                It seemed the sender is now a object not only a string with several properties. Therefore this code snippet has changed a little by sender to sender.name:

                notificationReceived: function(notification, payload, sender){
                  if(notification === "NEW_STUFF" && sender.name === "modula"){
                    //handle the payload: {foo: "bar"}
                  }
                }
                

                Looking for some building inspiration?
                Check out my large, thin and metal framed mirror on robstechlog.com.

                Modules released:
                MMM-GoogleAnalytics
                MMM-GrafanaChart
                MMM-GrafanaGauges

                1 Reply Last reply Reply Quote 1
                • 1 / 1
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy