Let’s MONITOR our house with IFTTT

By on September 18, 2019
Pin It


Let’s switch on the house lights using voice commands given through Google Assistant and the ESP demoboard for WiFi connection.

Google is one of the most innovative companies in the IT sector and it’s testified by the exorbitant number of users who use its services: from the most widely used search engine to the cloud to manage its documents (which can be stored and edited), the services offered by the giant of Mountain View are really numerous and above all extremely useful to the bulk of the public.

The most suggestive service offered by Google is currently the Google Assistant voice assistant, which is made available on all the latest generation smartphones in which the Android operating system is installed.

Recently the hardware version for domestic use, called Google Home, has been launched on the market which, in the more economic version, looks more or less like a round bar of soap of about 10cm in diameter. However, there are alternatives offered by other companies, such as Siri from Apple, Alexa from Amazon and Invoice from Samsung, but currently, the vast majority of users use the Google system.

While to use the voice assistant on Android mobile devices it is necessary to unlock the screen, the home version is always active and will immediately respond to your commands.

At this point a question naturally arises: exactly, what does a voice assistant do? Well, on a technical level it is a very sophisticated voice recognition system, able not only to understand what you said but, thanks to artificial intelligence, also to interact with you, learning over time to adapt the answers to your needs.

By collecting more and more information on where you live and where you normally move, it can provide you with voice messages useful for your travels or weather conditions. By knowing your musical tastes, you can start your favourite music faster.

Obviously, the basic response functions to the simplest questions will always be available, such as those for making a mathematical calculation, to answer the request of a random number or the question about the age of your favourite actor. Analyzing the numerous questions that are asked, the voice assistant will be increasingly able to respond in a consistent and sensible way, almost as if we were talking to a person in the flesh.

Given the “cut” of our magazine, we will not enter into the ethics of this technology, nor will we address the issue of privacy (which becomes current, given that the system collects as much information as possible about users’ lives to adjust the shot), but we will limit ourselves to exploit this opportunity for practical purposes of daily use.

However, we are certain that you will not be wanting to try this new technology out of curiosity.

At the Consumer Electronics Show (CES), the consumer electronics fair held in January in Las Vegas (United States), numerous products were presented that integrate Amazon’s Alexa, Apple’s Siri and the Google Assistant. The devices currently compatible with Google Assistant are about 5,000: they range from LED bulbs to power sockets (now on sale for some time) to the most recent room thermostats and robot vacuum cleaners, but also to the blackout curtains (proposed by the Swedish Ikea).

Just at the CES, Google announced that its assistant, thanks to the massive presence on Android smartphones, will shortly be covering one billion devices, while Amazon in recent weeks has announced the overcoming of 100 million devices with Alexa. Let’s see how we can use this technology for our utility, the goal we set ourselves is to manage a light point in our home using a common smartphone and Google Assistant voice commands.

Prerequisite for being able to implement this project is to have access to the internet via WiFi, to have a development board based on the ESP module and the Arduino IDE configured for programming ESP modules.

The first step is to have suitable hardware able to receive commands from the Internet and consequently activate a load powered by the mains voltage: a cheap module with an ESP8266 chip interfaced to a TTL control relay can do the job. This hardware is in effect a real IoT (Internet of Things) device.

Any board based on ESP2866 is fine, including the NodeMCU, Espresso Lite, or our ESP03 Demoboard board (code FT1191M) used in this article;

As for the switching of the load, a simple relay module, such as the one proposed by openelecronics with the code 2846-RELAY1CH will be more than fine. This module is supplied already assembled and tested and contains a one-piece relay with a 5 volt coil, capable of switching 10A in systems operating up to 240Vac; the command is given to him on the “S” contact and consists of a positive voltage level with respect to ground, typically 5V.

The only other element required will be a small switching power supply unit (220V / 50Hz) with a 5V stabilized DC voltage output (1.5A of current is enough) needed to power the board. The connection diagram is shown in Fig. 2.


Fig. 2


The second step is to ensure that our IOT device is reachable from the internet, in fact, the visibility within the local WiFi network available in our home is not sufficient. To do this we have to use a cloud service like the one offered by the American Adafruit who recently set up the Adafruit IO server, specifically created to connect small IoT devices to the network and thus be able to interact with them. Following the next steps, we will be able to control the lights of our home from any networked browser.


Step 1

We access the site https://io.adafruit.com and create an account by clicking on Sign up for free; for small projects the service is completely free (Fig. 3).


Fig. 3


Step 2

On the main screen select feed then on the action and then create a news feed. Then insert a new feed named on/off which will contain the data that will be exchanged with your IoT device (Fig. 4).


Fig. 4


Step 3

Click on the news feed; the dashboard screen will open, which you can customize as you like. Click on the + button and add a toggle switch (Fig. 5). Continue with the settings and select the feed to which the switch will be associated (Fig. 6). Continue again and in the Button On Text field enter the text ON, while in the Button Off Text field insert the string OFF (Fig. 7).


Fig. 5


At this point, you have completed the part related to the cloud and you are ready to program your IOT device.


Fig. 6/7


Step 4

Open the Arduino IDE and in the library management section (Sketch menu command> Import library) look for and install the library named Adafruit MQTT library. This library will add the commands that will allow you to manage the communication between the IOT board and the Adafruit cloud through the MQTT protocol (Fig. 8). Load the sketch named AdafruitIO_IFTTT_ONOFF.ino downloadable together with the files of this issue of the magazine and update the WIFI_SSID and WIFI_PASS fields with the credentials to access your WiFi network. Return for a moment to Adafruit IO (Fig. 9) and from the main screen select the View IO Key tab and copy the two Username and Active key fields, then paste them into the listing in the respective entries; these represent the credentials for accessing the cloud.


Fig. 8


Make sure that in the line Adafruit_MQTT_Subscribe onoff = Adafruit_MQTT_Subscribe (& mqtt, MQTT_NAME “/ f / onoff“) the name of the feed you created and with which you want to interact is present (Fig. 10).


Fig. 9


Then load the sketch on the development board and open Serial Monitor to view the debug, if the procedure is successful the board will connect to your WiFi network and then connect to the Adafruit cloud.


Fig. 10


Check that everything works correctly: by operating the switch on Adafruit IO, you must be able to control the activation of the output and the switching on of the relay. Both on Serial Monitor and on the Adafruit dashboard you will have the list of commands exchanged between the cloud and the IOT board (Fig. 11).


Fig. 11


Step 5

At this point, we are ready to implement the activation of the relay through voice commands. We need to connect the Google Assistant service with the Adafruit cloud and for this, we must use the IFTTT service, created by a Californian company specifically to connect different and heterogeneous services on the network.


Fig. 12/13

We access the IFTTT page at the link https://ifttt.com/ and we subscribe to the service through the Google account, since we should still use its services. Upon entering, IFTTT will provide you with a series of ready-made examples, instead, we will click on My Applets and then on the small button + to create an application of our own.

Click on the + symbol next to this to start the process of creating a new applet. Look for the Google Assistant service and select it, when a screen opens in which you can set what you think your trigger should be, ie the event that will activate the lights in your home.

Select the first item (Say a simple phrase) and in the What do you want to say field set the phrase you will say to activate the lights, for example, “turn on lights” (Fig. 14). In the next two fields you can enter alternative phrases such as “lights on” or “turn on the lights”, while in the field What do you want the Assistant to say in response?


Fig. 14


Insert the answer phrase of the assistant: for example “ok, turn on the lights” (Fig. 15). In the last field, ie Language, select the Italian language. At this point the trigger is ready: we only need to set the corresponding action.


Fig. 15


Step 6

Select this time the “that” and look for Adafruit among the services (Fig. 16), then select the only item available (for the moment) Send data to Adafruit IO. In the Feed, name field selects the feed previously created or on/off while in the Data to field save the string ON (Fig. 17), then click on create action and confirm the creation of the applet (Fig. 18).


Fig. 16


Repeat the procedure creating a new applet that we will use to turn off the lights, so the voice command could be “turn off lights” and the action will have to send the string OFF.


Fig. 17


At the end of the procedure, you will find yourself with two operative applets, one to activate the light and one to turn it off (Fig. 19). If necessary, you can still make changes at any time by clicking on the gear icon.


Fig. 18


We just have to call up the Google Assistant with the voice command “ok Google” and give the commands “turn on lights” and “turn off lights”, always on the Arduino Serial Monitor you will see the commands received. We note that in the firmware, the only lines necessary to manage the commands are the ones shown in Listing 1. These are two simple ifs that verify the received string sent by the Adafruit cloud in turn received by the IFTTT service; nothing easier. We could easily modify the trigger phrases and the action text to be able to carry out our specific function. For example, we could modify the previous listing to be able to manage the opening of a door interlocked by an electric lock, in the one visible in Listing 2.


Fig. 19


The phrase relating to the trigger could be of the “open the door” type with the sending of the string “DOORON”, the task of the software is to activate the electric lock for a moment, perhaps connected to another output on the board, in order to leave both systems operational. In this case, you don’t need a second applet that executes the off command.

Listing 1

void readTouchInputs()
if (!strcmp((char*) onoff.lastread, “ON”)) digitalWrite(LED_PIN, HIGH);
if (!strcmp((char*) onoff.lastread, “OFF”)) digitalWrite(LED_PIN, LOW);

Listing 2

void readTouchInputs()
digitalWrite(LED_PIN, HIGH);



Let’s finish this article sure of having you

at least intrigued and certain that many of you will want to test our application example in practice, also because putting together the required hardware costs very little.

You will immediately see how comfortable it is to manage users in the home environment and if you have guests, you will be amazed by seeing them have everything under control, even the lights of the house, simply by ordering by voice what you want. In short, you will already have a foot in the future, which will certainly see the massive use of voice assistance systems.


From openstore

FT1191M Demoboard ESP03

Module 1 relay


About Boris Landoni

Boris Landoni is the technical manager of Open-Electronics.org. Skilled in the GSM field, embraces the Open Source philosophy and its projects are available to the community.

Leave a Reply

Your email address will not be published.