• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.

Motion Detector and OSX

Scheduled Pinned Locked Moved Solved Troubleshooting
6 Posts 2 Posters 1.0k Views 2 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.
  • 0 Offline
    0v3rNuLL
    last edited by Mar 14, 2019, 1:58 PM

    hi everyone!
    I succesfully run MM2 on a macmini late 2009. Currently im testing some modules and so far so good except for one module Motion detector. I was looking on the code on node_helper.js and found the line with the command “vcgencmd display_power 0”.
    In OSX not work but “pmset displaysleepnow” to put the screen on sleep does the trick and " caffeinate -u -t 1" to wake up.
    So i replace the command

    if (result) {
    				exec("vcgencmd display_power 0", function(err, out, code) {
    					if (err) {
    						console.error("MMM-MotionDetector: error deactivating monitor: " + code);
    					} else {
    						console.log("MMM-MotionDetector: monitor has been deactivated");
    					}
    				});
    			}
    

    to

    if (result) {
    				exec("pmset displaysleepnow", function(err, out, code) {
    					if (err) {
    						console.error("MMM-MotionDetector: error deactivating monitor: " + code);
    					} else {
    						console.log("MMM-MotionDetector: monitor has been deactivated");
    					}
    				});
    			}
    

    Its looks like work but im getting this message on console log “pmset displaysleepnow blocked by app electron.js” and the screen keeps alive.

    Is there a way to solve this?
    Or maybe toggling the body to hide to get the black screen?

    Thanks in advance and sorry for my bad english :)

    1 Reply Last reply Reply Quote 0
    • S Away
      sdetweil
      last edited by sdetweil Mar 14, 2019, 2:02 PM Mar 14, 2019, 2:01 PM

      @0v3rNuLL said in Motion Detector and OSX:

      pmset displaysleepnow blocked by app electron.js

      there is an npm module to work around that it appears

      https://electronjs.org/docs/api/power-save-blocker

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      0 1 Reply Last reply Mar 17, 2019, 3:24 AM Reply Quote 1
      • 0 Offline
        0v3rNuLL
        last edited by Mar 14, 2019, 6:52 PM

        hi sdetweil!

        I try on node_helper.js located on MMM-MotionDetector at the begining and did not work still getting display slep prevented by electron

        here is the part i change

        //////Original code/////
        
        const NodeHelper = require("node_helper");
        const exec = require("child_process").exec;
        ///////////////////
        
        const { powerSaveBlocker } = require('electron');
        
        const id = powerSaveBlocker.start('prevent-app-suspension'); 
        
        console.log(powerSaveBlocker.isStarted(id));
        
        powerSaveBlocker.stop(id)
        

        Its the correct place ?

        Sorry but im totally new on node.
        Thanks in advance

        S 1 Reply Last reply Mar 14, 2019, 8:01 PM Reply Quote 0
        • S Away
          sdetweil @0v3rNuLL
          last edited by sdetweil Mar 14, 2019, 8:01 PM Mar 14, 2019, 8:01 PM

          @0v3rNuLL said in Motion Detector and OSX:

          complete node helper

          const NodeHelper = require("node_helper");
          const exec = require("child_process").exec;
          const { powerSaveBlocker } = require('electron');
          
          module.exports = NodeHelper.create({
          	start: function () {
          		this.started = false;
          		this.isMonitorOn(function(result) {
          			console.log("MMM-MotionDetector: monitor on " + result);
          		});
          	},
          
          	activateMonitor: function () {
          		this.isMonitorOn(function(result) {
          			if (!result) {
          				let id = powerSaveBlocker.start('prevent-app-suspension'); 
          				if(powerSaveBlocker.isStarted(id))
          			           powerSaveBlocker.stop(id)		
          				exec("vcgencmd display_power 1", function(err, out, code) {
          					if (err) {
          						console.error("MMM-MotionDetector: error activating monitor: " + code);
          					} else {
          						console.log("MMM-MotionDetector: monitor has been activated");
          					}
          				});
          			}
          		});
          		this.started = false;
          	},
          
          	deactivateMonitor: function () {
          		this.isMonitorOn(function(result) {
          			if (result) {
          				let id = powerSaveBlocker.start('prevent-app-suspension'); 
          				if(powerSaveBlocker.isStarted(id))
          			           powerSaveBlocker.stop(id)	
          				exec("vcgencmd display_power 0", function(err, out, code) {
          					if (err) {
          						console.error("MMM-MotionDetector: error deactivating monitor: " + code);
          					} else {
          						console.log("MMM-MotionDetector: monitor has been deactivated");
          					}
          				});
          			}
          		});
          		this.started = false;
          	},
          
          	isMonitorOn: function(resultCallback) {
          		exec("vcgencmd display_power", function(err, out, code) {
          			if (err) {
          				console.error("MMM-MotionDetector: error calling monitor status: " + code);
          				return;
          			}
          
          			console.log("MMM-MotionDetector: monitor " + out);
          			resultCallback(out.includes("=1"));
          		});
          	},
          
          	// Subclass socketNotificationReceived received.
          	socketNotificationReceived: function (notification, payload) {
          		if (notification === "MOTION_DETECTED" && this.started === false) {
          			console.log("MMM-MotionDetector: MOTION_DETECTED, score " + payload.score);
          			this.started = true;
          			this.activateMonitor();
          		}
          		if (notification === "DEACTIVATE_MONITOR" && this.started === false) {
          			console.log("MMM-MotionDetector: DEACTIVATE_MONITOR");
          			this.started = true;
          			this.deactivateMonitor();
          		}
          	}
          });
          

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 1
          • 0 Offline
            0v3rNuLL
            last edited by Mar 17, 2019, 3:14 AM

            Finally figured it out, this module now can put the screen off and on (osx el capitan).
            Here is the modification for node_helpder.js

            const NodeHelper = require("node_helper");
            
            const exec = require("child_process").exec;
            
            var cmd=require('node-cmd'); // install node-cmd (npm install node-cmd) first and add excute command osx style then change exec to cmd.get <-- return the result to analize
            
            module.exports = NodeHelper.create({
            	start: function () {
            		this.started = false;
            		this.isMonitorOn(function(result) {
            			console.log("MMM-MotionDetector: monitor on " + result);
            		});
            	},
            
            	activateMonitor: function () {
            		this.isMonitorOn(function(result) {
            			if (!result) {
            				cmd.get('caffeinate -u -t 1', function(err, out, code) {
            					if (err) {
            						console.error("MMM-MotionDetector: error activating monitor: " + code);
            					} else {
            						console.log("MMM-MotionDetector: monitor has been activated");
            					}
            				});
            			}
            		});
            		this.started = false;
            	},
            
            	deactivateMonitor: function () {
            		this.isMonitorOn(function(result) {
            			if (result) {
            				cmd.get('pmset displaysleepnow', function(err, out, code) {
            
            					
            					if (err) {
            						console.error("MMM-MotionDetector: error deactivating monitor: " + code);
            					} else {
            						console.log("MMM-MotionDetector: monitor has been deactivated");
            					}
            				});
            			}
            		});
            		this.started = false;
            	},
            
            	isMonitorOn: function(resultCallback) {
            
            
            
            		cmd.get('pmset -g powerstate IODisplayWrangler | tail -1 | cut -c29', function(err, out, code) {
            			console.log("MMM-MotionDetector: monitor " + out);
            
            			if (err) {
            				console.error("MMM-MotionDetector: error calling monitor status: " + code);
            				return;
            			}
            
            			console.log("MMM-MotionDetector: monitor " + out);
            		resultCallback(out.includes("4")); // <4 is off
            		});
            	},
            
            	// Subclass socketNotificationReceived received.
            	socketNotificationReceived: function (notification, payload) {
            		if (notification === "MOTION_DETECTED" && this.started === false) {
            			console.log("MMM-MotionDetector: MOTION_DETECTED, score " + payload.score);
            			this.started = true;
            			this.activateMonitor();
            		}
            		if (notification === "DEACTIVATE_MONITOR" && this.started === false) {
            			console.log("MMM-MotionDetector: DEACTIVATE_MONITOR");
            			this.started = true;
            			this.deactivateMonitor();
            		}
            	}
            });
            
            
            

            This can be marked as SOLVED :slightly_smiling_face:

            1 Reply Last reply Reply Quote 0
            • 0 Offline
              0v3rNuLL @sdetweil
              last edited by Mar 17, 2019, 3:24 AM

              Icant post the entire code so, link to pastebin :)

              node_helper.js

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                4/6
                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