Smarter Homes: Cost-effective options
With the significant advancement in technology such as cloud computing, Voice-controlled smart devices such as Alexa, AI/ML, mobile applications, and easy to program microcontrollers, it has become a lot easier to build home automation systems. In the coming years, there is a huge market for IoT in every country and globally the IoT market is forecasted to grow over trillion dollars in the next few years.
With open-source hardware and software platforms like Arduino, prices have become very affordable and there is a wide variety of micro-controllers available today. This has resulted in a shorter payback period for your investment in home automation projects.
Home automation is the utilization of intelligent "things", which is an automation system to control home appliances and equipment. An increase in awareness for efficient energy usage, a rise in electricity prices, and technological advancements are expected to drive the home automation market growth. Moreover, the increase in safety & security concerns fueled the adoption of the home automation systems, thus boosting the market growth.
Just the home automation market is expected to be over 90,000 Million USD. by 2024. I would expect more innovation to come in the area of microcontrollers, sensors, and home connectivity.
You also see various smart home products are available commercially which can be easily hooked with your home network, however, they do cost more and requires you to replace your existing electrical fittings. It's quite affordable and fun to build it yourself rather than buying ready-made products.
Also since your smart devices are now connected to the internet, you have the ability to control and monitor them remotely anywhere in the globe !.
Your purpose of home automation could be saving water, energy, or making your family safer.
There is no doubt that this provides an incredible learning opportunity at a low investment.
Moreover, IoT is an interesting topic for technology enthusiasts, students, and older folks like me :). It sort of binds software and hardware together into a useful solution that you can enjoy every day.
There are various IoT device management platforms today and we have a wide variety of choices for selecting the one most suitable.
Some of the other names are IoTsense, Thingspeak, inVIEW , Thingworx, Thingsboard (an open-source) to name a few. These platforms provide data collection, processing, visualization, and device management. Some of them have analytics and other higher-order features.
Let's understand the common use-cases for home automation.
- If you have a garden at home, you could build an IoT solution to automate the watering of plants and lawns while you are away or depending on weather conditions let the home automation make intelligent decisions on watering based on weather conditions.
- You can use sensors to control lights, fans for optimal use.
- Or you may be feeling cold during the early morning and you want to switch off your fan based on room temperature.
- Another useful solution could be to develop a home security system and use image recognition algorithms to allow or deny access to your home.
- How about generating automatic service alerts on electrical devices to your Alexa or mobile app.
- You can build robotic kits that could do useful work for you at home.!
Use-case that I took up as a priority was to automate home hot water geysers to optimize power consumption and monitor usage.
You may watch this short video to understand an application to control a home hot water geysers via Alexa and/or mobile application. You can notice that both the mobile app and Alexa are in sync with each other.
In the same way, you could make your other gadgets smarter.
Let's now briefly understand the technology stack which is relevant for this solution.
Alexa Skills Kit
AWS has done a pretty good job in providing a developer console for Alexa skill development and also Alexa Skills Kit(ASK) CLI to address your deployment needs to the cloud. Earlier the developer console was a bit clumsy but now it's very easy to use and also provides a simulator to test your skills.
Alexa has smart home skills which are a lot easier to use, however, it would lack the flexibility that you can achieve using a custom skill. In this example, a custom skill was developed which gives us full control over voice commands and responses.
The core concepts of Alexa skill-building start with having a skill invocation name ( ie. how you want to launch the skill ), planning the interaction model and then you can define various intents that will allow you to perform various tasks as required. For example, you may have an intent for "turn on the geyser" or "check your monthly usage", etc. SSML((speech synthesis markup language) support on Alexa allows you to control how Alexa generates speech from your skill's text responses. You will need to provide the serverless functions which will do the necessary task for the intents and return the response back to Alexa.
Alexa allows you to accept user input by using slots during dialog interactions. Alexa expects us to provide samples for each intent so that it can build the learning model for future interactions. It's quite powerful and has a variety of features that are worth exploring. The developer console allows us to host the lambda function as "Alexa hosted" or "AWS account hosted". I have chosen the latter since I required interactions with other AWS services.
Overall it's a good value proposition for a starter to use "Alexa hosted skill", as it makes it a lot easier, it's free, and does not require an AWS account.
Alexa stores the interaction model, samples, and intent definitions in a JSON document.
Alexa custom skills can also be monetized by publishing apps which is another interesting area to explore. The Alexa skill store has more than 100,000 voice apps and the list is growing. The growth in skills and device support is reflected by the cadence of updates to Alexa’s developer tools.
Although the easiest alternative for using Alexa based for home automation would be using something like "Sinric" (an Alexa Smart Home platform), it's free for 4 devices, however, it does not provide the level of flexibility you get by developing your own custom skill.
Blynk
Besides controlling your smart device from Alexa ( or Google home), you may use mobile apps, chatbots, smartwatches, web apps etc..
You can spend time writing mobile applications or use an app-builder called "Blynk" which is extremely useful for quick and elegant dashboarding. It provides you an API key and set of widgets that you can configure and map Virtual pins to your real device GPIO pins ( from a micro-controller). This gives us the ability to easily get nice graphs, useful widgets such as a real-time clock, alerts on your mobile, software sensors etc. The way it works is your micro-controller would connect to the Blynk cloud and the mobile app would fetch and send commands via the Blynk cloud to your microcontroller. You simply need to select the Widget and drag and drop and customize it to your needs. Blynk has 2000 energy units worth of widgets free initially then you can buy more widgets at a nominal cost using a credit card.
Once your Blynk customized app is done, you can share it with your friends and family and they get to use the app as well. Blynk supports timers, virtual pins which are very useful for simplifying your interactions with a micro-controller. It provides an Arduino ESP32 library for client interactions from the micro-controller.
I love the way it sets you up so quickly.
Blynk's popularity is due to its simplicity and ease of use.
One could use AWS IoT 1-click to trigger lambda functions well, however, I feel Blynk is better.
AWS IoT Core and lambda services
In order to fulfill your skill intents, you will most likely need to write serverless code or web services to return you the response from your device. For example, you ask Alexa to change the duration of the geyser to ten minutes, this input will be received by the lambda function to provide the desired effect. You can implement lambda function using NodeJS, python etc.
AWS IoT Core will allow devices to connect with the cloud and interact with the other devices and cloud applications. It provides support for HTTP, lightweight communication protocol, and MQTT.
AWS IoT, which is a pretty useful service for monitoring and controlling single or multiple devices ( thing) . It has a nice concept of a device shadow, which a virtual representation of the actual device state.
Your device shadow, a JSON document in AWS IoT, is where the device state is updated by Alexa and the micro-controller. There are IoT SDK that allows us to fetch the shadow details from Alexa and update the shadow based on user intents. Also from the micro-controller, you would be updating the shadow as the device state changes. You can update/fetch the shadow using MQTT publish/subscribe from your micro-controller. For example, suppose you switch on your device from Alexa and update the desired state of the shadow, AWS IoT generates a delta topic which the micro-controller would subscribe to and do the needful switching for the required device.
You can also ingest your sensor data from AWS IoT shadow topic using "topic rules" to any database or AWS Timestream for telemetry data. This is useful if are monitoring room temperature, humidity etc..
ESP32 Micro-controller board with Arduino IDE
ESP32 is one of the most popular and cost-effective development boards today, it comes with a real-time operating system ( FreeRTOS), dual-core, default bootloader, supports 2.4GHz WiFi, and Bluetooth. It runs on 3.3V and has analog and digital pins with various other features. It can be programmed using C/C++ /Micropython etc.. Reasonably easy to learn and program. You would typically program your ESP32 to connect to your home Wi-Fi network so that it gets an IP address and is on the internet.
ESP32 is a powerful beast that can do pretty good edge computing as well. It comes with a lightweight file system ( SPIFFS ), which can be used to keep a persistent state during power outages or when the micro-controller restarts.
Typically you would receive web requests from Blynk or MQTT requests from AWS IoT and the micro-controller would be programmed to do the needful on the physical device(Geyser).
For your circuit, you would use a relay (with optocoupler) to control a high current device like a geyser. The relay gets triggered by one of the GPIO pins ( digital output). I am also using an ACS712, a current sensor to detect power outages and signal the microcontroller accordingly. You can use a Blynk timer to switch off the geyser automatically based on the desired duration.
Final word
As a final step, you will require to test this thoroughly using a smaller device like a LED before using the solution on the home Geyser. Like any other software/hardware testing, you need to look at boundary conditions as well, error handling, all E2E test scenarios, and resilience of the solution to make it robust for long term usage. Some of the boundary conditions are how the solution behaves when home WiFi is down or there was a power outage, does the user ( Blynk, Alexa ) gets notified on-time.
The tricky part is ensuring that shadow states are consistent whether you use the Blynk app, Alexa, or both. Also, the status shown on Blynk needs to be the same as what we fetch from Alexa.
One more important aspect is to ensure there is adequate security in your solution all across to avoid any misuse by intruders.
Blynk and ESP32 allow secure communication, also the AWS IAM user and roles need to be given minimum privileges to avoid misuse. You should use MFA for the IAM user and ensure access keys are not shared with anyone. Unless you must have root user access keys (which is rare), it is best not to generate them. Limit your regions using a strict policy for the IAM user and Role. Besides it safer to avoid sharing code on public Github to avoid chances of access keys or tokens getting compromised. AWS Secrets Manager enables you to control access to secrets using fine-grained permissions and audit secret rotation centrally for resources in the AWS Cloud.
Also, it's a good idea to enable access control on your router to allow only the MAC address of your ESP32. In there are many smart devices that you need to secure, you may also use AWS IoT Device Defender.
What is best about using AWS or any cloud provider is the wealth of cloud services that are available to enhance your IoT solution further, such as databases, IoT analytics, ML services, data pipelines, etc.
The possibilities are endless!
Principal Product Manager | IIM-B | Business & Technology Expertise | AI Enthusiast
3 年This is really a great article Atanu , the level of technology and technical details you have gone into is amazing. The lucid manner in which you described the different options and various approaches is commendable. Many congratulations on such a comprehensive and knowledge filled article !!
Vice President at JPMorgan Chase & Co.
3 年Nice article Atanu Dasgupta! This reminded me of an AI app i built that used google speech to text n text to speech to automatically find and book meeting rooms in office using outlook.. The world has already taken giant steps in AI. But lot of ppl are still 'ok' with old style work.. Delighted to see a leader like you going so deep in tech.. Keep rocking!