Skip to content

Instantly share code, notes, and snippets.

@bphermansson
Created November 8, 2022 09:31
Show Gist options
  • Save bphermansson/f3c990f19042a112354e8d8eff6cb811 to your computer and use it in GitHub Desktop.
Save bphermansson/f3c990f19042a112354e8d8eff6cb811 to your computer and use it in GitHub Desktop.
# Code inspired by https://projects.raspberrypi.org/en/projects/physical-computing/11
from gpiozero import MotionSensor
import paho.mqtt.client as paho
import json
pir = MotionSensor(22)
mqtt_pir_topic = "magicmirror/pir"
broker="192.168.1.190"
client= paho.Client("MagicMirrorSensors")
while True:
pir.wait_for_motion()
print("You moved")
client.connect(broker)
client.loop_start()
client.publish(mqtt_pir_topic, "MagicMirror movement detected!")
pir.wait_for_no_motion()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment