My door sends me chat messages

Raspberry Pi powered door sensor and Rocket.Chat bot with some neat info

Posted on 2016-04-24

Get new posts by email (~ one email every couple of months & no spam)

The result
Github repo: Link

What does it do?

  • Senses when your door was opened
  • Sends a chat message in a rocket chat channel of your coice (own servers supported)
  • Tells you how long the door was opened
  • Tells you how much time has passed since the door was last closed so you know how long you were out or in

Requirements

  • Raspberry Pi
  • Reed Switch
  • 1x 10k ohm resistor
  • Channel ID of the channel your bot is going to post the message

Build it yourself - It's pretty easy


Step 1: Connect the Reed switch to the Raspberry Pi

Connect the reed switch acording to these schematics:

diagram

The reed switch is activated by a magnet. You can glue the magnet to the door and put the sensor on the frame like this:

reed switch on the door

The reed switch only lets through the current when the magnet is close. If the door opens, the script will detect that and send a chat message

reed switch on the open door

You don't need a bread board or something like that, you can just solder the resistor to the reed switch directly and connect it to the Pi. The resistor is under the black shrink tube:

reed switch on the open door

Step 2: Install php and the "gpio" command

apt-get install wiringpi php5-cli
echo 'w1-gpio' >> /etc/modules
modprobe w1-gpio

Step 3: Get the script

wget https://raw.githubusercontent.com/geek-at/raspberry_doorbot/master/door_chatbot.php

Step 4:

Edit the settings in the door_chatbot.php file and add your channel, server and login credentials

settings in door_chatbot.php

Final step: Run script on startup

crontab -e

insert this at the end of the crontab

@reboot php /path/to/your/door_chatbot.php >> /var/log/doorbot.log

And then start once (or reboot)

nohup php /path/to/your/door_chatbot.php >> /var/log/doorbot.log &

Should be working now

Bot in action

Things to consider

  • You can enable notifications on that bot channel so you get notified when your door is opened
  • Don't let your bot post on public channels or you might just make the front page on PleaseRobMe
  • Make a private channel
  • If you host your own rocket.chat instance, use HTTPS. It's free with let'sencrypt


Tags: raspberry pi | diy | bot | chat | rocket.chat

1ChrisHMgr4DvEVXzAv1vamkviZNLPS7yx
0x1337C2F18e54d72d696005d030B8eF168a4C0d95