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

MMM-Pir-Sensor - Hue lights control

  • Hey!

    Im using a pir sensor on my mirror and the MMM-Pir-Sensor module.
    Wich works just great.

    Thing is tho, i also added a little python script to turn on some hue light strips i have on the back of the mirror. Wich is being executed when the screen turns on from movement being detected. Buuuut, that is a slow and sluggish way of doing it.

    import requests
    import time
    colors = {'white':'{"on":true,"bri":255,"sat":0,"hue":0}',
    hour = time.localtime().tm_hour
    time_colors = {(0,2):'red', (2,7):'blue', (7, 20):'white', (20,24):'yellow'}
    color_schema  = {hour:color for hours, color in time_colors.items() for hour in range(hours[0], hours[1])}
    color = colors[color_schema[hour]]
    headers = {
        'Accept': 'application/json',
    requests.put('', headers=headers, data=color)

    Thats the actual script being ran. But execing python from within the node helper.js its too much delay for my liking.
    Does anyone have any decent suggestions for speeding this up or a better way of doing it?

  • Anyone? 🙂

  • Thats exactly what i am already doing. But its too slow for my taste :p

  • I found it to slow running it through the mm, maybe cause I’m running it from a pi0.
    So I run the PIR python script (it also does the led strips) as a background task outside of mm enabled at boot via crontab.
    It’s more responsive and seems to use less resources.

Log in to reply