MagicMirror² v2.12.0 is available! For more information about this release, check out this topic.

PIR-Sensor - put your mirror to sleep if not used

  • @paviro
    I need some help please, because my PIR-Sensor doesn´t work with your module.
    I do not know what I did wrong. I wrote my Problem in another category in the MM Forum, but unfortunately until now nobody could help me.

    My problem is that my monitor does not turn off. I configured the config.js like this

                module: 'MMM-PIR-Sensor',
                config: {
                        sensorPIN: 23,
                        powerSaving: true,  

    and connect the sensor to the raspberry like this

    Waiting about one, two minutes, but the monitor does not turn off. I would be really happy if you could help me.

    Thanks in advance.

  • @paviro Cheers for making a very useful module.

    I have made some modifications to node.js to make it work in my situation. I’ve never really done any javascript programming, so what I did was kind of hacked together from various forums. As you know what you’re doing it would be great if you could include any of these features for future versions (I’ve never used GIT before so not sure how to fork etc).

    I had to make the following modifications-

    1. Use the vcgencmd function to turn on/off screen (I couldn’t get it to wake up using tvservice despite trying many variations found online). I found this option suggested by others on the forum. Perhaps a config option to use this in place of the TV service for those who it doesn’t work for?
    2. The PIR sensor I used is not the same as that used by nearly everyone else (the ones I bought are Wingoneer… they come on a smaller board & don’t have the sensitivity adjustments)… the outcome of this is that the sensor pin is high (+5V) when there is no detection & pulled low (0V) when you move in front of sensor. I therefore had to invert your motion detected logic by swapping the 1 & 0. Could an option for ‘invert pin’ be included?
    3. I followed various options online for how to disable the screen saver… but my pi still goes in to screen save mode after 30 mins. This means even if motion is detected, the screen switches on but remains blank. I solved this in a bit of a hacky way by using the xdotool package to simulate pressing “space” and therefore end the screensaver.
    4. One final issue which I haven’t been able to resolve yet is that after restarting my PI, assuming there is no motion detected, the screen will be ‘On’ even though there is no motion detected. As an event is not generated (i.e the state didn’t change) it will stay on until the sensor has detected someone & then moved away. Although this isn’t really a huge deal (it should only be restarted if I’m using the screen so I can trigger an event by moving in front & away again) I just wondered if there is a way to do an initial poll of the sensor after start up. I’m not sure if this is because my sensor logic is inverted or if this behaviour is seen on those using the normal PIRs.

    As I understand I will lose these changes if you upgrade your module next time I do a GIT pull.

    My code below if it is of interest to anyone:

    switch off

    exec("vcgencmd display_power 0"); //Used in favour of tvservice

    switch on

    exec("vcgencmd display_power 1"); //Used in favour of tvservice
    exec("xdotool key space"); //simulate  spacebar to disable screensaver. Needs xdotool to be installed

  • Hi! I’ve run through the posts - though I haven’t been able to find anybody that’s had the sample problem that I’ve had. To test the hardware, I put a towel over the IR sensor, and I find that the monitor flickers on and off, even when the sensor is covered.

    Has anybody had this issue? Or can suggest some solutions?


  • Anyway this can send a signal to openhab to control the lights ive put around my frame?

  • @Jopyth Hi.
    Could You give a hint?
    It makes sense just to get data for buses/train departures when screen is active…

  • @randomnoise said in PIR-Sensor - put your mirror to sleep if not used:

    exec(“xdotool key space”); //simulate spacebar to disable screensaver. Needs xdotool to be installed

    Hello Randomnoise;

    So you did exactly what I am looking to do. Can you elaborate on how to configure this so my PIR will turn off the screen saver? I’ve already installed Xdotool, but I don’t know where to go from there.