Home Automation

Category: Articles
Published on Thursday, 16 April 2020 17:51
Written by AltonaLab
Hits: 185

Experiment: Home Automation.

AltonaLab diagram: KIT_HomeAutomation.nsm

Used hardware:

Home automation is very interesting area, because each of us wants something to be automated in his home. In the previous experiments, we learned how to control and monitoring some simple processes. In this experiment, we will learn how to build a complex system to automate our home. For this purpose we need a computer, which runs not stop and an AltonaLab software running on the same computer. The controlled devices at home will be - heather in bathroom, fan in bathroom, light in yard. Of course we will monitoring the temperature at a home and will have a security PIR sensor. Some of the devices will be controlled automatically from the computer, but if we want, we can control them in manual mode from the buttons located at the AltonaLab diagram or using our phone with android OS. So with this experiment, we will demonstrate a simple to use but very powerful block AndroidRemoteControl, which will allow you to control what you want by phone.


Warning!!! Before starting the AltonaLab diagram, you must to do the next:




To be able to send commands from your Android phone to the running AltonaLab software, you need to follow a few simple steps described below:

1. At AltonaLab software, set which IP Port will be used for a TCP/IP Server. Usually it is 707. If the checkbox AutoStart TCP/IP Server is checked, when AltonaLab software is started, the TCP/IP Server will be started automatically too:

2. Open the used TCP/IP Port 707 in Windows FireWall. For Windows 10, the steps are shown below:

Navigate to Control Panel, System and Security and Windows Firewall.
Select Advanced settings and highlight Inbound Rules in the left pane.
Right click Inbound Rules and select New Rule.
Add the port you need to open and click Next.
Add the protocol (TCP or UDP) and the port number into the next window and click Next.
Select Allow the connection in the next window and hit Next.
Select the network type as you see fit and click Next.
Name the rule something meaningful and click Finish.

You have now opened a firewall port in Windows 10!

At the same Inbound Rules interface, click with right mouse button over the application AltonaLab, then select Properties, then select the radio button Allow the connection. The changes are shown below:


3. Usually, your computer has an local IP address, because it is connected to the internet by an internet router. But for this experiment, you need to find your external IP address. You can use a WEB site as the URL below, to find your external home IP address:


4. You need to know a local IP address of the computer, where an AltonaLab software runs. For this purpose, click over the icon of your internet connection and find your local IP address. It looks like: IPv4 address: The other way is - run the Command prompt application and then execute the command: ipconfig. Then at the text result of the command, find your local IP address:

IPv4 Address. . . . . . . . . . . :

5. Because we will start a TCP/IP Server of an AltonaLab software and we will use a 707 TCP/IP Port, we have to set the Port forwarding at our internet router. You need to know the local IP address of your internet router and to open its WEB interface, where some settings can be made. If you don't know how to make this, please ask your internet provider. The WEB site of my DLink internet router looks like the image below. I will use it to redirect an external IP Port from my external IP address to an internal Port of my computer which a local address I found with the command above. So if the external IP Port 707 is the same as an internal IP Port 707 of my computer with a local IP address, then the Port forwarding settings are:

6. Now is a time to start the TCP/IP Server of the AltonaLab software. For this purpose press the button of AltonaLab shown below. This will allow AltonaLab to receive TCP/IP connections from other devices over the internet:

7. You need a Smart phone with an Android OS;

8. Open an internet browser on your Android phone and open the URL below:


The click on the second image, which is: 2. Android application for remote control:

9. You need to allow an installation from an unauthorized source and to install the application.

10. When the android application is installed, run it and press the button Settings. On the image below is shown the Android's application interface. The settings interface is the right page. At the Server IP Address you have to set an external IP address of your home. Usually we use the port 707 for AltonaLab TCP/IP Server, but it is not problem, if it is other number. ObjectID and Password has to be same asthe properties ObjectID and Password at the block AndroidRemoteControl from the running AltonaLab diagram.

11. AltonaLab can receive TCP/IP commands only from registered android phones, so it is a time to register all the phones of your family. Please be sure, the TCP/IP Server of AltonaLab software is started, then navigate to Settings->Allowed android devices at AltonaLab software. Run the android application shown at the image above, click the button Settings and if the Server IP and Port are set with valid values, click the button Register to host, at this moment the uncial ID of your phone will appeared at the edit Android device ID. At the next edit set a Description and Add the device to the allowed devices. Now your phone is allowed to send TCP/IP commands to a running AltonaLab software.

12. The last step is to read the button configuration, which is set at the block AndroidRemoteControl. For this purpose be sure the TCP/IP Server of AltonaLab is started, then run the AltonaLab diagram too. At this moment press the button Get configuration from a Settings interface of an Android application. Then go back to the main interface of Android application and you will see control buttons of your home devices. When you press some of the buttons from the main interface of Android application, the corresponding TCP/IP command will be send to a AltonaLab TCP/IP Server and some of your devices will be turned ON.



The used hardware is shown below. GPIO 0 and GPIO 1 of a Numato board are used to read the values of a Temperature sensor and a PIR Sensor. The 2 relays controller has two digital inputs, connected to GPIO 4 and GPIO 5 of a Numato board. GPIO 4 is used to control the Yard Light, GPIO 5 controls a bathroom heater. The Yard light is simulated with a 12V lamp, the Bathroom heater is controlled by powerful 12V 8A relay, available in the KIT equipment. The wire between 2 relay controller and One load relay board 8A can be very long. AltonaLab diagram controls GPIO 6 of a Numato board, but in this hardware diagram it is not connected to a real hardware.


Please be very careful with PIR sensor! It is very small and it has not good readable texts on its board about its pins. Its board has two sides, one with electronic elements and other with soldering. The image below is with electronic elements on top side. The left pin is Positive power supply, the middle pin is signal output, then is GND. The pins of a PIR sensor are connected to the Connector board by cables Male to Female!!!



The used AltonaLab diagram is:

AltonaLab diagram has a few areas:

- A top area with controls - there is a text control, which shows the current temperature, Lamp for current state of a PIR sensor, three lamps for Heater in bathroom, Fan in bathroom, Yard light. There are three buttons, if one of them is pressed, the corresponding device will be Turned ON for 10 min. The diagram has two lamp, which show whenever the e-mail is send or not, when there is a security event generated from a PIR sensor.

- Read sensor data and control relays - the area includes Numato block, block AltonaSensorTemp, which converts the read RAW value from the ADC to degree centigrade, SchmittTrigger block, which convert ADC value to digital signal. The high value of this digital signal means there is a security event generated from a PIR Sensor. Because the diagram has to work non stop, Numato block is not in Fast mode and its parameters are CommunicatePerSec=1, FastMode - unchecked;

- Send e-mail - the area is well explained in the experiment Simple home security system. The purpose of the area is when there is a security event, generated from the PIR Sensor, the home owner to receive an e-mail with information of the temperature of the house too. If there is not a secure event, the owner will receive every day an e-mail at 20:00h. This e-mail is very important, if you receive the mail this means, the computer is still running and additional you will know what is your home temperature. The information is interesting is case you are at a holiday or at a business trip;

Control heater - if your bathroom is cold at a winter time, you can turn ON the heater for 10 min by pressing a button Heather in bath located on top of a running AltonaLab diagram or to press the button Heater of your Android application, running on your smart phone. The both events are connected to the inputs of a OR block, then the TimeOut block will be turned ON for a 10 min and GPIO 5 of a Numato block will become to a high level. The main purpose of this area is to demonstrate how simple is to control a device using a TCP/IP command, which is sent from a phone;

- Control Yard Light - the area has a similar logic as a Control heater area, additional is added a block SunInfo. At this block are set parameters Latitude and Longitude with GPS coordinates of your home. As is known, the sun set and sun rise are changing every day and are different on all the world locations. When outside is night or twilight, your Yard light will be turned ON. The time of Turn ON/OFF will be different every day. The Yard light can be turned ON for a 10 min by pressing the button Yard light of an android application;

- Control FAN - if you get a shower every working day around 8:30h and leave from home around 9:00h, it is a good idea the FAN of your bathroom to work at time period 9:05h..9:20h. But only in working days, because at a holiday it is not clear when you will get a shower. This logic can be easy achieved by a block TimeInterval, which parameter OnOffInterval is set to 9:05;9:20. This means at this interval of time every day, the output of the block will be in high level. The mentioned output is with AND logic with output WorkDay of a block DayOfWeek. The output WorkDay is in a high level from 00:00:00h of Monday to 23:59:59 of a Friday. The fan can be turned ON for a 10 min by pressing the button Fan of an android application;

- Remote control by phone - the area contains a block AndroidRemoteControl, which is well explained at the URL below:



The properties of the block AndroidRemoteControl are shown below.

The properties are:

Temp is: <InTemp;1> C
Heather bath: <InHeather>
Fan bath: <InFan>
Lamp yard: <InLampYard>

When the button Read of an android application is pressed, or some other button sending a command to AltonaLab software is pressed, the running diagram replaces the names of the input signals of the block AndroidRemoteControl with theirs values and sends the result to the phone. For example the text is replaced with:

Temp is: 23.5 C
Heather bath: Off
Fan bath: On
Lamp yard: Off

More information about how to format text can be read at the article Text formatting conception: