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

Strip Down Guide for BenQ 28" VA Monitor GC2870H

Scheduled Pinned Locked Moved Hardware
61 Posts 10 Posters 49.8k Views 10 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.
  • M Offline
    MadScientist @bachoo786
    last edited by Jan 4, 2019, 10:19 AM

    @bachoo786 The sensor should have three pins: VCC, GND and signal out. You connect them the same way you connect a PIR sensor and it should also work with the same MM module MMM-PIR-Sensor.

    1 Reply Last reply Reply Quote 0
    • Y Offline
      yep_DD @bachoo786
      last edited by yep_DD Jan 5, 2019, 12:41 PM Jan 5, 2019, 12:40 PM

      Hi @bachoo786

      thank you so much. As @MadScientist pointed out the three pins are connected directly to the Raspberry. For evaluating the state I use a small http server (see below). The important parts are where the you can find anything with

      monitorStatus
      

      If you want I can reduce the code to what is important for you. This is the complete server which allows control of

      • ARD Livestream
      • ARD Tagesschau
      • Lowering / Increasing volume
      • Radar Sensor (just the last couple lines of code (search for: GPIO.add_event_detect)
      • Powerin On / Off Monitor by http Request (used if no one is at home / and at night)

      For me the radar sensor is just a backup. I use the power control mainly like this:

      • If someone is at home and it is between sunrise / sunset, turn on the monitor(1)
      • If someone is at home but it is night and all lights are off, turn off the monitor(1)
      • If someone is in front of the monitor turn it on by radar

      (1) is done via FHEM (a home automation running on another raspberry, it calls my mirror like this: 10.0.1.49/on (monitor on) 10.0.1.49/off (monitor off) 10.0.1.49/up or /down (for volume) and so on.

      #!/usr/bin/python3 -u
      host_name = '10.0.1.49'  # Change this to your Raspberry Pi IP address
      host_port = 8000
      proc = ''
      monitorstatus = 'unknown'
      
      import RPi.GPIO as GPIO
      from pathlib import Path
      import os
      import subprocess
      import signal
      from subprocess import call
      from time import sleep
      from http.server import BaseHTTPRequestHandler, HTTPServer
      
      
      SENSOR_PIN = 24
      
      GPIO.setmode(GPIO.BCM)  
      GPIO.setup(SENSOR_PIN, GPIO.IN) 
      
      class MyServer(BaseHTTPRequestHandler):
      
          def monitor_on(channel): #define initial status of Monitor
              if monitorstatus!="on":
                  status='Monitor on by Radar Sensor'
                  #monitorstatus='on'
                  subprocess.Popen(["/usr/bin/vcgencmd", "display_power", "1"], preexec_fn=os.setsid)
      
          def do_HEAD(self):
              self.send_response(200)
              self.send_header('Content-type', 'text/html')
              self.end_headers()
      
          def do_GET(self):
              global proc
              global monitorstatus
              html = '''
                 <html>
                 <body style="width:960px; margin: 20px auto;">
                 <h1>Magic Mirror Control</h1>
                 <p>Current GPU temperature is {}</p>
                 <p>Podcast: <a href="/play">Play</a> <a href="/stop">Stop</a></p>
                 <p>ARD Livestream: <a href="/ard">Play</a> <a href="/stop">Stop</a></p>
                 <p>Volume: <a href="/down">down</a> <a href="/up">up</a></p>
                 <p>System: <a href="/shutdown">Shutdown</a> <a href="/restart">Restart</a></p>
                 <p>Monitor: <a href="/on">On</a> <a href="/off">Off</a></p>
                 <div id="podcast-status"></div>
                 <script>
                     document.getElementById("podcast-status").innerHTML="{}";
                 </script>
                 </body>
                 </html>
              '''
              temp = os.popen("/opt/vc/bin/vcgencmd measure_temp").read()
              self.do_HEAD()
              status = ''
              if self.path=='/':
                  #GPIO.setmode(GPIO.BCM)
                  #GPIO.setwarnings(False)
                  #GPIO.setup(17, GPIO.IN)
                  status='nothing'
              elif self.path=='/play':
                  if proc=='':
                      my_file = Path("/home/pi/MagicMirror/video.mp4")
                      if my_file.is_file():
                          statinfo = os.stat('/home/pi/MagicMirror/video.mp4')
                          if statinfo.st_size > 0:
                              proc = subprocess.Popen(["omxplayer", "-o", "alsa:hw:ALSA", "--no-osd", "/home/pi/MagicMirror/video.mp4"], preexec_fn=os.setsid)
                              status='Playing Podcast'
                          else:
                              proc = subprocess.Popen(["omxplayer", "-o", "alsa:hw:ALSA", "--no-osd", "/home/pi/MagicMirror/Loading.mp4"], preexec_fn=os.setsid)
                              status='Not yet available'
                      else:
                          proc = subprocess.Popen(["omxplayer", "-o", "alsa:hw:ALSA", "--no-osd", "/home/pi/MagicMirror/Loading.mp4"], preexec_fn=os.setsid)
                          status='Not yet available'
                  else:
                      status='Stopping Podcast'
                      os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
                      proc=''
              elif self.path=='/ard':
                  if proc=='':
                      proc = subprocess.Popen(["livestreamer", "hlsvariant://daserste_live-lh.akamaihd.net/i/daserste_de@91204/master.m3u8", "best", "-vnp", "omxplayer -o alsa:hw:ALSA --no-osd --timeout 20"], preexec_fn=os.setsid)
                      status='Playing ARD Livestream'
                  else:
                      status='Stopping Stream'
                      os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
                      proc=''
              elif self.path=='/stop':
                  if proc!='':
                      status='Stopping Podcast'
                      os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
                      proc=''
                  else:
                      status='Nothing to stop'
              elif self.path=='/shutdown':
                  status='Shutdown'
                  subprocess.Popen(["sudo", "shutdown", "-h", "now"], preexec_fn=os.setsid)
              elif self.path=='/restart':
                  status='Restart'
                  subprocess.Popen(["sudo", "reboot"], preexec_fn=os.setsid)
              elif self.path=='/down':
                  status='Volume down'
                  subprocess.Popen(["amixer", "set", "Master", "8%-"], preexec_fn=os.setsid)
              elif self.path=='/up':
                  status='Volume up'
                  subprocess.Popen(["amixer", "set", "Master", "8%+"], preexec_fn=os.setsid)
              elif self.path=='/on':
                  if monitorstatus!="on": #switch on Monitor if status was off (by httpRequest NOT Radar)
                      status='Monitor on'
                      monitorstatus='on'
                      subprocess.Popen(["/usr/bin/vcgencmd", "display_power", "1"], preexec_fn=os.setsid)
              elif self.path=='/off':
                  if monitorstatus!="off": #switch off Monitor if status was on  (by httpRequest NOT Radar)
                      status='Monitor off'
                      monitorstatus='off'
                      subprocess.Popen(["/usr/bin/vcgencmd", "display_power", "0"], preexec_fn=os.setsid)
              self.wfile.write(html.format(temp[5:], status).encode("utf-8"))
      
      
      if __name__ == '__main__':
          http_server = HTTPServer((host_name, host_port), MyServer)
          print("Server Starts - %s:%s" % (host_name, host_port))
      
          try:
              GPIO.add_event_detect(SENSOR_PIN , GPIO.RISING, callback=MyServer.monitor_on) #detect radar sensor and enable Monitor
              http_server.serve_forever()
          except KeyboardInterrupt:
              http_server.server_close()
      GPIO.cleanup()
      
      
      1 Reply Last reply Reply Quote 0
      • B Offline
        bachoo786
        last edited by Jan 8, 2019, 2:09 AM

        @MadScientist @yep_DD Thanks for the replies. Is there anyway to limit the distance that the radar sensor senses? I have my magic mirror in the bath room and it faces the wooden door which I believe will be detecting motion through it and I don’t want that.

        Y 1 Reply Last reply Jan 8, 2019, 6:33 PM Reply Quote 0
        • M Offline
          MadScientist
          last edited by Jan 8, 2019, 2:45 PM

          I have a sensor that allows changing the sensitivity but for me the lowest was still to much as it got triggered when somebody walked by outside my house. I am using a PIR-Sensor now.

          1 Reply Last reply Reply Quote 0
          • Y Offline
            yep_DD @bachoo786
            last edited by yep_DD Jan 8, 2019, 6:34 PM Jan 8, 2019, 6:33 PM

            @bachoo786 apparently it also depends on the quality of the sensor, I ordered a batch on ebay and got lucky with one where I have to get really close to the glass to trigger it. at first I thought I would change it, but now I am satisfied because it fits the purpose of just activating in case the mirror is off and the other power-on / off logic didn’t work (guests at home). But if I had to redesign I would not use a sensor at all as my other ways of powering the mirror seem far more integrated, e.g. I do not want to see the mirror turn on and / off as this disturbs the design.

            1 Reply Last reply Reply Quote 0
            • B Offline
              bachoo786
              last edited by Jan 9, 2019, 12:14 AM

              @MadScientist is your pir visible near your mirror?as it wouldn’t work behind the mirror.

              @yep_DD are you talking about the rcwl0516? I have read that using a low value resistor can decrease the range of detection up to 5cm. Trouble is I don’t where to connect the additional resistor and the low value of it too.

              1 Reply Last reply Reply Quote 0
              • M Offline
                MadScientist
                last edited by Jan 9, 2019, 6:47 AM

                I have it incorporated in the frame. I drilled a 2 or 3mm hole in the front of the frame and a 8mm hole from the back which only goes half way through. The 8mm are perfect to mount the PIR sensor without the lense. The mirror only activates when you are directly in front of it and it’s hardly visible.

                B 1 Reply Last reply Jan 9, 2019, 9:01 AM Reply Quote 0
                • B Offline
                  bachoo786 @MadScientist
                  last edited by Jan 9, 2019, 9:01 AM

                  @madscientist is it possible to share a photo please?

                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    MadScientist
                    last edited by Jan 9, 2019, 12:11 PM

                    View from the back:
                    0_1547035553395_IMG_20180207_185809.jpg

                    View from the front:
                    0_1547035794660_IMG_20180207_185957.jpg

                    PIR sensor without IR lense and the inside-8mm-hole:
                    0_1547035573916_IMG_20190109_130158.jpg

                    B 1 Reply Last reply Jan 11, 2019, 9:43 AM Reply Quote 0
                    • B Offline
                      bachoo786 @MadScientist
                      last edited by Jan 11, 2019, 9:43 AM

                      @madscientist very well done and looks neat thanks for that

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