Created
November 8, 2022 09:31
-
-
Save bphermansson/f3c990f19042a112354e8d8eff6cb811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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