Hello! I’ve been using a MagicMirror for years and have worked on and developed modules for a while as well, but this is the first I’m posting here on the forums in hopes someone finds it useful besides myself.
I’ve used various PIR modules to make my screen only turn on when someone moves in front of the mirror, to save a lot of power during most times when there’s nobody there. But recently, I’ve installed a bunch of Zigbee motion / presence sensors as part of my smart home upgrades, and decided to ditch the standalone sensor on the mirror and integrate it into the global presence detection instead. The simplest way to do this is via MQTT, since all sensor data flows through there anyway, and the integration can be really lightweight.
What came out is https://github.com/olexs/MMM-MQTTScreenOnOff. Take a look :) No screenshots, since it is a pure background module with nothing rendered to screen.
The default option values approximate a connection to local MQTT and subscribing to a Zigbee2MQTT motion / occupancy sensor data. The module also allows to make the mirror turn the display off at startup (assuming it may restart at night during automated updates, or after a power outage, etc).
You can configure the commands used to turn the screen on and off - by default I use DISPLAY=:0.0 xrandr --output HDMI-1 --auto
and DISPLAY=:0.0 xrandr --output HDMI-1 --off
, this works on a current out-of-the-box Raspberry Pi OS (ex-Raspbian) installation, but you may need something else depending on which hardware and OS your mirror is running on.
Finally, you can optionally make the module broadcast a USER_PRESENCE
message to other modules in the mirror when the screen turns on and off. This can be useful to disable regular updates when the mirror is inactive, especially for modules that use quota-limited or paid APIs (e.g. Google Maps or similar).
I’ve been using this for almost a year now, and it’s solid. External sensor works much more reliably for me than any standalone PIR I’ve plugged into the mirror itself before.
Let me know what you think.