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.

    Garage Door Detectors

    Scheduled Pinned Locked Moved Requests
    22 Posts 6 Posters 15.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.
    • strawberry 3.141S Offline
      strawberry 3.141 Project Sponsor Module Developer @istepgueu
      last edited by

      @istepgueu you need a getDom function where you render your images.

      then in the notification received save the state in variables then call updateDom.

      in getDom you render the images based on the state

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

      istepgueuI 1 Reply Last reply Reply Quote 1
      • istepgueuI Offline
        istepgueu @strawberry 3.141
        last edited by

        @strawberry-3.141
        Thank you for the help !
        I understand the principle but not knowing javascript, I have a little trouble with the variables.

        This is my (not working) code :

        /* global Module */
        
        /* Magic Mirror
         * Module: MMM-door-sensor
         *
         * By iStepgueu http://www.twitter.com/istepgueu
         * MIT Licensed.
         */
        
        Module.register("MMM-door-sensor",{
        
        	// Default module config.
        	defaults: {
        		text: "Hello World!"
        	},
        
        
        	// Define start sequence.
        	start: function() {
        		Log.info("Starting module: " + this.name);
        
        	},
        
        
        
        	notificationReceived: function(notification, payload, sender) {
        		if (sender) {
        			Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
        			if (notification === "REMOTE_ACTION") {
        				this.sendSocketNotification(notification, payload);	
        
        				var door_state = "close.png";			
        	
        				this.updateDom();				
        			
        			}
        		} else { 
        			if (notification === "DOM_OBJECTS_CREATED") {
        				this.sendSocketNotification("REQUEST_DEFAULT_SETTINGS");
        			
        				var door_state = "open.png";
        
        
        				this.updateDom();
        
        
        			}
        		}
        		
        		},
        
        
        		getDom: function() {
        
        		var wrapper = document.createElement("div");
        		return door_state;
        		wrapper.innerHTML = '<img src=" + door_state + " />';
        		return wrapper;
        	}
        
        
        
        });
        
        
        strawberry 3.141S 1 Reply Last reply Reply Quote 0
        • strawberry 3.141S Offline
          strawberry 3.141 Project Sponsor Module Developer @istepgueu
          last edited by strawberry 3.141

          @istepgueu

          Module.register("MMM-door-sensor",{
          
          	// Default module config.
          	defaults: {
          		text: "Hello World!"
          	},
          
          	// Define start sequence.
          	start: function() {
          		Log.info("Starting module: " + this.name);
          	},
          
          	notificationReceived: function(notification, payload, sender) {
          		if (sender) {
          			Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
          			if (notification === "DOOR_STATE") {
          
          				this.door_state = payload;			
          	
          				this.updateDom();				
          			
          			}
          		} 
          		
          	},
          
          
          	getDom: function() {
          
          		var wrapper = document.createElement("div");
          if(this.door_state){
          		wrapper.innerHTML = '<img src=" + this.door_state + " />';
          } else {
          		wrapper.innerHTML = 'No door state present.';
          }
          		return wrapper;
          	}
          });
          

          config mmm-button

          {
                          pin: 24,
                          name: "power",
                          longPress: {
                              title: "Power off",
                              message: "Keep pressed for 3 seconds to shut down",
                              imageFA: "power-off",
                              notification: "DOOR_STATE",
                              payload: "close.png"
                          },
                          shortPress: undefined
                      }
          

          you would therefore need a button released to send open.png

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

          istepgueuI 1 Reply Last reply Reply Quote 3
          • istepgueuI Offline
            istepgueu @strawberry 3.141
            last edited by

            @strawberry-3.141 Thank you !! It’s working :-)

            1 Reply Last reply Reply Quote 0
            • J Offline
              jasondreher
              last edited by

              I like the MMM-door-sensor module, and I see that it uses notificationReceived to change the icon, but how do you send a notification to the module? I have tried this.sendNotification but I cannot seem to get it to work…

              1 Reply Last reply Reply Quote 0
              • 1
              • 2
              • 3
              • 3 / 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