MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Simple python script for pir motion sensor

    Scheduled Pinned Locked Moved General Discussion
    2 Posts 1 Posters 2.3k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • KimzerK Offline
      Kimzer
      last edited by

      Hey guys
      I managed to throw together this bit below by looking at other pir sensor scripts to control a set of hue strips. Its probably a million better ways to do this but this is where im at.

      The problem is that this scripts overrides whatever i do from say my phone app.
      If i turn on the lights from my phone and there is no movement next to the sensor it will kill the lights after a sec or two. This i want to avoid, i would like this script to be able to be overrun by the controls elsewhere. Could someone please help me out with this?

      import RPi.GPIO as GPIO
      import time
      GPIO.setwarnings(False)
      GPIO.setmode(GPIO.BOARD)
      GPIO.setup(15, GPIO.IN)         #Read output from PIR motion sensor
      while True:
             i=GPIO.input(15)
             if i==0:                 #When output from motion sensor is LOW
                   print "No movement detected - Turning lights off",i
                   exec(open("./LightsOff.py").read(), globals())
                   time.sleep(1)
             elif i==1:               #When output from motion sensor is HIGH
                   print "Movement detected - Turning lights on",i
                   exec(open("./LightsOn.py").read(), globals())
                   time.sleep(60 * 30)
      

      Edit; the time.sleep (60 * 30) is used because i want the light to stay on for 30 minutes after there has been movement infront of the pir sensor. There is probably a better solution to this somewhere?

      The two scripts being executed is merely a couple of scripts telling the hue bridge to turn lights on/off.
      Let me know if those are needed for any reason and i will post them.

      1 Reply Last reply Reply Quote 0
      • KimzerK Offline
        Kimzer
        last edited by

        Anybody?

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Enjoying MagicMirror? Please consider a donation!
        MagicMirror created by Michael Teeuw.
        Forum managed by Sam, technical setup by Karsten.
        This forum is using NodeBB as its core | Contributors
        Contact | Privacy Policy