Enhancing Home Security with a Custom-Built Motion Detection Alert System using SwitchBot and Cloudflare Workers
As smart home technologies evolve, the need for more sophisticated monitoring systems becomes apparent. While standard motion sensors, like those from SwitchBot, are great at detecting movement and triggering immediate actions, they often lack the capability to alert users about the absence of motion for extended periods. This is crucial in scenarios where non-activity can be as significant as activity, such as monitoring the well-being of elderly relatives or ensuring that a seldom-used space remains undisturbed.
To address this, I’ve developed an innovative system using SwitchBot’s motion detection capabilities, combined with the power of Cloudflare Workers, to create an alert mechanism for both motion detection and the lack of it over extended periods, specifically beyond the 30-minute mark, which is the limit in SwitchBot’s default settings.
How the System Works
-
Extended Absence Detection: The SwitchBot sensors are excellent at motion detection, but they can’t natively send alerts for periods of inactivity longer than 30 minutes. My system overcomes this by using Cloudflare Workers alongside the SwitchBot API to detect absence of motion over intervals longer than 30 minutes.
-
Integration with Cloudflare Workers: Upon detecting motion, the SwitchBot sensor triggers a webhook request to Cloudflare Workers. These Workers then log the time of the motion event in Cloudflare’s Key-Value (KV) storage system.
-
Scheduled Checks and Notifications: A scheduled Cloudflare Worker periodically checks the last recorded motion timestamp in the KV store. If it detects that no motion has been recorded for over 6 hours, it triggers a notification.
-
Utilizing Pushover for Alerts: For sending notifications, I chose Pushover – a convenient app for sending push notifications to smartphones. It’s ideal for personal systems where you want to integrate push notifications easily.
Development and Resources
The implementation was guided by the official API documentation of SwitchBot (SwitchBot API) and Cloudflare Workers (Cloudflare Workers Documentation). The ease of use of Cloudflare Workers, particularly for setting up web APIs and using the KV store for data persistence, made it an excellent choice for this project. The deployment process was streamlined thanks to well-organized Wrangler commands.
Conclusion
This project showcases how combining existing smart home devices with powerful cloud services like Cloudflare Workers can result in highly functional and customized home security solutions. The ability to monitor both presence and absence of motion opens up new avenues for home monitoring, ensuring peace of mind when it comes to the safety and security of our homes and loved ones.
The implementation details, code are available on my GitHub repository. I welcome fellow enthusiasts to explore, fork, and adapt this system to their requirements.