Home Automation
License:
Attribution-ShareAlike (CC-BY-SA)
Created:
9 years ago
Updated:
8 years ago
Views:
21467
13 Collect
0 Comments
Share
318 Download (12.47 MB)
Donate to support Open Hardware

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:

  • communication between the Nodes and the Gateway using 2.4 GHz radio network;
  • communication between the Gateway and the Controller using MQTT protocol;
  • monitor temperature in each room;
  • monitor humidity in some rooms (able to monitor for each room, if necessary);
  • check for water leak in each room;
  • monitor smoke/gas level in each room;
  • monitor temperature for refrigerator and freezer;
  • control electric devices in each room, as needed (light, water heater, radio, TV etc);
  • control TV using IR (emulate IR remote codes);
  • control light in each room:
    • automatically, based on motion detection, take in consideration the natural light (check sun elevation): turn on light for 10-15 min when motion detect, extend the interval for each motion detection; first entrance in the room will trigger the lights with a delay to allow people shut the drapes first;
    • manually, using IR remote control: set on/off each light or electric device or all of them from one room;
    • choose auto or manual mode for each room;
  • control lights by hand (distance based) from dedicated sensor module, possible to built one for each room;
  • Welcome Home actions, based on mobile presence nearby:
    • turn on the water heater;
    • turn on the outdoor light and the light on the corridor if dark enough (sun elevation check);
  • corridor light will go on automatically based on the natural light (sun elevation) and goes off at established night time;
  • web interface for all settings, available from any device like PC, tablet, mobile.

The system can act also as an alarm system with the following features:

  • activate/deactivate the alarm for the whole house;
  • activate/deactivate the alarm for each room (useful for some windows left opened during hot nights in the summer);
  • when the alarm is activated, the WebCam from that room is also activated (power up);
  • WebCam can be activated independently, using web interface;
  • alarm activation/deactivation can be done using IR remote or the web interface for each room or for all house;
  • alarm activation offer a delay for exit;
  • alarm trigger offer a delay for deactivate only for regular access;
  • buzzer installed on each module;
  • in case of local alarm, the alarm will sound only in the room where troubles encountered (water leak, smoke, movement in the activated alarm room); the output alarm sound is on low level in this case;
  • in case of general alarm triggered, all modules will activate the buzzers and lights will flash in each room; when alarm shout off, the lights remains off, except the corridor light which remains on; the output alarm sound is on high level in this case;
  • the triggered alarm will be recorded on the web interface, only manual acknowledge will reset it;
  • any alarm will be notified by email.

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:

  • Arduino Nano; (decoupling 100uF);
  • NRF24L+ module; (decoupling 470nF + 100uF);
  • Sensors:
    • 5V Relays: 4 channel high level trigger Relays 10A 250V(for some nodes 2 channels 250V 10A or 1 channel relay 250V 30A); (decoupling 100uF);
    • Water Leak sensor low level trigger;
    • PIR Motion sensor, high level trigger;
    • Smoke/Gas sensor MQ-2;
    • Temperature sensor DS18B20;
    • Temperature/Humidity sensor DHT11, DHT22;
    • Buzzer, 5V;
    • IR receiver module;
    • IR transmission module;
  • Power supply 5V min. 1A;
  • Boxes.

Physical building and sensors location and arrangements was a challenge, because the following things should be take in consideration:

  • PIR and Smoke/Gas sensors must be installed at higher position;
  • IR receive and sending module should stay in the line of sight (usually on a high position);
  • Temperature and Humidity sensors should stay in the middle, because at higher position is the biggest temperature inside a room, while on the floor is the lowest;
  • Radio coverage is better when the Radio module is on a higher position;
  • Relays will control home appliances via AC power sockets staying on the floor;
  • all parts needs power: electronics need 5V, Relays must control 220V.

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:

  • Arduino Nano; (decoupling 100uF);
  • NRF24L+ module; (decoupling 0.47uF + 100uF);
  • Ultrasonic sensor: HC-SR04
  • Power supply 5V min. 1A;
  • Box. The Hand-Sensor send the measured distance to the Controller each second if it detects any modification here.

The Gateway is built of:

  • Arduino UNO;
  • Ethernet Shield W5100;
  • NRF24+ radio module; (decoupling 0.47uF + 100uF);
  • Sensors:
    • 5V Relay: 2 channel high level trigger Relays 10A 250V;
    • PIR Motion sensor, high level trigger;
    • Smoke/Gas sensor MQ-2;
  • Power supply 5V min. 1A;
  • Box.

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:

  • send and receive messages from and to the Nodes via Gateway and MQTT mosquitto broker;
  • processes automation to fulfill the features/requirements;
  • additional data retrieval (time, sun data like sunset, sunrise, elevation, devices location etc);
  • web interface available for mobile, tablet and PC.

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.