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.

    MMM-Motion-Detection {fixed monitor on/off} tvservice --> vcgencmd

    Scheduled Pinned Locked Moved Utilities
    mmm-motion-detectionmonitorblack screenfixhelp
    3 Posts 2 Posters 3.2k 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.
    • K Offline
      kelddel
      last edited by kelddel

      Re: [MMM-Motion-Detection] Motion Detection through PiCam or USB Webcam

      I have limited knowledge of programming and here I was trying to setup a magic mirror with a motion sensor. I looked into PIR sensors but the glass was too reflective for them to function properly, so I decided on using a USB webcam as a motion sensor instead. Only problem was that MMM-Motion-Detection had almost no documentation, and once I finally got the module ‘functioning’, the monitor would turn on but wouldn’t display anything. Forcing me to reset the RPi and monitor to finally get it to display again properly. After researching for hours, the only mention of the problem I was encountering was a couple short sentences from a guy, gismo2006, who had solved the same issue but was asking a completely different question in the post

      "I see only a black page. So after i changed the order to activate and deactivete from ‘tvservice’ to ‘vcgencmd display power 1’… "

      There we go! If only I can figure out wtf that means! More googling and everyone’s saying ‘vcgencmd’ is wayyyyy better than tvservice. Sweet! So with my vast knowledge of programming how the f*** do I do that? Figured if I fired up every single MMM-Motion-Detection module file with notepad++ I could just ctr+f ‘tvservice’ every doc until it pops up… and it totally F’ing worked! Found it in the node_helper.js!

      activateMonitor: function () {
          if (this.config.turnOffDisplay) {
            // Check if hdmi output is already on
            exec("/opt/vc/bin/tvservice -s").stdout.on("data", function(data) {
              if (data.indexOf("0x120002") !== -1)
                exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
            });
          }
        },
      
        deactivateMonitor: function () {
          if (this.config.turnOffDisplay) {
            exec("/opt/vc/bin/tvservice -o", null);
          }
        },
      

      Now more confusion! It seems to be executing a file? I can’t think of any other reason to use a directory file listing (seriously shooting into the dark). So I directly plug-in tvservice -o into the command prompt, without the file directory, and it turned off my monitor! OH YEAH BOY! I’M AN 3LITe C0D3R!!! Finally, I’m honing in on the answer, after countless hours of desperately searching. Now it’s time for the fireworks; pi@raspberrypi:~ $ tvservice -p.!! …my monitor starts turning on, my palms are sweaty from the anticipation of finally being able to change my clothes after two miserable days of blankly staring into the monitor.

      The friendly reminder on the screen that HDMI 2 was the signal source had me jumping in ecstasy!

      Then nothing…
      The screen was clearly on, but a hazy, black background was all I could see.
      It felt like I was looking into my own soul.

      Okay, so it’s obviously this tvservice function that is ruining my life. This was suppose to be a fcking gift, now it’s become a fcking obsession. A fcking obsession and a fcking two month late gift. At this point I’m literally losing calcium in my bones. Might as well pop a bottle and start chain-smoking cigarettes.

      So, the exec array obviously runs tvservice on/off functions, I know what each command does; Maybe I can just swap out those commands with similar0 vcgencmd commands without having to enter some weird file directory looking command

        },
      
        activateMonitor: function () {
          if (this.config.turnOffDisplay) {
            // Check if hdmi output is already on
            exec("vcgencmd display_power 1").stdout.on("data", function(data) {
              if (data.indexOf("0x120002") !== -1)
                exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
            });
          }
        },
      
        deactivateMonitor: function () {
          if (this.config.turnOffDisplay) {
            exec("vcgencmd display_power 0", null);
          }
        },
      

      BINGO! My pants are instantly sopping wet, but was worth it because… I’M THE KING OF THE FCKING WORLDDDDDDDDD!!! 1337 BITCHES!!! 1337 C0D3R!! I DID IT HAHAHHAHAHHAHAHAHHHAHAH NO MORE WILL I BE SHAMED. VINNY VINNY WHATEVER HAHAHAHAHHAHA

      Now if only I can get the mic to work…

      tl;dr: Navigate to your node_helper.js and replace:

      activateMonitor: function () {
          if (this.config.turnOffDisplay) {
            // Check if hdmi output is already on
            exec("/opt/vc/bin/tvservice -s").stdout.on("data", function(data) {
              if (data.indexOf("0x120002") !== -1)
                exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
            });
          }
        },
      
        deactivateMonitor: function () {
          if (this.config.turnOffDisplay) {
            exec("/opt/vc/bin/tvservice -o", null);
          }
        },
      

      with

       activateMonitor: function () {
         if (this.config.turnOffDisplay) {
           // Check if hdmi output is already on
           exec("vcgencmd display_power 1").stdout.on("data", function(data) {
             if (data.indexOf("0x120002") !== -1)
               exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
           });
         }
       },
      
       deactivateMonitor: function () {
         if (this.config.turnOffDisplay) {
           exec("vcgencmd display_power 0", null);
         }
       },
      

      Probably not perfect, but it does the trick.

      1 Reply Last reply Reply Quote 1
      • G Offline
        gismo2006
        last edited by

        Hi,

        I found your post.

        I have/had several problems with tvservice. So I decide to google about one or two years ago. Then I found the vcgencmd and everytime there was spoken about tv serve i use vcgencmd and everything works fine ;-)

        To find out what I mean, you could just send me a pn :-D

        greets gismo2006

        K 1 Reply Last reply Reply Quote 0
        • K Offline
          kelddel @gismo2006
          last edited by

          @gismo2006 Hey, honestly if it wasn’t for the fact that you mentioned changing tvservice to vcgencmd I’d never have figured it out! Your brief commend put me on the right path to getting everything working, thank so you much!! If I run into any problems with vcgencmd in the future I’ll be sure to pm you :)

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