Last minute Halloween scary sound raspberry pi project

AdySan

Young grasshopper
Joined
Aug 26, 2018
Messages
32
Reaction score
12
Location
Bellevue, WA
hello folks,

I have an idea for a last minute Halloween project to scare trick or treaters. My front door camera gets triggered reliably when someone enters the front yard. I would like to send a web hook/Mqtt message to a raspberry pi (which is physically connected to a little speaker) and make it generate a random scary sound. Should be rather easy, but given the lack of time I don’t want to experiment a lot. Anyone have experience with what’s the easiest, most reliable way to do this with a BI server? I know BI supports things like IFTTT and MQTT. If there’s a simple python script someone can help me get started with I can polish it up.

TIA, Ady
 

looney2ns

IPCT Contributor
Joined
Sep 25, 2016
Messages
15,521
Reaction score
22,657
Location
Evansville, In. USA
hello folks,

I have an idea for a last minute Halloween project to scare trick or treaters. My front door camera gets triggered reliably when someone enters the front yard. I would like to send a web hook/Mqtt message to a raspberry pi (which is physically connected to a little speaker) and make it generate a random scary sound. Should be rather easy, but given the lack of time I don’t want to experiment a lot. Anyone have experience with what’s the easiest, most reliable way to do this with a BI server? I know BI supports things like IFTTT and MQTT. If there’s a simple python script someone can help me get started with I can polish it up.

TIA, Ady
Hook a speaker to the BI computers' audio out, setup an alert to trigger a sound to that speaker.
 

AdySan

Young grasshopper
Joined
Aug 26, 2018
Messages
32
Reaction score
12
Location
Bellevue, WA
I was able to get this to work with this simple python script running on the pi!

Code:
#!/usr/bin/python#!/usr/bin/python

import paho.mqtt.client as mqtt
import os

MQTT_SERVER = "192.168.10.74"
MQTT_PATH = "app"


# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe(MQTT_PATH)

# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))
    os.system('mpg123 -q /home/pi/scream.mp3 &')
    # more callbacks, etc

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect(MQTT_SERVER, 1883, 60)

# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.
client.loop_forever()
 
Top