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.

    Want to turn off my monitor

    Scheduled Pinned Locked Moved Troubleshooting
    monitorpower-saving
    27 Posts 9 Posters 25.5k Views 7 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.
    • R Offline
      robmcc83
      last edited by

      Not sure if this belongs in troubleshooting but didn’t know where to post this so sorry if it’s in the wrong section, but my problem is something I want to achieve so I thought this would be the best place.
      Basically been running my mirror for around 8 months now and really enjoy it but I usually only turn it on when we have visitors just to show it off lol.
      What I would like to achieve is to have it on permantly but maybe have the monitor go to sleep at night so that the monitor isn’t on all the time.
      Is this at all possible or if not what does everyone else do to cut down on electric cost due to the monitor being on all day.
      Thanks in advance

      1 Reply Last reply Reply Quote 0
      • R Offline
        robmcc83
        last edited by

        Or if I cannot achieve this is there a simple ssh command I could use from my app i use on my phone to set the monitor to sleep and wake as i want.
        Obviously I would prefer the option for me to set on and off times for the monitor but if it’s not achievable this option would have to do.
        Thanks
        Rob

        1 Reply Last reply Reply Quote 0
        • R Offline
          ryck Module Developer
          last edited by

          What you want here is a PIR sensor, so the monitor only wakes up when there is someone around. That will help you with the electric cost and, more importantly, won’t stress your display that much. Look for “PIR sensor” here, there is plenty on modules / ways to do it, and the actual sensor is dirty cheap on Amazon. If case that helps you, this is how I did it.

          1 Reply Last reply Reply Quote 0
          • cruunnerrC Offline
            cruunnerr
            last edited by cruunnerr

            Easiest way is to use the MMM-Remote-Control module. With that, u were able to turn off and on the monitor with your phone or every other network device.

            Other options are a PIR-Sensor or a button on your mirror. There are many threads about that. Just give the search function a try ;)

            1 Reply Last reply Reply Quote 1
            • D Offline
              doubleT Module Developer
              last edited by

              Don’t forget, you can also hook up the monitor to a PIR switch directly (check wattage allowed for the PIR switch!) or to a light/power switch or even a combination.

              I didn’t want the monitor to be in standby when I’m not home for a week, so the PIR directly controls power to the monitor to completely switch it off instead of it going to standby. And the PIR is behind a switch, too.

              1 Reply Last reply Reply Quote 0
              • R Offline
                robmcc83
                last edited by

                Cheers for the replies everyone all is noted :)
                For now think I’ll keep searching the net for a way to have the monitor on during the day and sleep at night.
                I have found one site that shows how to do it but want to make a backup image first incase I break anything lol.
                I do like the idea of a pir. Are they easy to setup if I cannot get on with the way I’m currently looking for.
                Cheers

                1 Reply Last reply Reply Quote 0
                • randomnoiseR Offline
                  randomnoise
                  last edited by

                  For simple time based screen on & off check https://github.com/ianperrin/MMM-ModuleScheduler

                  randomnoiseR 1 Reply Last reply Reply Quote 0
                  • randomnoiseR Offline
                    randomnoise @randomnoise
                    last edited by

                    Sorry, should say you combine with the remote control module to send screen off notifications.

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      robmcc83
                      last edited by

                      So I’ve been looking through the net and have found I can use vcgencmd display_power 0 to turn off my monitor and the same again to power 1 to turn it back on, it also explains it can be run as a cron job but I’ve never done one of them so not to sure.
                      Would it all be possible to hook up a push button switch to the gpio and have them commands somehow turn the display off and on.
                      Thanks

                      1 Reply Last reply Reply Quote 1
                      • D Offline
                        doubleT Module Developer
                        last edited by doubleT

                        Don’t forget that the monitor will still be on, it’s just in standby, still consuming power. The Pi can’t switch the power of the monitor itself off.

                        1 Reply Last reply Reply Quote 0
                        • R Offline
                          robmcc83
                          last edited by

                          Yeah cheers I’m aware of that, it’s just monitor uses 37w whilst on and 2w in standby so I really don’t mind it being in standby at night.
                          I think I’m going to look into mmm-remote as trying the other method using vgenmcd power makes my screensaver come back to life even though it’s Been disabled for the last 8 months.
                          Is there any tutorials anywhere in setting up mmm-schedule and mmm-remote.
                          Cheers all

                          1 Reply Last reply Reply Quote 0
                          • R Offline
                            robmcc83
                            last edited by

                            Ok so after trying various ways to get my monitor to turn off I have still been unsuccessful.
                            What I am trying now is with a webcam.
                            I found in my box of computer bits a Microsoft lifecam hd 3000.
                            After a little Google research I can confirm the webcam works with the pi using motion software.
                            I also found a site explaining how I can add a start and and event on detection so I set vgencmd display_power 1 as start event and vgencmd display_power 0 as end event but still no luck it just keeps display on but if I enter the command in terminal my display turns on/off as it should.
                            Am I going about this in the most awkward way or is there a simple way to get the monitor to sleep using the usb webcam.
                            Thanks in advance

                            Mykle1M 1 Reply Last reply Reply Quote 0
                            • Mykle1M Offline
                              Mykle1 Project Sponsor Module Developer @robmcc83
                              last edited by Mykle1

                              @robmcc83

                              You could try this for ON

                              if (something) {
                              exec("/opt/vc/bin/tvservice -o", null); }

                              And this for OFF

                              { exec("/opt/vc/bin/tvservice --preferred && sudo chvt 6 && sudo chvt 7", null); }

                              Or

                              { exec('xset dpms force on', null); }
                              { exec('xset dpms force off', null); }

                              Create a working config
                              How to add modules

                              Mykle1M 1 Reply Last reply Reply Quote 2
                              • cruunnerrC Offline
                                cruunnerr
                                last edited by cruunnerr

                                did u try:

                                sudo tvservice -o to turn off your Monitor
                                sudo tvservice -p to turn on your monitor
                                ?

                                If this isn’t working i think your Monitor or your HDMI Cable are not supporting CEC.

                                If this works u have several options.
                                For example u can create two *.sh files and make them executable. Put these scripts into cronjob file for time based turning on or off the monitor.
                                Or u can use a PIR or a simple Button to do that. Let me give you a small software tutorial for this example:

                                Tutorial beginning:

                                cd
                                nano monitor_on.sh (creates the file)

                                write this in this file:

                                sudo tvservice -p
                                

                                save with “ctrl+x” and say “y” to save the file.

                                nano monitor_off.sh

                                write this in this file:

                                sudo tvservice -o
                                

                                save with “ctrl+x” and say “y” to save the file.

                                chmod +x monitor_on.sh (to make it executable)
                                chmod +x monitor_off.sh

                                So now you have two options. Write a python script to automatically start the shell scripts by using a GPIO or just put the Shell scripts into a cronjob.

                                Here is the first way:

                                nano pir.py (creates a script which executes the *.sh files via PIR or Button)

                                write this into the file:

                                #!/usr/bin/env python
                                
                                import sys
                                import time
                                import RPi.GPIO as io
                                import subprocess
                                
                                io.setmode(io.BCM)
                                SHUTOFF_DELAY = 119 # in seconds, how long the monitor will be on until next button press or PIR detection
                                PIR_PIN = 25       # 22 on the board (this needn't to be a PIR. Can be a button also)
                                LED_PIN = 16      # optional
                                
                                def main():
                                    io.setup(PIR_PIN, io.IN)
                                    io.setup(LED_PIN, io.OUT)
                                    turned_off = False
                                    last_motion_time = time.time()
                                
                                    while True:
                                        if io.input(PIR_PIN):
                                            last_motion_time = time.time()
                                            io.output(LED_PIN, io.LOW)
                                            print ".",
                                            sys.stdout.flush()
                                            if turned_off:
                                                turned_off = False
                                                turn_on()
                                        else:
                                            if not turned_off and time.time() > (last_motion_time + 
                                                                                 SHUTOFF_DELAY):
                                                turned_off = True
                                                turn_off()
                                            if not turned_off and time.time() > (last_motion_time + 1):
                                                io.output(LED_PIN, io.HIGH)
                                        time.sleep(.1)
                                
                                def turn_on():
                                	subprocess.call("sh /home/pi/monitor_on.sh", shell=True)
                                
                                def turn_off():
                                	subprocess.call("sh /home/pi/monitor_off.sh", shell=True)
                                
                                if __name__ == '__main__':
                                    try:
                                        main()
                                    except KeyboardInterrupt:
                                        io.cleanup()
                                
                                

                                save with “ctrl+x” and say “y” to save the file.

                                chmod +x pir.py

                                You can check if your button works by simply typing python pir.py. Every time u move through the PIR or press the button it will show you some …
                                End the test with “ctrl+c”

                                now we editing the rc.local to start the script after booting the Pi:

                                sudo nano /etc/rc.local

                                write this in the file (above the “exit 0”):

                                python /home/pi/pir.py &

                                save with “ctrl+x” and say “y” to save the file.

                                after all it should look like this:

                                #!/bin/sh -e
                                #
                                # rc.local
                                #
                                # This script is executed at the end of each multiuser runlevel.
                                # Make sure that the script will "exit 0" on success or any other
                                # value on error.
                                #
                                # In order to enable or disable this script just change the execution
                                # bits.
                                #
                                # By default this script does nothing.
                                
                                # Print the IP address
                                _IP=$(hostname -I) || true
                                if [ "$_IP" ]; then
                                  printf "My IP address is %s\n" "$_IP"
                                fi
                                
                                python /home/pi/pir.py
                                
                                exit 0
                                

                                Here comes the second way:

                                Next steps we will do as root to be sure it works. Maybe not the best way, but i am just a simple guy, who is still learning the stuff. ^^
                                Lets say we want to turn on the monitor every day at 6am and turn off at 8pm:

                                sudo nano /etc/crontab (to open the crontab)

                                write this into the file:
                                0 6 * * * /home/pi/monitor_on.sh
                                0 20 * * * /home/pi/monitor_off.sh

                                this should look like this:

                                # /etc/crontab: system-wide crontab
                                # Unlike any other crontab you don't have to run the `crontab'
                                # command to install the new version when you edit this file
                                # and files in /etc/cron.d. These files also have username fields,
                                # that none of the other crontabs do.
                                
                                SHELL=/bin/sh
                                PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
                                
                                # m h dom mon dow user  command
                                17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
                                25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
                                47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
                                52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
                                0 6     * * *   root      /home/pi/monitor_on.sh
                                0 20    * * *   root      /home/pi/monitor_off.sh
                                #
                                

                                I wrote this just out of my head so i hope i didn’t forget anything.

                                Tutorial ending!

                                That is just an example of using a GPIO to turn off and on your monitor via HDMI-CEC.
                                How i said, if your monitor or cable doesn’t support this u need to choose another way (turn a relays on and off to the power supply of the monitor e.g.)

                                edit:

                                sorry @mykle1, did not notice that you already answered, because I already started to write while you answered :D

                                Mykle1M J 2 Replies Last reply Reply Quote 1
                                • Mykle1M Offline
                                  Mykle1 Project Sponsor Module Developer @cruunnerr
                                  last edited by

                                  @cruunnerr

                                  No worries, mate. I hope to learn something from your answer. (which is totally amazing to me)

                                  Peace!

                                  Create a working config
                                  How to add modules

                                  1 Reply Last reply Reply Quote 0
                                  • R Offline
                                    robmcc83
                                    last edited by

                                    Thanks this is very useful information that I didn’t know before.
                                    I have issued the sudo tvservice -o command and it did indeed shut down my monitor.
                                    But what I am trying at the moment is to have it shutdown and wakeup the monitor with a usb webcam now.
                                    That’s what I’m struggling with.
                                    Cheers

                                    1 Reply Last reply Reply Quote 0
                                    • R Offline
                                      robmcc83
                                      last edited by

                                      One interesting thing I like about the second way is it seems easy :) lol.

                                      Would it be possible to say have the screen come on 6-9am in the morning Monday to Friday then come on again 4-10pm as everyone out at work or school during the day. Than say set it so that its on 8am till 10pm on a saturday and sunday when everyone is usually about.

                                      Thanks

                                      1 Reply Last reply Reply Quote 0
                                      • cruunnerrC Offline
                                        cruunnerr
                                        last edited by cruunnerr

                                        Sure, this is possible. For the beginning it seems easy, because u needn’t any optional hardware :)

                                        For your understanding how cronjobs works u should note the following:

                                        * * * * * user executive_command
                                        ┬ ┬ ┬ ┬ ┬
                                        │ │ │ │ │
                                        │ │ │ │ └──── Weekday (0-7, Sunday is 0 or 7)
                                        │ │ │ └────── Month (1-12)
                                        │ │ └──────── Day (1-31)
                                        │ └────────── Hour (0-23)
                                        └──────────── Minute (0-59)
                                        

                                        So for your special wish ^^it should look like this:

                                        # /etc/crontab: system-wide crontab
                                        # Unlike any other crontab you don't have to run the `crontab'
                                        # command to install the new version when you edit this file
                                        # and files in /etc/cron.d. These files also have username fields,
                                        # that none of the other crontabs do.
                                        
                                        SHELL=/bin/sh
                                        PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
                                        
                                        # m h dom mon dow user  command
                                        17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
                                        25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
                                        47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
                                        52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
                                        0 6,16  * * 1,2,3,4,5   root  /home/pi/monitor_on.sh
                                        0 9,22  * * 1,2,3,4,5   root  /home/pi/monitor_off.sh
                                        0 8     * * 6,7   root  /home/pi/monitor_on.sh
                                        0 22    * * 6,7   root  /home/pi/monitor_off.sh
                                        #
                                        

                                        Or if you don’t want to create the *.sh files u can also just type the directly command.
                                        Like this:

                                        0 6,16  * * 1,2,3,4,5   root  /usr/bin/tvservice -p
                                        0 9,22  * * 1,2,3,4,5   root  /usr/bin/tvservice -o
                                        0 8     * * 6,7   root  /usr/bin/tvservice -p
                                        0 22    * * 6,7   root  /usr/bin/tvservice -o
                                        

                                        Last thing is the extremely easiest way because u just need to modify the crontab. there is nothing else needed at all.
                                        Just put these commands in your crontab and u are done ^^

                                        1 Reply Last reply Reply Quote 0
                                        • R Offline
                                          robmcc83
                                          last edited by

                                          That’s brill your a legend, got a few hours to myself tomorrow so armed with all this information and sure be giving this a try see what the outcome is.
                                          Thank you so much :)

                                          1 Reply Last reply Reply Quote 0
                                          • Mykle1M Offline
                                            Mykle1 Project Sponsor Module Developer @Mykle1
                                            last edited by Mykle1

                                            @Mykle1 said in Want to turn off my monitor:

                                            { exec(‘xset dpms force on’, null); }
                                            { exec(‘xset dpms force off’, null); }

                                            These commands do work. I just tested them on my desktop machine with a monitor connected through DVI and a laptop. Displays are immediately turned off (standby) and on. Here’s the laptop.

                                            https://youtu.be/3ldlUPkw2nM

                                            Create a working config
                                            How to add modules

                                            R 1 Reply Last reply Reply Quote 2

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • 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