The MMM-Hue-Motion-Screensaver module allows you to automatically control the screen of your MagicMirror² based on motion detected by a Philips Hue motion sensor.
With this module, you can ensure that your MagicMirror² is only active when someone is nearby, providing a seamless and intelligent user experience, as well as saving energy and extending the life of your screen. It is easy to integrate into your existing MagicMirror² setup.
In your terminal, go to your MagicMirror² Module folder and clone MMM-Hue-Motion-Screensaver:
cd ~/MagicMirror/modules
git clone https://github.com/Zaro-kar/MMM-Hue-Motion-Screensaver.git
cd ~/MagicMirror/modules/MMM-Hue-Motion-Screensaver
git pull
To use this module, add it to the modules array in the config/config.js
file:
{
module: 'MMM-Hue-Motion-Screensaver',
position: 'lower_third',
config: {
hueBridgeID: 'your-hue-bridge-id', // Required
sensorId: 'your-sensor-id', // Required
apiKey: 'your-api-key', // Required
}
}
Option | Possible values | Default | Description |
---|---|---|---|
hueBridgeID |
string |
N/A | Required. The ID of your Hue Bridge (e.g., "beb7cfcccd56ab3a") |
sensorId |
string |
N/A | Required. The ID of the motion sensor (e.g., "1") |
apiKey |
string |
N/A | Required. The API key for the Hue Bridge (e.g., "your-api-key") |
coolDown |
number |
300 | The cooldown time in seconds before the screen turns off (e.g., 300) |
activeDays |
array |
["Sat", "Sun"] | The days on which the module is always on (e.g., ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]). Note: The startTime and endTime settings are only effective on these days. |
startTime |
string |
"06:00" | The start time in "HH:MM" format (e.g., "06:00"). Note: This works only in conjunction with activeDays . The monitor will stay on between startTime and endTime only on the days defined in activeDays . |
endTime |
string |
"22:00" | The end time in "HH:MM" format (e.g., "22:00"). Note: This works only in conjunction with activeDays . The monitor will stay on between startTime and endTime only on the days defined in activeDays . |
pollInterval |
number |
2000 | The polling interval in milliseconds (e.g., 2000) |
language |
string |
"en" | The language for the display (available options: "en", "de") |
screenCommandOn |
string |
"xrandr -display :0.0 --output HDMI-1 --auto" | The command to turn the screen on. You can also specify additional options like --rotate left , --brightness 0.7 , etc. |
screenCommandOff |
string |
"xrandr -display :0.0 --output HDMI-1 --off" | The command to turn the screen off. You can also specify additional options like --rotate left , --brightness 0.7 , etc. |
Note: This module has been tested with xrandr
and works by default with it. While you can theoretically provide a command for another driver like Wayland, functionality with other drivers is not guaranteed.
Official 'Getting Started' guide from Philips Hue
To find the ID of your Hue Bridge, you can use the following command:
openssl s_client -showcerts -connect <Bridge-IP-Address>:443
The output will include a line like this:
# I've replaced the actual ID with 'HUE_BRIDGE_ID'
subject=/C=NL/O=Philips Hue/CN=<HUE_BRIDGE_ID>
issuer=/C=NL/O=Philips Hue/CN=<HUE_BRIDGE_ID>
In order to use https for the requests to the Hue Bridge, you have to add the hueBridgeID
along with the IP address of the Hue Bridge to the /etc/hosts
file:
sudo nano /etc/hosts
Add the following line:
<Bridge-IP-Address> <hueBridgeID>
To generate an API key for your Hue Bridge, follow these steps:
- Press the link button on your Hue Bridge.
- Within 30 seconds, send a POST request to the Hue Bridge using a tool like
curl
:curl -X POST -d '{"devicetype":"my_hue_app"}' http://<hue-bridge-ip>/api
- The response will contain a username, which is your API key.
To find the ID of your Hue motion sensor, you can use the Hue API. Open a web browser and go to https://<bridge-ip-address>/clip/v2/resource/device
. Make sure you are on the same network as the bridge and use the IP address obtained earlier. Look for the sensor with the type "ZLLPresence" and note its ID.
The hue_bridge_ca_cert.pem
file included in this project is the public CA certificate for the Hue Bridge. It is used to establish a secure HTTPS connection with the Hue Bridge. You can find this certificate on the official Philips Hue developer website: Using HTTPS.
Notification | Description |
---|---|
CHECK_MOTION |
Checks the motion status of the sensor |
TOGGLE_SCREEN |
Toggles the screen on or off |
npm install
- Install devDependencies like ESLint.npm run lint
- Run linting and formatter checks.npm run lint:fix
- Fix linting and formatter issues.