Introduction
My home automation project first idea was to add several features which the actual alarm system are missing, mainly smoke and water leak detection. Starting from here, I have built a more complex system able to be extended and improved continuously, as needed. The project is based on MySensors development branch for Nodes and Gateway and Home Assistant for Controller. I started from the demo one-sensor nodes and built multi-sensor nodes. In order to have a simple and scalable system, I have develop a node with all needed sensors (possible to add more sensors anytime), use mostly the same software and hardware for each node, just change the NodeID. Later, during the fine tunning process, I have removed some of unused code for nodes, if case, to minimize the number of radio messages in the network, leave more space for code and decrease the node process power.
Home Automation features
My Home Automation offers in the actual stage the following features:
The system can act also as an alarm system with the following features:
Network topology
My Home automation Project include one main Node for each room (five in total), a Gateway and a Controller. One more node installed in the Living Room is used to control the light by hand, without contact. The Nodes and the Gateway contains all needed sensors for each place. The Nodes communicate directly with the Gateway via radio network on 2.4GHz. The central location of the Gateway minimize the need of node repeater facility. The Gateway exchange information with the Controller using Ethernet connection and MQTT protocol. The Controller is located on a Linux Server with LAN access. External access is possible by VPN connection.
Project build
I have built the Nodes, the sensors network, starting from MySensors library - development branch. Each node consist of:
Physical building and sensors location and arrangements was a challenge, because the following things should be take in consideration:
I choose a solution with a box placed upper in the room and another placed on the floor for most of the nodes. The upper box contains all electronics, sensors and relays, it is connected with the lower box with 2x3 electrical wires, so 6 available individual used for: 220V power bring for power switching module and relays, 4x1 wire for each relay to control a device. The box on the floor is connected to the upper box with those 2x3 wires on one side, and on other side offer 1 connexion for 220 and 4 connexions for home appliances. In some cases I used only one upper box, for example in the kitchen were only one light needs to be controlled on the floor and on the corridor only the water heater needs wires down. The temperature sensor is conected with a ~1.5m wire to lower it from the upper position of the main node box.
The nodes was built for Living room, Office Room, Bedroom, Kitchen and Corridor. Each of them use almost the same software based on MySensors library - development branch, but different NODE-ID. During fine-tuning adjustment I have removed some code not used, for example sending IR code is used only in Living room, so removed from other nodes. The nodes send update information from sensors to the controller each minute (adjustable in the sketch) for most sensors or immediately for PIR sensor. The relays states are also updated immediately to the Controller if local IR remote is used.
One additional node for light management by moving hand nearby is built of:
The Gateway is built of:
I choose the radio module NRF24 because it is easier to be used in combination with 5V Arduino module: the power supply for this module is 3.3V, available right from Arduino board, the inputs are 5V tolerant, so no need for any special level translation. As recommendation, I have added decoupling capacitor directly on radio module power: 100uF and 100-470nF in parallel, to filter low and high frequencies and to keep instant energy reserve for peaks. The coverage area of this module is not very large, but almost enough for an apartment. I want to extend a little bit the default range of NRF24, to have a more secure transmission. For this, I modified the modules from nodes by cutting the PCB antenna and add an external λ/4 wire as antenna. For the Gateway radio module I have used one antenna from a 2.4GHz router.
For the water leak sensors I add few mm legs to avoid false alarm each time while small amount of water accidentally reach the floor (shower, washing).
For the relay modules I have added capacitors on their power PINs to improve transient response while goes on and to filter eventually spikes. The capacitor value here is 100uF/16V.
As box for nodes and Gateway I used some ABS electrical junction boxes, because the parts fits well inside (several box sizes available) and I can made holes as needed for the sensors mounting.
I have installed sensors inside the refrigerator and freezer using a thin transparent wire from an RJ11 phone cable. Those sensors and the one located outside on the top of the refrigerator are One-Wire DS18B20 with all 3 pins connected.
Most of the parts are fixed inside the box with hot plastic glue. This solution is cheap and assure enough strengthens for fix indoor nodes while still possible to get the parts out, if needed.
The power supply is a 5V/1A switching power module from a phone. For the nodes with relays inside, the power module is also inside the box, because 220V is already there. The only case I use the external power supply is the Hand-Sensors, which do not use any relay. I added to those power modules additional filtering capacitors of 470uF-1000uF + 220-470nF.
The Gateway receive the information from all Nodes via radio network and send it to the Controller via wired Ethernet network using MQTT protocol. The MQTT message structure is well detailed on the MySensors site in Serial API area. My Gateway manage also few sensors and relays directly, because its physical placement inside the house on the corridor. I have assigned static IP address for the Gateway. Node programming was done using Arduino IDE 1.6.5 installed on a Linux PC. The Arduino Nano and UNO clones works very well with this setup.
My Controller is HomeAssistant. It was installed first on a PC running Linux Mint acting as server, then moved to a Raspberry Pi v.3 running Raspbian Jessie. Mosquitto is also present here for MQTT v3.1.1 broker and Python 3.4 as the main HomeAssistant requirement. The Controller is responsible for:
Daily Home Automation functioning
When leave home it is possible to activate the alarm using the IR remote control or using the web interface. The exit timer will start, it is notified with a specified sound. When timer expires, the system is full activated. In case of intruder detection, the lights will start flashing and the alarm sound will goes on in all rooms. The alarm is also notified via email. When come back home, the system may detect the user by his phone presence and disable the alarm. If it is dark enough, the outside door light and the corridor light will be turned on. The water heater will be turned on too, regardless the daylight or day time. If the system does not automatically detect the user, the alarm will start the entrance timer, notified also by a specific sound. During this warning interval it is possible to cancel the alarm using the IR remote or web interface from mobile phone.
When dark enough, the system is ready to help with the lights in each room. When entering into one room after sun trigger (customizable), a short timer will start, allow user to shut off the drapes, then room light goes on and they will work normal. If the person moves in the room, a timer restarts at each movement detection. If no movement is detected for 10-15 min (as programmed), the lights will go off there. The automatically lights for the rooms are linked to the corridor light: after this light is switched off, the lights in the rooms will not automatically works afterwards. The corridor light is programmed to be turned off at a specific time, for me it is 22:30, but when movement is detected on the corridor, this time is extended by 10 mins. For the bedroom, a special automation is implemented: One light out of two is automatically turned on movement detection - Light2. Usually I manually turn on Light1 using IR remote or web interface on mobile. When command turn off this Light1 using IR remote or mobile, the Light1 really turn off, but Light2 turn on for 20s, allow me to go to bed.
It is possible to activate the alarm for any room, not only for whole house: this can be done using the IR remote inside the desired room or using the web interface. If the alarm is triggered in this case, the alarm sound and flashing lights will be active in that specific room.
It is possible to switch from automatically mode lights for each room to the manually mode using the web interface. In the case of manual mode, the lights will not turn on on movement detection, only using manual IR remote or the web interface. The sensors are permanent monitored. In case of water leak, temperature or smoke/gas level over a predefined value, the system start the warning alarm in the room where problem encounter and notify the situation via email.