• 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.

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

Scheduled Pinned Locked Moved System
utilitygpiomotion-sensorpower-saving
56 Posts 32 Posters 97.5k Views 47 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.
  • P Offline
    paviro Admin
    last edited by Jopyth Jan 28, 2017, 1:48 PM May 6, 2016, 8:21 PM

    Description:

    MMM-PIR-Sensor will monitor a connected PIR-sensor and putt your mirror to sleep if no one uses it either by disabling HDMI output or by turning of a relay.

    Download:

    [card:paviro/MMM-PIR-Sensor]

    FAQ

    “An unhandled error occurred inside electron-rebuild. Unable to find electron-prebuilt’s version number, either install it or specify an explicit version”

    Possible solution: Change your package.json file in ~/MagicMirror/modules/MMM-PIR-Sensor like this.

    Developer note

    If you are a developer and want to pause your module while no one uses it (if it is processor intense), you can listen to the USER_PRESENCE broadcast. It will return true or false as its payload.

    Changelog


    Initial release

    We're all stories in the end. Just make it a good one, eh?

    – The Doctor

    J N D 4 Replies Last reply May 13, 2016, 3:09 AM Reply Quote 2
    • topic:timeago-later,about a month
    • K Offline
      KirAsh4 Moderator
      last edited by Jun 9, 2016, 7:12 PM

      For troubleshooting or HOWTO questions, please post in the Troubleshooting thread:
      https://forum.magicmirror.builders/topic/208/pir-sensor-put-your-mirror-to-sleep-if-not-used/1

      A Life? Cool! Where can I download one of those from?

      1 Reply Last reply Reply Quote 0
      • topic:timeago-later,22 days
      • S Offline
        sameershah23
        last edited by Jul 1, 2016, 7:34 PM

        I was wondering if there is a way to toggle the power to the TV via HDMI CEC commands (sent by pi) and integrating a PIR sensor?

        Example setup: The pi is always powered on. I walk into the room, the PIR senses me, and sends a power on signal to my TV via HDMI CEC command, and the mirror modules are displayed.

        After a set duration, if no activity sensed by PIR sensor, a power off CEC command is sent to the TV by PI.

        Has this been done before?

        Any guidance would be much appreciated.

        P T 2 Replies Last reply Jul 1, 2016, 9:22 PM Reply Quote 0
        • K Offline
          KirAsh4 Moderator
          last edited by Jul 1, 2016, 8:03 PM

          Please do not cross-post the same question across multiple categories. Answers will get lost in the various posts.

          A Life? Cool! Where can I download one of those from?

          1 Reply Last reply Reply Quote 0
          • P Offline
            paviro Admin @sameershah23
            last edited by Jul 1, 2016, 9:22 PM

            @sameershah23 Should be possible. There already is a function that turns of the HDMI output of the Pi you would just need to replace that part (or add a new mode) that sends a command to the monitor. Feel free to send a pull request!

            We're all stories in the end. Just make it a good one, eh?

            – The Doctor

            S 1 Reply Last reply Jul 8, 2016, 3:37 PM Reply Quote 0
            • S Offline
              sameershah23 @paviro
              last edited by sameershah23 Jul 8, 2016, 3:38 PM Jul 8, 2016, 3:37 PM

              @paviro I am fairly new to the programming world, but i was wondering what I need to add to the “//Detected Movement” & “//No movement” parts so that it sends the appropriate power toggle CEC signal to my TV?

              Do I need to install the CEC library? How do I initialize this CEC library in your node_helper.js file?

              After some googling, i found this library for CEC.

              https://github.com/Pulse-Eight/libcec/issues/84

              Will this library work for this application?

              Any help would be greatly appreciated. :)

              1 Reply Last reply Reply Quote 0
              • K Offline
                KirAsh4 Moderator
                last edited by Jul 8, 2016, 5:26 PM

                Assuming your monitor/TV supports proper HDMI CEC commands, you need to first install the necessary binaries on your rpi and test that yourself - that’s outside of MM².

                Once you figured out that it works, then you need to write (or ask someone else to write) a module that interacts with the CEC binaries sending the proper commands. - that’s MM² related.

                A Life? Cool! Where can I download one of those from?

                1 Reply Last reply Reply Quote 0
                • topic:timeago-later,14 days
                • T Offline
                  tyho @sameershah23
                  last edited by Jul 22, 2016, 12:33 PM

                  @sameershah23 maybe power off and on your hdmi signal and let your monitor/tv go to sleep mode when no signal.

                  The command will be:
                  OFF:
                  /opt/vc/bin/tvservice --off
                  ON:
                  /opt/vc/bin/tvservice --preferred && sudo chvt 6 && sudo chvt 7

                  You can easily execute commands in node.js

                  1 Reply Last reply Reply Quote 1
                  • topic:timeago-later,16 days
                  • I Offline
                    IngmarSwart
                    last edited by Aug 7, 2016, 8:42 PM

                    Using motion detection to switch your mirror on and off is very appealing. PIRs are a good option and Paviro’s module does a wonderful job. However, for an aesthetic point of view, I would like to mount the motion sensor behind the mirror, i.e. in such a way you can’t see the sensor. Since glass absorbs the light the PIR is sensitive to, PIRs (or at least the ones I tested, played with sensitivities as well) are not the best option. I played around a bit and found an alternative solution based on the Picamera, OpenCV and Paviro’s MMM-PIR module.

                    Downsides include having to run a python program next to the Magic Mirror. On a RPi3 it this is not a problem and is in my view therefore a rather minor drawback. If you run your MM on a RPi2, this may be an issue. Getting this to work also requires a non-trivial installation of OpenCV. However, thanks to the fantastic people over at PyImageSearch, detailed instructions are available. Upsides of this solution are: motion detection using a camera from behind the glass and the possibility to upload a photo taken by the camera each time it detects motion to your dropbox account.

                    Steps to follow:

                    • Disable the red LED on the Picamera by adding disable_camera_led = 1 to \boot\config.txt
                      (you don’t want to see red LED of the camera when looking at your mirror)
                    • Install a full version of OpenCV on the RPi. Detailed instructions can be found here
                    • Follow the two part tutorial on writing a python based code for motion detection: Part I and Part II
                    • Modify the python program found on the second page to generate a 3.3 V signal on a specified pin when the camera detects motion. This pin (pin 4 below) is then connected by a wire to the pin you specified in the MMM-PIR section of the MM config.js file. My modifications to the python code are:

                    On line 14 of the python code, add:

                    import RPi.GPIO as GPIO
                    GPIO.setmode(GPIO.BCM)
                    OPENCV_pin = 4 # specify whatever pin you want to generate the 3.3 V at when motion is detected.
                    GPIO.setup(OPENCV_pin, GPIO.OUT)
                    

                    On line 26 add:

                    UnoccupiedCounter = 0
                    NumUnoccFramesSwitchOff = conf["fps"] * conf["time_to_switch_off"]
                    
                    

                    On line 108 insert:

                    UnoccupiedCounter = 0
                    if GPIO.input(OPENCV_pin) == 0 # check if openCV pin is high or low. If low, turn high
                             GPIO.output(OPENCV_pin,1)
                             print "Switched Mirror ON"
                    

                    On line 137 insert:

                    UnoccupiedCounter =  UnoccupiedCounter + 1
                    if UnoccupiedCounter = numUnoccFramesSwitchOff and GPIO.input(OPENCV_pin)==1:
                             GPIO.output(OPENCV_pin, 0)
                             print "Switched Mirror OFF"
                    
                    • Add "time_to_switch_off": 30 to the conf.json file. Don’t forget to add the comma behind the previous entry.
                    • Optional but recommended to get a clean exit:
                      Insert the whole for loop in a try statement.
                      Between line 53 and 54, add
                    try: 
                    

                    Don’t forget to indent all the code that comes next. Add the very bottom, add:

                    except KeyboardInterrupt:
                          print "Stopped camera surveillance" # exit the program when you press CNRL +C
                    
                    except: 
                          print "Other error or exception occurred!" # catch all other errors
                    
                    finally:
                         GPIO.cleanup() # this ensures a clean exit.
                    

                    I hope the above is of use to some of you.

                    D 1 Reply Last reply Oct 20, 2016, 2:20 PM Reply Quote 6
                    • D Offline
                      DirkS
                      last edited by Aug 11, 2016, 12:58 PM

                      HI @IngmarSwart,

                      great hack!! Did you use the original Camera behind the glass? Noir or without the IR Filter?

                      I’m using a PI2, can you specify why this should be an issue?

                      Best regards
                      Dirk

                      I 1 Reply Last reply Aug 11, 2016, 1:42 PM Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 5
                      • 6
                      • 1 / 6
                      1 / 6
                      • First post
                        9/56
                        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