MagicMirror² v2.14.0 is available! For more information about this release, check out this topic.

Device detection - personalised message

  • Hi. I’ve been hacking around with some python code to create a module that can pick up a known device (via MAC address) and if detected push up a message. Having no Python experience it’s been trial and error. It’s working but only just! Two problems are that when it’s publishing the result it appears to be flicking between the MAC detected message and MAC not detected message. Also when Python is calling the ‘import bluetooth’ line it appears to be conflicting with the Pi’s WIFI (as speeds drop to next to nothing). I’m running a Pi3. Appreciate both of these are not core MagicMirror issues - but just throwing them here if of interest to anyone, or someone can help.

    Here’s the module js (athomecheck.js)

            defaults: {
                    prependString: 'HOME: '
            start: function() {
                    this.athome = 'fetching ...';
            socketNotificationReceived: function(notification, payload) {
                if (notification === 'ATHOMECHECK') {
                    this.athome = payload;
            // Override dom generator.
            getDom: function() {
                    var wrapper = document.createElement("div");
                    wrapper.innerHTML = this.config.prependString + this.athome;
                    return wrapper;

    Here’s the node_helper.js

    var NodeHelper = require("node_helper");
    var PythonShell = require('python-shell');
    module.exports = NodeHelper.create({
                    start: function function_name () {
                    var self = this;
                    setInterval(function() {
                    }, 1000);
            sendUpdate: function() {
                    const self = this;
                    const pyshell = new PythonShell('', { mode: 'text', scriptPath: 'modules/athomecheck'});
                    pyshell.on('message', function(message){
                            self.sendSocketNotification('ATHOMECHECK', message);

    and the python script

    import bluetooth
    import time
    import sys
    outputa = "x"
    outputb = "y"
    binder = ""
    while True:
            result = bluetooth.lookup_name('EX:AM:PL:E1:MA:C2', timeout=5)
            if (result != None):
                    outputa = "Hello Mr SMITH"
                    outputa = ""
            result2 = bluetooth.lookup_name('EX:AM:PL:E1:MA:C3', timeout=5)
            if(result2 != None):
                    outputb = "Hello Mrs SMITH"
                    outputb = ""
            if(result != None and result2 != None):
                    binder = ", "
            print outputa + binder + outputb


  • Hi. FYI I’ve changed the module refresh rate to 30 secs, and also refined the python script:

    import bluetooth
    macs = { "Mr Smith":"EX:AM:PL:E1:MA:C1", "Mrs Smith":"EX:AM:PL:E2:MA:C2" }
    for macname, macnumber in macs.iteritems():
            result = bluetooth.lookup_name(macnumber, timeout=5)
            if (result != None):
                    print macname, "IN",

    Still experiencing the Bluetooth / Wifi conflict, but doesn’t seem to be compromising the MagicMirror output too much.

  • Hey guy, are you still on it ?

  • Project Sponsor Module Developer

  • :-p thanks 🙂

Log in to reply