The family house control system based on Raspberry Pi

The article deals with the design and implementation of a smart household based on simple wireless modules, which are monitoring (collecting data) and controlling smart household supporting devices. The central unit processes measured parameters, and in relation to resulting values, a pre-set action is performed. Those actions variety can be configured by user via the user interface so that a set of smart rules for reaction on by household devices generated stimuli or problems can be created. That all together composes a control system based on Raspberry Pi, which manages indoor and outdoor temperature measurement, the lighting control, RF transmitter, jalousie, motion sensor control etc. There is a GUI for a PC and for a mobile phone as a part of that system.


Introduction
The term "Smart house" or "Smart household" is popular already since 1980s.The term "smart building" emerged in USA at the turn of the 80s and 90s decade.That term expressed an above-standard comfort building [1].Since then, the technology development influences the meaning and the content of that interrelatinon "smart" and "bulding".It is common that housholds are equipped with various electronic gadgets nowadays.Among many others, we can name desktop and mobile computers, smart TV sets being able to record TV broadcasts automatically, wireless garage gate control, and provide household both indoor and outdoor security.Those all are technologies taken for granted by majority of us contemporary that are forwarding the significance of smart building on.
Currently, we perceive that term as fully automated household where individual devices control is doable via an uncomplicated user interface.
Although the particular technologies are not very new, it is not easy to network them in a coherent system controllable from one location.The individual household technologies have different communication channels and interfaces according to the manufacturer.Some of the do not have any communication channel and interface.Therefore there is very complicated to install a smart system in an established household.The particular devices are not prepared and smart system compatible.For the purpose of such household automation, and to include in the smart system its existing devices, we have to create an active control of particular devices.We need also to realize modules able to communicate via various interfaces, or we need to procure brand new more advanced devices.

Effective household controlling
If we manage to interconnect as much as possible existing and newly installed devices, we obtain affortless access and controllability over the whole household.Thanks to unified access to all devices, we are able to create situation oriented modes and indoor environment according to user´s mood.One button touch sets the whole household particular complex setting.For instance, the morning awakening arrangement could start with jalousie slats opening, sun shine and music.All particular jalousie get open in between.On entering bathroom, lights are lit on and the favourite radio station is switched on.
As another example, the household locking could illustrate the system possibilities.When leaving, all unnecessary appliances are automatically switched off, the jalousies get partially closed, air condition stops operation, all lights go out, and all security elements get active.
We occupy ourselves with devices and relevant control algorithms for smart building control development at our department.
The building lighting control via DALI bus is one of our implemented oproject [2].To control the whole building with a programmable logic controller (PLC) is another variant of solution [3].Although such solution is comprehensive, its high costs represent noticeable disadvantage.Those costs comprise also mostly a complete wiring replacement and completion what means sensors and actors interlinking.
As a cheaper alternative, there is a possibility to make use of a microcontroller or of a small cheap computer together with a higher number of wireless modules [4].

Systems on the market
There are many systems for smart household on the market nowadays.We aim at wireless communication possibility what means that PLC control does not fit in our project goals.PLC application is much more convenient for new buildings where the special wiring is indispensable.

Loxone
Loxone company offers both their flag ship PLC automation based on PLC Miniserver [5] and Miniserver GO [5] without the PLC link what is more advantageous for wireless communication with peripherals.

Fibaro
Fibaro company´s products are based on miniature modules designed for easy installation without special demands on wiring.
Z-Wave protocol oriented control unit is one of Fibaro basic components for smart household.That control unit incorporates Fibaro System Home Center 2 for remote control over all connected devices.The control is executed via web interface as well as mode setting and composing rules for automation [6].

Control4
The core of Control4 system is a control unit offered in a few variants.Those variants differ in power, in number of ports and integrated devices like audio, and in range of controllable smart devices.Up to 50 devices can be connected to each control unit.
Control4 system does not provide any own wireless sensors and modules.That shortage is substituted for Nyce company´s products represented with wireless modules communicating via ZigBee interface and protocol [7].

Main ideas of our design
The designed system proceeds from three basic ideas [4].

Wireless modules application
Wireless approach can be regarded as noninvasive form of household automation.
A lot of smart systems is based on PLC application what requires special wiring where a majority of devices and elements is interconnected with cable and relays or with other integrating technologies.
Those systems are advantageous in case of new building and flat construction or when we are refurbishing them including the new wiring installation.
However, if we plan to implement the smart building technology in an existing household, that system represents a costly alternative.

Open source products utilization
In pursuance of our project goals, there are employed products and applications developed as community projects so that they are freely accessible for use.
The big advantage of those projets is a numerous user base which the open discussion of problems or presentation of successful solution accompanied with detailed instructions is a standard way of improvement in.

Price
By employing open source projects and by modular solution of automation by our own, we are able not only modify the system exactly according to our needs, but we can also save money compared to commercial products employing.

Remote access and hosehold system securing
There is possible to control a smart household not merely from the household itself or its vicinity, but also from any placein the world where the link to our system is possible to establish.The remote access to our system is practicable via mobile phone technologies like GSM or via internet.

Project main goals
The following demands are placed on the solution of our smart household control project.

System remote management
• There is possible to address the system from any computer or mobile device in household concerned.• To address the system outside that household is permitted exclusively with knowledge of security access data.• It is possible to configure and monitor all connected devices.

Temperature measurement
• The temperature measurement inside any room and also outside the household.

Surroundings humidity measurement
• The humidity measurement inside any room and also outside the household • The indoor plant soil humidity measurement.

Movement detection
• People´s and animals´ movement is detected in selected rooms.

Illumination control
• The light go on/go out in any room is possible without user presence in that very room.• The light intensity control in any room.

6 Jalousie control
• The indoor jalousie complete control comprising the ful or partial opening/closing.

7 Security camera system
• Any household place monitoring with streaming and recording opossibility.

8 Main entrance control unit
• The whole system controllability from a fixed place at main entrance.• The "leaving" button to switch the whole system in the mode of "deserted" household.According to aforesaid requirements, the smart building system has been designed.The smart household, MQTT Broker, and database are carried on a server.Individual modules with connected sensors for temperature, air humidity, movement detection, indoor plant soil humidity measurement and the module for windows jalousie control are linked to the system.The light control module is also linked to the system.

Raspberry Pi
Raspberry Pi is a fully-fledged miniature single-board microcomputer designed and developed by the British Raspberry Pi Foundation aimed at informatics education in highschools [8].There is not possible to change the configuration of Raspberry Pi because all modules are soldered on one PCB.The GNU/LINUX operational system is iemployed, and it is possible to choose among a few distributions, like Debian, Ubuntu and others.
There is supplied a new model Raspberry Pi 2 in February 2015.That model is fitted out with a new SoC Broadcom BCM2836, and it includes a quadruple processor cores with clock rate of 900 MHz and a SIMD 1 GB memory to increase performance.The inbuilt graphic processor VideoCore IV supports OpenGL ES 2.0, 1080p30, .This model is used by the system as a central control unit for our smart household system concept.

Arduino
Arduino is an open platform with a graphic user interface development environment related to the Wiring environment (similar project like Arduino, i.e. a board with microcontroller and IDE) [9,10].
The development hardware support is represented with Atmel 8 bit microcontroller boards in many varieties, as for instance ATMega8, ATMega168, ATMega328, ATMega1280 and ATMega2560.
Unlike Raspberry Pi, Arduino is not devised as a desktop so that it does not content any operational system.
As for that, the servicing programs need to be prepared on a different device, and to load it to Arduino afterwards.
The advantage of such solution is a lower energy consumption, and in contrast to Raspberry Pi, it is possible to power those modules from batteries.

1. 4 NodeMCU
NodeMCU is an open IoT platform that was developed from ESP8266 project by processing unit together with micro USB port (for power supply and communication) and with 10 I/O pins (6 digital pins, 3 analog pins and one ADC pin) insertion in a common module.The first generation employs the ESP-12 processing unit with 20 KB SRAM and 4 MB flash memory.The incorporated wifi module supports 802.11b/g/n, devkit nodemcu v0.9 standard [11].

GPIO
Like at Raspberry Pi or at Arduino, the NodeMCU includes I/O pins for peripherals communication.The pins sorting follows [13]: -6 digital -3 analog -1 ADC -Four 3.3 Volts power supply pins -One 5 Volts power supply pin -4 common ground pins

2. Wireless modules
The majority of wireless modules uses the NodeMCU unit.

The NodeMCU supporting scripts implementation
There are a repeating set of steps in creating and programming individual modules.These steps are as follows: 1. Module activation from sleep mode.2. Module connection to WiFi.
3. The particular module task execution.4. Communication with the central node. 5. Putting a module in the sleep mode for a set time period.
It is necessary to implement servicing LUA script for a particular function execution.

Module initialization
The module initialization begins with loaded firmware starting (we use basic firmware with LUA language), and with seeking out the initialization script "init.lua".Provided that script is accessible, it starts automatically.

Module link to the local WiFi network
Module tries repeatedly to connect to WiFi network specified in "wifi.config"filewhich SSID and password are also in.If connection to WiFi fails, or if DHCP server does not assigned IP address, module repets that attempt in 10 seconds interval.In case that connection fails even after that set of attempts, module is put to sleep mode for 10 minutes.After module activation, the "init.lua"script is launched again.

Communication with the central node
A simple HTTPrest api serves for communication between a notification module and central node.We specify module ID and data to be transferred, and data are sent to central server with the POST utility.Central server processes data, and it sends response HTTP 200 to that module, and server stores data in database or it launches other predefined action according to the implemented procedure.Providing the central application is not able to accept that message, it sends the error code HTTP 400 and saves the information about unsuccessful transaction in logs [4].

Putting module to sleep for a set time period
In order to serve their purpose, there is necessary to consider the power supply concept of individual modules, and how to minimize energy consumption.There are two groups of modules.First group is characterized by uninterrupted operation.This group includes sensors and modules waiting all the time for launching event, like movemen sensor, jalousie control, camera system etc.The second group includes so called notification sensors that are measuring physical quantities in regular intervals.In between, those sensors can enter the slee mode which they are consuming minimum energy in until they are activated to perform their task.

Temperature measurement module
There exist both simple sensors measuring only temperature and advanced sensors measuring also air humidity.The air humidity could be interesting for case of keeping constant household humidity by automatic humidifiers.Nevertheless, same rooms are not interesting for humidity control so that only temperature measurement is sufficient.In that case, we can use a cheaper sensor.DS18B20 sensor has been selected for our project.When also humidity level is of our interest, we can choose DHT11 sensor or a more expensive but more accurate sensor DHT22.
For a created module fulfils its function of temperature measurement and data passing to server, it is necessary to implement ULA language script.The function of that script is as follows: 1. Module activation from sleep mode ("init.lua").2. Module connection to WiFi ("wifi.lua").3. Temperature value reading from sensor ("temp ds18b20.lua").4. Temperature forwarding to server ("data send.lua").5. Putting module in sleep mode for a specified time period ("sleep.lua").
The sleep mode after task execution saves the connected battery energy.

Humidity measurement module
There exist many sensors for the soil humidity measurement.The budget-wise sensor Produino LM393 has been selected for our project.
That sensor is one of the cheapest on the market (1.7 EUR).That sensor enables humidity evaluation both in digital and in analog form (relative humidity percentage in the range of 0 -100.Nevertheless, the digital form is very inaccurate, and it indicates only exceeding of preset humidity limit. The house plants soil humidity is unlike the temperature changing not so frequently so that there is not necessary to awake module every 10 minutes.It is sufficient to set sleep mode for an interval of about 60 minutes (the maximum value is about 71 minutes).The module with batteries operational time can be remarkably extended.

Movement detection module
One of the most frequently used sensors are the movement sensors installed in buildings and in households.Those sensors are most often used for entrance automatic lights, toilet lights and in other windowsless rooms.
The movement detection module has been realised with commercial models NodeMCU and HC-SR501.HC-SR501 module can identify movement in angle of 120° and distance of 7 meters (price 1 EUR) [14,15].
The sensor data is read via digital pin D4 which is set to mode "gpio.INT", and with the help of "gpio.trig()"function, we put pin D4 in automatic detection mode.In that mode, pin D4 waits for event (callback), and in case of logic 1 reception, module calls the preset function.There takes place a notification of central node about movement detection with "data send.lua"script and "Motion"data type in our case.

Household lighting control module
The household lighting control requires not only module creation with wireless communication addressing ability to a mobile device, but also a wireless control of lighting itself.All foregoing modules are exclusively collecting physical quantities data, but they do not communicate with their environment.Providing that we need to control remotedly, we need to deal with a problem what to communicate at lights with.Common house light is connected to the mains voltage of 230 volts, and it is controlled with a touch switch is located at the wall or it may be located at the power supply cable.
The further requirement concerns light intensity control, so called dimming possibility [16].
There is emerging also a WiFi application for house lights remote control besides the radio controlled sockets in couple of recent years.Unlike a simple controlling element insertion between bulb and socket, there are modified light bulbs containing embodied radio receiver.Nevertheless, that system comprises another component called WiFi Hub that receives simple UDP packets initiating the radio signal for individual bulbs control.Such arrangement is easy to implement and to control via any device communicating via a WiFi link.The higher costs of such solution are compensated for much easier incorporation in our smart household system [17].

Window jalousie adjustment module
The last module for smart household system design is an automatic jalousie controller.There exist many jalousie system concepts.In our project, we are concentrated on the current broadly used system of indoor horizontal jalousies supplied for common plastic window design.That system is handled by means of bead pull-chain driving the shaft of window blind.
The simpliest way how to handle window blinds is a direct shaft rotation handling.That way of handling has a drawback in module mounting on pull-chain end what means a higher pull force for pulling the blind up.Thet is why we need 12 volts motor and adaptor power supply.
One of few stepping motors with operational voltage of 12 volts is 28BYJ-48 motor.Stepping motors are well applicable for jalousie handling because of stepwise controlled rotation in accurate number of steps.There is 64 steps needed for one turn of the motor shaft.

Camera supervising system
One of the main security elemnts for household security is without doubt camera supervising system.It guards the household both against intrusion from outside and also monitors various parts of household, like child´s rooms and animals without personal presence necessity.The majority of camera systems is also detecting movement, and in case of such event, camera system can notify user, send the event documenting picture, or it can start event recording.
There exists a huge amoun of various camery systems for household security provision.The most important attributes of a quality camera is its functionality, placement variety, and also its ability to communicate with other systems.The outdoor camera required attributes set will naturaly differ from the indoor camera one.Fig. 3. Raspberry Pi Camera module [18].We have employed the Raspberry Pi camera for our project.Its integration in system is easy, and its performance in household projects is excellent.

Camera installation in Raspberry Pi
The Raspberry Pi camera module is capable of taking full HD 1080p photo and video and can be controlled programmatically.
If we want to use camera also during the night, it is recommended to accomplish it with two infrared light generating LEDs.Those LEDs are to be fixed with screws on the camery PCB, one LED on each side.
That camera enables also streaming services.The access to video stream is possible via a PC or via mobile application "IP Cam Viewer Lite".That application is available for both mobile platforms Android and iOS as well.

OpenHAB server implementation
OpenHAB (Open Home Automation Bus) is a server Java application designated for home automation.It offers both a server backend running ounder all common operational system versions (Windows, Linux, OS X) and also frontend in the form of web environment plus mobile applications for Android and iOS.It is an open code project what means that application is free of charge under the EPL licence.That is why OpenHab is becoming an excellent candidate for household automation and smart household creation starting projects.
The system is modular, and it is possible to extend it with addons serving as interface for peripherals.Among those extensions, we can find also binding to Milight system for light bulb control, binding to MQTT broker in both modes publish/subscribe, email client, bluetoth and others.
The other part represents a data repository, which stores states of all connected elements.It takes care for synchronization among all connected packages.All obtained data can be stored in a database, in a harddisk or in cloud systems to ensure durability even after system restart.
OpenHab Log serves for data storage in log files or in databases.The RRD4J (Round Robin Database for Java) is a default database serving mostly for diagram generation in user environment [21].
The other possibility is a link to SQL database or to another one.Providing we store data in files, we find them in openhab home/logs directory [22].

Graphic User Interface -GUI
OpenHab makes possible to answer individual queries directed to the databases, and to present response in predefined graphic windows.Those windows are to be displayed on a computer s, mobile phone or tablet screen with any operational system.
The windowas creation description is beyond the scope of this article.Nevertheless, the following figures illustrate resulting windows example.

Conclusion
As a result of our project, the complex household control system based on Raspberry Pi and other wireless modules has been created.The whole system is functional, and to its remarkable advantages belong prise, noninvasive implementation with further extension possibility.
The designed system increase the inhabitation comfort, it optimizes lighting energy consumption, thermal energy and other energies consumption.
It also improves the household security level either in case of a flat or a family house.The modular solution does not hamper modification and extension for sake of household control optimization.
This work was supported by the Ministry of Education, Youth and Sports of the Czech Republic within the National Sustainability Programme project No. LO1303 (MSMT-7778/2014) and also by the European Regional Development Fund under the project CEBIA-Tech No. CZ.1.05/2.1.00/03.0089.