Yes, this is yet another alarm clock! But I feel like I'm not the only one deisiring a nice and simple object like this one to keep on the bedside table.
It comes with useful features like a soft wake up (with chirping birds from a little bluetooth speaker), changing set of information and luminosity for day and night, weather, news. WiFi is turned off during sleep time. All very customizable!
It is mainly based on the beautiful MagicMirror project, but in this case we use it with a little screen to display information we need, without hiding everything behind a mirror.
If you know MagicMirror a little, you know that there are different modules to install, to provide different kinds of functionality. For my project I used:
- Clock (the default one)
- MMM-AlarmClock (we want an alarm clock, right?)
- CurrentWeather (default module)
- WeatherForecast (also default)
- NewsFeed (default)
- MMM-Online-State (to check weather WiFi is on or off)
- MMM-Tado (if you have a smart thermostat, you can display ambient info)
- MMM-ModuleScheduler (optional, to switch modules displayed)
Then I thought cron is the easy and right tool to program some events during the day(s). I'll show my crontab below.
Let's take a peek at my screen now (day version):
And now let's have a look at the night version:
Seen the difference? I don't need much information if I wake up at 3 a.m.: the clock is sufficient! And also the indication that the WiFi is turned on/off is ok (for example I set the on sign to yellow and off sign to blue).
So, if you like it, let's do it!
Hardware setupThe setup is so simple:
1) first, if you have a case, insert your Raspberry Pi (version 2, 3, or 4 will work) with the microSD card into it (make sure the relevant pins/connector can still be accessed to connect the screen);
2) then just connect the screen (whichever you want to use) to the Raspberry Pi; I would recommend a small one (like the 3.5" in the list), but you could also use the official Raspberry Pi Touch Display, or another one; the touch function will be useful (but not 100% necessary) to turn off the alarm clock;
3) then, if you are using a bluetooth speaker, it may be practical to power/recharge it directly from the Raspberry Pi USB, so just connect it to any USB port;
4) finally connect the power plug. Done!
Software installationNow time to go to the SW installation:
1) I assume you have a standard Raspberry Pi OS installation, with desktop, on a (small capacity, e.g. 8GB) microSD card.
2) MagicMirror installation: the so called "manual installation" is as easy as a copy and paste of a few commands, so I would recommend it.
3) MagicMirror (additional, 3rd party) Modules. For each of the following modules there's a separate installation, it's quick and easy (simple copy and paste again), just follow the links for instructions: first MMM-AlarmClock, we will use this to play music or nature sounds in the morning; MMM-Online-State, I find this useful to make sure WiFi is turned off during the night; optional, if you have a Tado thermostat, MMM-Tado, to show current and set temperature, humidity, etc.; the equivalent module for Netatmo is also available: MMM-Netatmo. I recently decided to try MMM-ModuleScheduler and never got back! It's easy to schedule the displaying of different modules at different times of the day/night.
4) The other modules we will use are default modules, so no further installation is required.
ConfigurationThere is one main configuration file to edit, plus you may want or need to tweak some other files, to optimize visualization and get the best result possible.
Let's start from the MagicMirror configuration file: you will find a sample file in your MagicMirror/config folder. I also provide my configuration file which you may use as a starting point. Find it below.
If you would like to have a day and night configuration, I suggest you create a config_day.js and config_night.js, as I did. Then we will switch them with a cron command (here at 11pm and 6am):
> crontab -e
# For more information see the manual pages of crontab(5) and cron(8)
# m h dom mon dow command
01 23 * * * cp /home/pi/MagicMirror/config/config_night.js /home/pi/MagicMirror/config/config.js
00 06 * * * cp /home/pi/MagicMirror/config/config_day.js /home/pi/MagicMirror/config/config.js
Alternatively, you could use the MMM-ModuleScheduler, which allows to show or hide different modules at different times, quite brilliant! You'll find my configuration file using the ModuleScheduler below.
Finally you may want or need to check the Raspberry Specific configurations, linked at the top of the configuration page. Especially to enable auto-startup and mouse pointer auto-hide.
Screen luminosityThis is an important topic, as we know how disturbing a bright screen can be while we are trying to sleep. And on the other hand we want a clearly readable screen in day light conditions. For some displays you can control the backlight illumination, this is true for the PiTFT screen I have. I made a little script to change luminosity with cron commands (again):
const raspi = require('raspi');
const pwm = require('raspi-pwm');
var myArgs = process.argv.slice(2);
var lumi = myArgs[0]/1000.0
raspi.init(() => {
const led = new pwm.PWM('GPIO18');
led.write(lumi); // 1-1000 duty Cycle, aka brightness
});
This will be executed by the following commands:
> sudo crontab -e
# For more information see the manual pages of crontab(5) and cron(8)
# m h dom mon dow command
@reboot /bin/sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'
@reboot /usr/bin/node /home/pi/screen_lumi.js 500
00 23 * * * /usr/bin/node /home/pi/screen_lumi.js 1
00 07 * * * /usr/bin/node /home/pi/screen_lumi.js 100
00 08 * * * /usr/bin/node /home/pi/screen_lumi.js 1000
00 19 * * * /usr/bin/node /home/pi/screen_lumi.js 800
The screen_lumi.js
script must be run with root privileges, so the screen luminosity will be handled by the root crontab.
This feature will let you sleep better, I believe. I prefer not to have Wi-Fi devices continuously radiating with wireless signals every night at a few centimeters from my head. So I introduce the Wi-Fi switch, thanks to the rfkill command run again by cron:
> crontab -e
# For more information see the manual pages of crontab(5) and cron(8)
# m h dom mon dow command
@reboot /usr/sbin/rfkill unblock wlan
00 23 * * * /usr/sbin/rfkill block wlan
00 7 * * * /usr/sbin/rfkill unblock wlan
This will turn Wi-Fi off during the night and on again in the morning (when you are supposed to get up!). The same command could also turn Bluetooth off, but I found that some Bluetooth speakers may not like it and have difficulties reconnecting timely for the morning alarm. Also, Bluetooth radiated power is quite lower than Wi-Fi and it's not a continuous transmission. Final remark: make sure you are not configuring your Alarm Clock through Wi-Fi when testing the "block wlan" command!
SpeakerIn my project I used a Bluetooth speaker (powered/recharged from the Raspberry Pi USB port). This can be easily configured in the Raspbian UI: first you need to find and pair the speaker from the Bluetooth menu, then you can select the speaker as an audio output device from the audio menu (see steps below). Of course, alternatively you could simply plug a 3.5" jack speaker (but in my case the Raspberry Pi PWM clock is busy dimming the screen backlight!).
Just a quick check on how we want to wake up: in my example below, the alarm clock will play an mp3 file I like, for 3 minutes, at 7am, every week day. Make sure you choose a soft nice sound, like the chirping birds in the forest! This is my preferred one (free to download): Birds in the forest.
{
module: 'MMM-AlarmClock',
position: 'top_left',
config: {
alarms: [
{time: "7:00",
days: [1,2,3,4,5],
title: "Wake-up!",
message: "It is 7.00am!",
sound: "birds-in-the-forest.mp3"},
],
format: 'dddd @ H:mm',
touch: 'true',
volume: 0.50,
timer: 180 * 1000
}
},
And from here you are free to experiment, tweak, improve, and adapt this project to your personal preferences!Let me know if you liked it! :-)
Comments