MMM-PIR-Sensor with RelayPin and execute script



  • 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



  • 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)
    


  • 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



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



  • @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.



  • 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)



  • 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


  • Moderator

    @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.



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


Log in to reply
 

Looks like your connection to MagicMirror Forum was lost, please wait while we try to reconnect.