@bibi: I’ve only tested my solution for a couple of days, so I can’t say much about the long term stability. The reason for this is simply that I was in the process of designing a (nearly) frameless mirror the last couple of months. The components have been ordered and I hope to assemble everything in the coming month. It might take a bit longer, as I have quite a few business trips lined up for November.
Read the statement by Michael Teeuw here.
Posts made by IngmarSwart
-
RE: PIR-Sensor - put your mirror to sleep if not used
-
RE: PIR-Sensor - put your mirror to sleep if not used
@Defibrillat0r: Thanks. Yes, I use the virtual environment. That being said, I don’t think it is stricktly necessary. In our configuration, the RPi is dedicated to running the MM, so the likelyhood that you need different versions of packages is very small. If you do use the virtual environment, you just have to make sure all the packages listed at the top of the python file are installed for the virtual environment you are working on. Other than that, no special tricks are needed.
@bibi: In my solution a PIR sensor is not needed. You only use @paviro’s module to interface the python code with the MM.
-
RE: PIR-Sensor - put your mirror to sleep if not used
Hi @DirkS,
I use a standard first generation RPi camera board. In other words, this solution works perfectly fine with IR filter on the camera.
The reason I think there might be issues with the RPi2: you should realize that this solution requires the RPi to analyze 10 images per second (give or take a few, you can specify the frame rate) using OpenCV routines. This causes a significant bump in processor load (approximately 33% on the RPi3 on top of everything else, if I’m not mistaken). I simply don’t know if the processor of the RPi2 is fast enough to do the image analysis, run the MM and the operating system simultaneously. The only way to know for sure is to test. I can’t help you with that as I don’t own a RPi2. Should the RPi2 struggle, perhaps you can get away with analyzing fewer frames (5 or maybe even 2). I encourage you to try and report back!
Best wishes,
Ingmar -
RE: PIR-Sensor - put your mirror to sleep if not used
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 theconf.json
file. Don’t forget to add the comma behind the previous entry. - Optional but recommended to get a clean exit:
Insert the wholefor
loop in atry
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.
- Disable the red LED on the Picamera by adding
-
Forecast lines
Dear all,
I love biking to work. Just not so much when it rains. Since it rains quite a bit where I live (the Netherlands), it would be very useful if I could simply look at the Magic Mirror to see when it will rain (and how much). I’m thinking of a module that displays graphs such as those being shown at e.g. http://forecast.io/lines/, in particular the ‘next hour’ one. Another example of such a graph can be found here: http://www.buienalarm.nl/location/utrecht (in Dutch)
It is relatively easy to show radar maps such as those at http://www.buienradar.nl/ on the Magic Mirror. Unfortunately, these maps are in green and blue. Not the optimal colours for the magic mirror if you ask me. I don’t have the NodeJS/Javascript skills to create a module showing graphs showing the expected precipitation. Any suggestions where to start and/or help coding this module are most welcome!
-
RE: PIR-Sensor - put your mirror to sleep if not used
@KirAsh4 I agree, it’s very strange. Like you, I am using a rPi-3 with the most recent version of Raspbian Jessie and run everything as user
pi
. So maybe it is the monitor (Philips 273V5l). Which one do you use?Although the problem is fixed, I would like to know what is going on.
-
RE: PIR-Sensor - put your mirror to sleep if not used
@MechMatt Have a look at the PowerSwitch Tail. If you live in the US, you can buy an assembled version from Adafruit. If you’re in 240V land (like me), you will have to do some (basic) soldering. Works like a charm for me. :-)
-
RE: PIR-Sensor - put your mirror to sleep if not used
@paviro I finally found some time to look into the problem I had some more. The exact origin is still unclear to me, but I did figure out that my problem, it is not related to your module, or the MM software in general. I got the same behaviour over ssh:
tvservice -o
switches the monitor connected to the Pi off,tvservice -p
switches it back on, but the screen would appear black. After fiddling around a little bit, I found another solution that does not require root rights. Instead of using thesudo chvt 7 && sudo chvt 9
command, the problem can also be solved usingfbset
. My modified version of the activateMonitor function file node_helper.js:activateMonitor: function () { if (this.config.relayPIN != false) { gpio.digitalWrite(this.config.relayPIN, this.config.relayOnState) } else if (this.config.relayPIN == false){ exec("/opt/vc/bin/tvservice -p", null); exec("/bin/fbset -depth 8 && /bin/fbset -depth 16 ", null); exec("/usr/bin/xrefresh",null); }
For the command
xrefresh
to work when given via ssh, the correct display variable has to be set (in my case):
export DISPLAY=:0
I have added this line to my .profile file in the /home/pi directory so that I don’t have to type it every time I log in via ssh. -
RE: PIR-Sensor - put your mirror to sleep if not used
@paviro, I also don’t understand where it comes from, especially since the MagicMirror appears as it should immediately after boot. At first glance, the monitor (Philips 273V5L) and Pi seem to play nice: EDID information is correct,
tvservice -s
gives the native resolution and refresh rate of the monitor. If I can find some time, I will look into it. However, I am also quite earger to start playing with your Facial-Recognition module… :relaxed: -
RE: PIR-Sensor - put your mirror to sleep if not used
@paviro, if I understoof the documentation correctly, the command
chvt
simply changes the foreground terminal. It appears that in my case the the output of the RasPi is send to another terminal than that is displayed on the monitor.My apologies for not using the markdown code. I only recently started using GitHub etc, so I have some learning to do when it comes to opening pull requests.
I just tested to confirm if the use of
sudo
is required. Unfortunately, it is.