The Problem
I live in Canada, in a peaceful area. There are still some bad things that could happen and have a negative impact on my property. Here are a few examples:
Fire
A friend of mine has lost his house just because the dishwasher was broken. As per local regulations, we have smoke detectors on all floors, connected all together, AC powered and also battery protected. When smoke is detected, it beeps. They are designed with just one intent: wake people up and convince them to get out of the house as quick as they can.
Water leakage
There is a 3/4 pipe entering in the house, in the basement and nothing to handle the case that pipe or any accessory could break. It does not take that long to transform my basement into a pool...
Extremely low temperature
During winter time, temperature can go down to -30 C. If no sufficient heating is maintained, it does not take that long to have big issues with many things, one of them being.. the plumbing
The expectations
Here is what I would expect the system could do:
Fire
I'm OK with smoke detectors beeping (it could save my life) but I would like the system to notify my neighbours as well (after a delay, just in case I had forgotten my toasts and created a false alarm) and it makes sense to notify me as well when I'm out of the home. If the system is stable enough (more than many commercial products), I would consider to notify 911 as well.
Water
I have a different expectation here. This is a local problem that should be handle locally and automatically. I'm interested in being notified but I would prefer a "Main valve has been turned off due to water leakage" message than "The pool is filling up, sorry guy"
Temperature (optional)
I'm OK with a notification when temp is going so low it could break something.
This project intends to provide innovation at lost and based on existing components. As end-user, I want to add a constraint to the design: I don't want batteries everywhere on all detectors, it's a pain to swap batteries, even after a long period of time. If it is really long (not the case with existing wireless sensors), the problem is .. that I do not remember where the sensors are located...
The hardware solution
The project is not so complex but I prefer to proceed step by step and to handle each sub-system one at a time.
1) Fire detection sub-system
I don't want to interfere with the existing system (for obvious reasons related to safety). I have 3 detectors, daisy-chained, one per floor. I bought them from Kidde and they also offer a small relay you can use to interface to the detectors. Here is how it works:
Detectors
All detectors are connected to a dedicated 110v AC circuit, with its own breaker. They are also daisy-chained (red wire) in order to make them all beep when one of them detects smoke/fire.
Relay
The relay is also connected to the same AC circuit and to the red wire. Two features are available:
- Do something when an alarm is detected or when the alarms goes off. To use this feature, connect your secondary circuit on Common-NC/NO
- Trigger an alarm intentionally. It looks useless (why should I turn the noisy "beep' on ??) but it helps to test your system to be sure it will work when a real fire alarm will be detected.
Outdoor bell
Once an alarm is detected, a timer is started (see later in C# code), after one minute, if the alarm is not cancelled (by the guy who forgot the toasts..), then a relay turns the big outdoor bell On. There are two ways to turn it off: either to handle the root case and to make the alarm disappear, or to manually turn the bell Off
2) Water leakage detection sub-system
Detectors
I used small detectors I bought from Aartech in Toronto. Here is how it looks like once installed:
Motorized valve
This one is more tricky. When you search for automated valves on Google, you discover there are (at least) two categories:
- solenoid based: used in dish-washer for example, when it is Off most of the time and On during small period of time during washing cycle.
- motorized. I found hundreds of models, mainly used in industry, not only for water but also for gas or oil. The big advantage is that such a valve can maintain two "idle' states (open and closed) even when electrical power goes off. I ordered the following one from AliExpress:
Here is how I plan to install the valve, I plan to keep the existing valve (to be sure I will always be able to "fix" any problem without a call to the city Utilities Department). The reason to plan a bypass valve (on the bottom side of the schema) is linked to the fact that the motorized valve has two idle states and I don't want the valve to be Off ...and to remain Off just when there is an electrical power outage in the city ("bad timing scenario")
There is a DC motor within the valve and it turns clockwise or counter-clockwise depending on polarity. There is a feed-back loop that indicates whether the valve is effectively On or Off. To turn it On, just apply a positive voltage to the upper-left connection. If it is already On, it will do nothing since the other side of the opto-isolator is connected to the feed-back "Valve is On" loop.
3) Weather sub-system
My plan is to integrate my existing Arduino-based weather station with the current system. It will be done at software level, since the weather station is already installed outdoor and broadcast weather related data on a regular basis (UDP messages) on the LAN
More on this to be posted later... stay tuned !
4) Notification sub-system
The system is connected to my house LAN using Raspberry RJ-45 port. There is no additional hardware there. The challenge is more on the software side. The requirement is to deliver notifications to multiple destinations (starting from an old-style flip-flop cellphone and up to a tablet). I used Azure Notification hub to deliver notifications to tablet and smartphones and Twilio to handle simple text messages.
The Software solution
1) Features
Here are the features to implement:
-
At startup... connect to the motorized valve, get its status and open it if needed
-
When water is detected... turn valve Off and then notify users through Azure Hub and Twilio SMS
-
When smoke is detected.. notify users through Azure Hub and Twilio SMS. After one minute, turn the outdoor bell On as well. Notify upon cancellation as well .. and don,t forget to switch the bell Off !
2) Architecture
There are 3 main blocks
- The first application to develop is a UWP application (one EXE and a DLL) that will be launched automatically at Raspberry start-up.
No UI is required and Windows has to be configured in headless mode. The UI stack is disabled and apps are no longer interactive and there reduce the amount of system resources used. In headless mode no UI app will be launched. “Background Apps” (StartupTasks) are apps that do not have UI and launch at startup. See https://ms-iot.github.io/content/en-US/win10/HeadlessMode.htm
- Another application will be hosted on PC/smart devices and will get the "toast" notifications. Azure Notification hub relies on WNS. If you want to understand in details how it works, just read this: https://msdn.microsoft.com/en-us/library/windows/apps/mt187203.aspx
- In the middle, we will leverage Azure Notification Hub and Twilio to broadcast the notifications. See https://channel9.msdn.com/Shows/Cloud+Cover/Episode-116-Cross-Platform-Notifications-using-Windows-Azure-Notifications-Hub for more info on how you can target multiple devices when sending "Toast" notifications
See https://www.twilio.com/blog/2011/09/using-the-twilio-rest-api-in-windows-8-metro-style-applications.html to learn more on Twilio and how to use REST API to send SMS
3) Design
Application running on Raspberry
At start-up (Run), we setup the link to the Kide relay (SetupFireDetection) and to the motorized valve and water sensors (SetupWaterLeakDetection) and then .. we wait..
Then.. it depends on real physical events, like water detected in the basement or smoke detected in my attic
Water detection sensors are connected in parallel and the only thing to do is to configure a GPIO port in order to trigger an interrupt when the line is powered up. See http://blogs.msdn.com/b/cdndevs/archive/2015/05/08/windows-10-how-to-use-iot-extension-for-raspberry-pi-2-part-1.aspx for more info on how to drive GPIO pins and http://ms-iot.github.io/content/en-US/win10/samples/PinMappingsRPi2.htm for the mapping.
Smoke detection is implemented with an interrupt as well
Controls outdoor bell: we have to power up/down a relay controlling the outdoor bell power supply
Controls motorized valve: this one is more complex. We have to drive two pins to turn the motor On.. in the right direction to open or close the valve. We get feedback through two GPIO ports to confirm when the cycle is completed. The code to drive the motorized valve is package in a separate class file
Notifications are sent either to Azure ("toast notifications") or to Twilio (SMS)
For this project, Raspberry is configured in headless mode (no UI). A Windows IoT Core device that is in headless mode can be discovered using the WindowsIoTCoreWatcher application that is installed with the Windows 10 IoT Core tools. When run, the application automatically finds all Windows IoT Core devices on the local network and displays device information such as the name, MAC, IP address, and more.
Application running on PC/smart device and Azure Notification Hub configuration
Follow this tutorial to create your application and to register it. Here is where you will find your keys (one key to send messages and another to read them)
Twilio Cloud-based infrastructure
The last step is to setup a Twilio account and then to invoke their REST API to send SMS from the Raspberry. Here is the tutorial.
4) Tests
The system is not really complex but there are multiple elements to connect. Instead of connecting everything and then to search why something does not work like expected, I preferred to go step by step and to test each subsystem individually.
Local tests
Here is how my breadboard looks like when testing the software part of the project
Cloud-to-App tests
There is a tool in Azure you can use to confirm that Toast notifications will hit the PC/smart devices. Here is how it looks like (do not forget to click on the Send button that is not so visible on the bottom of the page..)
Comments