Giter Club home page Giter Club logo

pi-motion-mqtt-sensor's Introduction

Pi Motion MQTT Sensor

This is a small script that turns a Raspberry Pi with a HC-SR501 PIR sensor into a Motion MQTT sensor for use with Home Assistant (or other IOT) equipment.

Other GPIO based PIR sensors should also work with minor or no edits.

How to install

Requirements

To install the PIR Sensor with the Pi a good tutorial is found here.

On the software side, you need to install the following requirements.

$ sudo apt install python3-gpiozero
$ pip3 install paho-mqtt 

Update Settings

Update the settings install pimotion.py with your own configuration.

Specifically the MQTT settings and the GPIO Pin Setting at the top of the file:

PIR_GPIO = 7 # GPIO Pin of PIR Sensor

# Update this to adjust sensitivity. Default is 0.5
PIR_THRESHOLD = 0.5

# Update the follow MQTT Settings for your system.
MQTT_USER = "mqtt"              # MQTT Username
MQTT_PASS = "mqtt_password"     # MQTT Password
MQTT_CLIENT_ID = "pisensor"     # MQTT Client Id
MQTT_HOST_IP = "127.0.0.1"      # MQTT HOST
MQTT_PORT = 1883                # MQTT PORT (DEFAULT 1883)

(OPTIONAL) Add a service

If you would like to have the Motion Sensor to restart on startup, create the a file in the in the following location /etc/systemd/system/pimotion.service

[Unit]
Description=Raspberry Pi Motion Sensor MQTT Service
After=network.target

[Service]
Type=idle
User=pi
ExecStart=/usr/bin/python3 /home/pi/studycam/pimotion.py
Restart=always

[Install]
WantedBy=multi-user.target

Update the file location and other settings as required and then load the service as follows:

$ sudo systemctl daemon-reload
$ sudo systemctl enable pimotion.service
$ sudo systemctl start pimotion.service

How to use new Sensor

To add the sensor to Home Assistant use the MQTT Binary Sensor Component a sample configuration is below:

binary_sensor:
  - platform: mqtt
    name: "Pi Motion Sensor"
    state_topic: "CHANNEL/Motion/Switch"
    device_class: motion
    payload_on: "1"
    payload_off: "0"

Troubleshooting

The motion sensor is activating randomly even after reducing sensitvity.

There seems to be an issue (especially with the Raspbbery Pi 3) with having the Wifi module active and having it setting off the PIR.

Try turning off the wlan0 interface and see if it works.

$ sudo ifconfig wlan0 down

If you get better performance, take a look at permanently disabling your wlan0 card (For RPI 3):

$ echo "dtoverlay=pi3-disable-wifi" | sudo tee -a /boot/config.txt

Note to renable it, you will need to remove the above line from your /boot/config.txt file

pi-motion-mqtt-sensor's People

Contributors

robmarkoski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

razserv2010

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.