How to trigger a script on pi 3?


just copy and paste here. i cannot access your link.

#!/usr/bin/env python

from picamera import PiCamera
from time import sleep
import RPi.GPIO as GPIO
import datetime

camera = PiCamera()

GPIO.setup(18, GPIO.IN) #PIR
camera.rotation =180 # flip the pic

import cayenne.client
import time
x = 0
# Cayenne authentication info. This should be obtained from the Cayenne Dashboa$
# Cayenne authentication info. This should be obtained from the Cayenne Dashboa$


# The callback for when a message is received from Cayenne.
def on_message(message):
    global x
    print("message received: " + str(message))
    # If there is an error processing the message return an error string, other$
    if ( == 4) and (message.value == "1"):
        print("button is pressed")
        x = 1
    if ( == 5) and (message.value == "1"):
        print("quit button is pressed")

client = cayenne.client.CayenneMQTTClient()
client.on_message = on_message
    indent preformatted text by 4 spaces



timestamp = 0

motion = False
motioncounter = 0
while True:
if motion:
motioncounter += 1
if (not motion) or (motioncounter > 50):
if motioncounter > 50:
motioncounter = 0
if GPIO.input(18):
print(“Motion Detected…”)
dt =
fn = ‘{:/home/pi/mqtt/examples/pic/%Y%m%dT%H%M%S.jpg}’.format(dt)
#time.sleep(5) ####If you really do need a delay here make it less $


        motion = True
        motioncounter = 0
        if (time.time() > timestamp + 10):
            print("making two state zero")
            timestamp = time.time()
            motion = False

  indent preformatted text by 4 spaces


this is because the button channel is 5 and when channel 5 becomes 1 it runs:

which shutdown the raspberry pi.

when adding a button select channel as 6.


Yes,that is correct, but I added a new widget on channel 7 with a trigger that should send an email.
When I press this widget, the pi keep running, but no email is sent, and the trigger run 0 times


sir,Would you mind sharing you account with me ? You can PM me your login and password and change your password here if you need.


It is Devise 2346


Now the triggers are working for motion and button.
Very good.Then I can start my project.
Now it is time to test if also sms is working.

Yes it is working …yipppi


once done, share the project with community.