29 - 11 - 2020

Home Automation

Experiment: Home Automation.

AltonaLab diagram: KIT_HomeAutomation.nsm

Used hardware:

  • Numato 8 channel USB GPIO Module;
  • Connector board for ADC 5V;
  • AltonaLab temperature sensor;
  • Mini PIR motion sensor;
  • 5V multi connector power supply board;
  • One load relay board 8A
  • 220V to 12V, 2A power supply;

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:

  • You need to have a Static IP address at your home. This will allow an external TCP/IP client as an android application running on your phone to be connected to an opened TCP/IP port from AltonaLab software. At this case, AltonaLab software is a TCP/IP Server!
  • After or before the diagram is started, you need to start the TCP/IP Server too. Just press the button next to the button for Start the process. When the TCP/IP Server is started, it will receive a commands from Android application running on your phone, and you can control or monitoring your home by phone:

 

  • Set the CommPort property of a Numato block in the diagram;
  • In block SunInfo - set the properties Latitude and Longitude with GPS coordinates of your home;
  • For block AndroidRemoteControl - you have to do a few settings, which are described below at this article;
  • In block MailSender to set all the properties related to the used mail account: Server, Port, UserName, Password, SenderEMail, RecipientMail, RecipientName. A MailSender block is well described at the article with URL below:

https://scada.altonalab.com/index.php/en/descriptions-of-the-functional-blocks/internet-library

 

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:

https://www.whatismyip.com/what-is-my-public-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: 192.168.2.3. 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. . . . . . . . . . . : 192.168.2.3

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 192.168.2.3, 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:

https://scada.altonalab.com/index.php/en/samples

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:

https://scada.altonalab.com/index.php/en/descriptions-of-the-functional-blocks/android-library-blocks

 

The properties of the block AndroidRemoteControl are shown below.

The properties are:

  • Properties ObjectID and Password has to be the same as the settings ObjectID and Password in the android application. One AltonaLab diagram can has more than one blocks AndroidRemoteControl, but this blocks need to have different ObjectID properties, which means some phones can send some commands, other phones can send other commands;
  • PhoneSettings - using this property we add at the top grid the monitoring signals, which values can be visible at the phone. The names of this values have to be added to the text of property TextOut of the block. At the bottom grid we add the buttons, which will appeared at the android application, when the button Get configuration is pressed at the Settings page of the android application. The added monitoring values appeared as inputs of the block AndroidRemoteControl, the added Buttons appeared as digital block's outputs. When the corresponding button at the android application is pressed, the same block's output becomes at a high value;
  • TextOut - at this diagram, the property is set to a text:

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:

https://scada.altonalab.com/index.php/en/conceptions/text-formatting-strategy