MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.24.0 is available! For more information about this release, check out this topic.

    MMM-PIR-Sensor with RelayPin and execute script

    Troubleshooting
    3
    9
    3621
    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.
    • nogE
      nogE last edited by

      Hi,
      My goal is: PIR Sensor detect presence and switch the relay pin. Additionally it should execute ah script hue_on.sh to switch MirrorLight on.
      Scripts works fine form CLI
      In which position of the node_helper.js from MMM-PIR-Sensor Module i put the lines
      exec(“/home/pi/scripts/hue_on.sh”, null);
      exec(“/home/pi/scripts/hue_off.sh”, null);

      pls help
      thx

      1 Reply Last reply Reply Quote 0
      • B
        Blackmirror last edited by yawns

        I have build in this python script in tho rc.local

        import RPi.GPIO as GPIO
        import time
        
        
        #Board Mode: Angabe der Pin-Nummer
        GPIO.setmode(GPIO.BOARD)
        
        #GPIO Pin definieren fuer den Dateneingang vom Sensor
        PIR_GPIO = 13
        Relay_GPIO = 37
        GPIO.setup(PIR_GPIO, GPIO.IN)
        GPIO.setup(Relay_GPIO, GPIO.OUT)
        GPIO.output(Relay_GPIO, True)
        GPIO.setup(32,GPIO.IN)
        
        read=0
        wait=0
        ein=0
        button=1
        
        while True :
           #PIR auslesen
           read = GPIO.input(PIR_GPIO)
           button = GPIO.input(32)
        
           if ((read==1 or button==0) and wait==0):
             GPIO.output(Relay_GPIO, False)
             wait=1
             ein=1
             time.sleep(0.5)
           elif ein==1 and button==0:
             ein=0
             time.sleep(0.5)
        
        1 Reply Last reply Reply Quote 0
        • nogE
          nogE last edited by

          Hi Blackmirror,
          thx for helping, i am no coders.
          pls can you explain me, howto it works to start with your script my hue_on.sh and hue.off.sh scripts?

          best regards
          Egon

          1 Reply Last reply Reply Quote 0
          • nogE
            nogE last edited by

            Sorry i understand. MMM-PIR-Sensor config with no RelayPin config. Make RelayPin with your script.

            B 1 Reply Last reply Reply Quote 0
            • B
              Blackmirror @nogE last edited by

              @nogE
              The MMM-PIR-Sensor module have not work at me.

              So i make a new datei this the name PIR.py in my home - ordner.
              And add python PIR.py in the rc.local
              After this was switch the PIR on the GPIO-Pin 13 the relay-pin 37. Add pin 32 i have a button to open the relay manual.

              1 Reply Last reply Reply Quote 0
              • nogE
                nogE last edited by

                when execute the python script (python /home/pi/scripts/light.py), i got following error:

                File “/home/pi/scripts/light.py”, line 22
                read = GPIO.input(PIR_GPIO)

                1 Reply Last reply Reply Quote 0
                • nogE
                  nogE last edited by

                  Hi,

                  i got an error when i run python script. now the whole error message:

                  File “/home/pi/scripts/light.py”, line 22
                  read = GPIO.input(PIR_GPIO)
                  ^
                  IndentationError: expected an indented block

                  thx

                  yawns 1 Reply Last reply Reply Quote 0
                  • yawns
                    yawns Moderator @nogE last edited by

                    @nogE
                    Python is a bit tricky. Unlike other languages python needs proper indentation. Make sure you don’t mix up tabs and whitespaces. Best practice is to use 4 whitespaces instead of one tab.

                    1 Reply Last reply Reply Quote 0
                    • B
                      Blackmirror last edited by

                      Yes, the error code says, you have not enought whitespaces before the lines.

                      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 Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy