Home Automation Using IoT
This comprehensive guide to IoT and home automation covers commonly used architectures, platforms, sensors, and prototyping techniques.
Join the DZone community and get the full member experience.Join For Free
what really would compel someone to actually develop a complete iot-based home automation system? could it be the need to improve the safety of your home, or could it be the desire to live a jetson-like life that millennials always dreamt of?
it is difficult to say. often, it is even more difficult to visualize the technology that is required to build a home automation platform.
due to the complexity introduced by software, hardware, and networking ecosystems, it becomes extremely important to learn, understand, and utilize the right home automation technology for your smart home product.
we hope to address some of the concerns with this article.
what will you learn here?
- home automation: how to get started from zero
- home automation sensors and protocols
- home automation architectures, gateways, and platforms
iot home automation: getting started
home automation has three major parts:
- communication protocols
each of these parts is equally important in building a truly smart home experience for your customers. having the right hardware enables the ability to develop your iot prototype iteratively and respond to technology pivots with ease.
a protocol selected with the right testing and careful consideration helps you avoid performance bottlenecks that otherwise would restrict the technology and device integration capabilities with sensors and iot gateways.
another important consideration is the firmware that resides in your hardware managing your data, managing data transfer, firmware ota updates, and performing other critical operations to make things talk.
applications of home automation
rebuilding consumer expectations, home automation has been projected to target wide array applications for the new digital consumer. some of the areas where consumers can expect to see home automation led iot-enabled connectivity are:
- lighting control
- lawn/gardening management
- smart home appliances
- improved home safety and security
- home air quality and water quality monitoring
- natural language-based voice assistants
- better infotainment delivery
- ai-driven digital experiences
- smart switches
- smart locks
- smart energy meters
the list is still not exhaustive and will evolve over the time to accommodate new iot use cases.
now that you are familiar with home automation applications, let’s have a detailed look at what components are involved in building a typical home automation prototype.
home automation components
we have talked about them before, but let’s clearly separate our components that will finally help you build a realistic model of what major components are involved in building a smart home. the major components can be broken into:
- iot sensors
- iot gateways
- iot protocols
- iot firmware
- iot cloud and databases
- iot middleware (if required)
iot sensors involved in home automation are in thousands, and there are hundreds of home automation gateways as well. most of the firmware is either written in c, python, node.js, or any other programming language.
the biggest players in iot cloud can be divided into a platform-as-a-service (paas) and infrastructure-as-a-service (iaas).
major iot paas providers
- aws iot
- azure iot
- ibm bluemix
characteristics of iot platforms
again, these platforms are extremely divided over the iot application and security-related features that they provide. a few of these platforms are open source.
let’s have a look at what you should expect from a typical iot platform:
- device security and authentication
- message brokers and message queuing
- device administration
- support towards protocols like coap, mqtt, and http
- data collection, visualization, and simple analysis capabilities
- integrability with other web services
- horizontal and vertical scalability
- websocket apis for real-time for real-time information flow
apart from what we mentioned above, more and more platform builders are open sourcing their libraries to developers. take for example the dallas temperature library for ds18b20 for arduino was quickly ported because of open source development to a new version that helped developers to integrate ds18b20 with linkit one . understanding these things become crucial as iot tends to evolve continuously and having an equally responsive platform makes it business safe to proceed.
let’s now deeply evaluate each of these components, starting with iot sensors.
home automation sensors
there are probably thousands of such sensors out there that can be a part of this list, but since this is an introduction towards smart home technology, we will keep it brief. we will break down iot sensors for home automation by their sensing capabilities:
- temperature sensors
- lux sensors
- water level sensors
- air composition sensors
- video cameras for surveillance
- voice/sound sensors
- pressure sensors
- humidity sensors
- infrared sensors
- vibrations sensors
- ultrasonic sensors
depending upon what you need, you may use one or many of these to build a truly smart home iot product. let’s have a look at some of the most commonly used home automation sensors.
the market is full of them, but the famous temperature sensors are dht11/22, ds18b20, lm35, and msp430 series from ti. the msp430 series is more accurate than the rest, but at the same time, it is one of the most expensive for prototyping or initial product testing purposes. msp430 tops all temperature sensors, as the precision and battery consumption is minimal with them.
the dht11 has a very restricted temperature range and suffers from accuracy issues. dht22, on the other hand, is a little bit more accurate but still, doesn’t make it as the preference.
the ds18b20, on the other hand, is more accurate, as opposed to digital temperature sensors like the dht22 and 11. dallas temperature sensors are analog and can be extremely accurate down to 0.5 degrees.
take note that often, the temperatures that you directly sense from these sensors may not be very accurate, and you would occasionally see 1000 f or greater values no matter what you are doing.
there’s an entire logic that goes around building temperature sensors that we will address in another blog post.
lux sensors measure the luminosity and can be used to trigger various functions range from cross-validating movements to turn the lights on if it becomes too dark. some of the most popular light sensors are tsl2591 and bh1750.
recent tests to include tsl2591 and bh1750 into low-powered iot devices have found them to be working fairly well for most use cases.
here’s a study done by robert and tomas that shows how these two compare against a spectrometer and a photodiode.
to get a good idea of whether these two sensors would meet your needs, we would suggest illuminance tests followed by normalizations of the data to observe deviations under various situations.
water level sensors
while building your prototype, you may consider a solid state etape liquid level sensor or, like others, just use an hc-sr04 ultrasonic sensor to measure the water level.
on the other hand, in other cases where those two don’t suffice, one has to utilize something that can deliver a much higher performance.
float level sensors and other ics like lm1830 offer a more precise measurement capability to iot developers — although, they are substantially much more expensive than others.
air composition sensors
there are a couple of specific sensors that are used by developers to measure specific components in the air:
- co monitoring by mics-5525
- mq-8 to measure hydrogen gas levels
- mics-2714 to measure nitrogen oxide
- mq135 to sense hazardous gas levels (nh3, nox, alcohol, benzene, smoke, co2
most of these are sensors have a heating time, which also means that they require a certain time before they actually start delivering accurate values.
these sensors mainly rely on their surface to detect gas components. when they initially start sensing, there’s always something that’s there on their surface, some sort of deposition that requires some heating to go away.
hence, after the surface gets heated enough, true values start to show up.
video cameras for surveillance and analytics
a range of webcams and cameras specific to hardware development kits are usually used in such scenarios. hardware with usb ports offer to integrate camera modules to build functionality.
but utilizing usb ports is not very efficient, especially in the case of real-time video transfer or any kind of video processing.
take the raspberry pi for example. it comes with a camera module (pi cam) that connects using a flex connector directly to the board without using the usb port. this makes the pi cam extremely efficient.
sound detection plays a vital role in everything from monitoring babies to automatically turning lights on and off to automatically detecting your dog’s sound at the door and opening it up for your pet.
some commonly used sensors for sound detection include the sen-12462 and easyvr shield for rapid prototyping.
these sensors aren’t as good as industrial-grade sensors like those from 3dsignals , which can detect even ultra-low levels of noise and fine tune between various noise levels to build even machine break-up patterns.
these sensors bring the capability of sensing humidity/rh levels in the air to smart homes. the accuracy and sensing precision depends a lot on multiple factors, including the overall sensor design and placement.
but certain sensors like the dht22 and 11, built for rapid prototyping, will always perform poorly when compared to high-quality sensors like hih6100 and dig rh.
while building a product to sense humidity levels, ensure that there’s no localized layer of humidity that is obscuring the actual results. also, keep in mind that in certain small spaces, the humidity might be too high at one end as compared to the others.
when you look at free and open spaces where the air components can move much freely, the distribution around the sensor can be expected to be uniform and, subsequently, will require fewer corrective actions for the right calibration.
home automation protocols
one of the most important parts of building a home automation product is to think about protocols — protocols that your device will use to communicate to gateways, servers, and sensors. a few years ago, the only way to do so was by either using bluetooth, wi-fi, or gsm. but due to added expenses on cellular sim cards and low performance of wi-fi, most such solutions didn’t work.
bluetooth survived and later evolved as bluetooth smart or bluetooth low energy. this helped bring a lot of connectivity in the “mobile server powered economy.” essentially, your phone would act as a middleware to fetch data from ble-powered sensors and send it over to the internet.
when looking at the major home automation protocols, the following top the list:
- bluetooth low energy or bluetooth smart: wireless protocol with mesh capabilities, security, data encryption algorithms, and much more. ideal for iot-based products for smart homes.
- zigbee: low cost, mesh networked, and low power radio frequency-based protocol for iot. different zigbee versions don’t talk to each other.
- x10: a legacy protocol that utilizes powerline wiring for signaling and control.
- insteon: communicates with devices both wirelessly and with wires.
- z-wave: specializes in home automation with an emphasis on security.
- wi-fi: needs no explanation.
- upb: uses existing power lines installed in a home. reduces costs.
- thread: a royalty-free protocol for smart home automation, uses a 6lowpan.
- ant: an ultra low-power protocol helping developers build low-powered sensors with a mesh distribution capabilities.
home automation: which protocol is the best?
while there are some protocols that clearly offer much more, it is always important to start from your smart home development needs and then move towards narrowing down the solutions.
the commonly preferred protocols are bluetooth low energy, z-wave, zigbee, and thread. the protocol selection can now be narrowed down by the following factors:
- ability to perform identity verification
- quality of sensor networks
- data transfer rate
- security level
- network topology required
- density of objects around
- effective distance to be covered
home automation architecture
this architecture supports the following considerations for home automation solutions:
- end to end security mechanisms involving multilevel authentication
- end to end data encryption, including the link layer
- flexible and configurable access and authorization control
- powerful cloud infrastructure
- network agnostic with built-in feedback loops
- configurable cloud-based rules engine
- api endpoints
- data scalability
- nosql databases
home automation gateways
for developing a home automation product, often a standalone product sending data to a server is not enough. due to battery and protocol limitations, the data from a sensor or sensors present in a home has been routed through an iot gateway.
to select the perfect gateway for your iot home automation, consider some of these factors:
- communication protocols supported
- real-time capabilities
- mqtt, coap, and https support
- security and configuration
when it comes to building iot gateways, modularity and hybrid iot protocol support top the list when a product is in the early stages of market introduction.
to incorporate a gateway in your home automation stack, you can consider the following options:
either create a gateway from the ground up using existing hardware stacks for prototyping (using raspberry pi, intel edison, etc). then, when a poc is validated, you can create your own custom hardware.
or, you can use existing gateway modules like ingincs ble gateway . these gateways are extremely easy to customize and connect with your cloud services and devices. however, they may or may not offer the same level of support that you need to build certain features.
for example, a gateway with a bad networking queue may result in traffic congestion, or it may not support the required protocols that you wish to use.
further, pivoting with these gateways to some other technology stack may become very difficult. it should be emphasized that they are extremely good for robust prototyping needs.
home automation programming languages
home automation frameworks
if you think you can build everything for home automation (protocols, hardware, software, etc.) on your own, that is a bit unrealistic. everyone, from high-growth startups to billion-dollar consumer-focused enterprises, is now using the help of home automation frameworks to build connected products to delight consumers.
there are more than 15 different smart home frameworks available for iot developers to use and build their next generation of connected home products. some of these frameworks are open source and some are closed-source. let’s have a look at some of them in the sections that follow.
open source iot platforms and frameworks
looking forward to doing a quick and dirty prototype? there’s no need to write down everything from scratch. thanks to a bunch of awesome contributions, we have open source platforms that can get your home automation products up and running in no time.
our favorites are:
- home assistant
- openhab: supports raspberry pi, written in java and has design tools to build your own mobile apps by tweaking ui.
- openmotics[asked their developer, waiting for them to respond(dev confirmed)]
let’s take a look at the major home automation iot platforms.
supports raspberry pi, uses python, and the os is hassbian. it has simplified automation rules that developers can use to build their home automation product, saving them thousands of lines of code.
home assistant supports the following:
how home assistant works:
- home control: responsible for collecting information and storing devices.
- home automation triggers commands based on user configurations.
- smart home triggers based on past user behavior.
as developers, it is very important for us to understand the architecture of home assistant for us to build high-performing products on top of it.
let’s have a look at the architecture that makes control and information flow possible.
home control consists of five components:
- state machine
- event bus
- service registry
the core architecture of home assistant:
all of these components working together create a seamless asynchronous system for smart home iot. in the earlier version of home assistant core, the core often had to stop while looking for new device information.
but with the new versions of home assistant, a backward compatible api, and an async core have been introduced, making things a lot faster for iot applications.
the best part about home assistant’s core architecture is how carefully it has been designed and developed to support iot at home.
openhab is a home automation and iot gateway framework for smart homes. similar to home assistant, openhab works nicely with raspberry pi and comes with their own design tools to create a ui for your home automation product.
an understanding architecture of openhab:
- modularity: it is realized with the bundle concept
- runtime dynamics: so that software components can be managed at runtime
- service orientation: there are services for various components to speak with each other and exchange information
further relying on the ogsi framework, it leverages the following layers stacked together:
- modular layer: manages dependencies between bundles
- life cycle layer: controls the life cycle of the bundles
- service layers: defines a dynamic model of communication between various modules
- actual services: this is the application layer, using all other layers
- security layer: optional, leverages java 2 security architecture and manages permissions from different modules
- plugin framework
- rules engine
- logging mechanism
- ui abstraction: a tree structure for ui widgets, item ui providers, and dynamic ui configuration
- ui implementations are available for the web, android, and ios
- designer tools availability
openhab has been primarily only been observed as a project for the hobbyist programmer, and even many parts of openhab.org convey the same. but we have observed a different effort in recent times from openhab in building the developer economy for building iot smart homes.
take this slowly growing github repo talking about openhab cloud , for example.
according to the repository, openhab cloud architecture will look something like this:
impressive enough that some open platform out there is thinking about system services, cron jobs, logging, etc.
further, let's look at the frameworks and technologies that openhab will support: node.js, express.js, nginx, mongodb, redis, socket.io.
unlike home assistant’s vast integrability, openhab is currently limited to:
- amazon alexa
- aws ec2 [aws multi-az isn’t compatible for multiple time zone availability]
- aws iot with openhab
- mqtt support
openhab is extremely powerful, but at the same time very limited in terms of integration. the team behind openhab is extremely promising and have already conveyed their plans to open up openhab to other integration capabilities very shortly.
calaos was developed initially by a company that closed back in 2013, but home automation since then has grown, and it is being maintained and upgraded by developers. while now being open source, it facilitates premade source code to:
- create sweet home environments
- control music
- automation rules that focus on time, mood, or ambiance
- easy configuration
calaos supports the following hardware:
- raspberry pi
- intel-based machines
their lack of support towards developing private iot applications restricts their usage by developers to build high-quality solutions for consumers.
domoticz allows you to monitor and configure your devices and sensors with the simplest possible design. impressive enough that the entire project is extremely lightweight, it further is backed by high integrability with third parties and features like auto-learning switches.
this platform has been designed to work with operating systems like linux and windows.
protocol capabilities of domoticz include: z-wave, bluetooth, apple homekit, x10, and mqtt
hardware integration capabilities of domoticz:
- rfxcom transceiver
- esp2866 wi-fi module
- p1 smart meter
- youless meter
- pulse counters
- philips hue
- essent e thermostat
domiticz can be used to create any sort of services that you can think of, ranging from a smart weather device to a telegram bot.
currently, very few people know about the architecture of domoticz, making it extremely difficult to build applications on it without taking unnecessary risks in building the product itself.
for example, the entire design of general architecture feels a little weird when you look at the concept of a sensor to control to an actuator. it seems to be missing.
building advanced applications with domoticz can be done using c++, lula, php, shell, etc.
blockchain in iot
consumers, especially those who grew up in the digital era, understand the importance of privacy. with the evolution of iot, security has taken center stage for realistic deployment scenarios.
deployment of blockchain into home networks can easily be done with a $35 raspberry pi. a blockchain secured layer between devices and gateways can be implemented without a massive revamp of the existing code base.
simply put, blockchain is a technology that would be an implementation that most users won’t even know about, but it will play a huge role in the future to reassure them with revolutionary and new business models like dynamic renting for airbnb.
so far, interoperability issues and broken protocols seemed to have hampered the growth of iot-based smart homes.
but as technology is progressing and more and more computing power can be generated with very low-powered devices, home automation will gradually become a technology that will easy for us to build and develop for on a daily basis.
home automation is a big space to address in one blog post. if there’s something else that you would like, feel free to drop a comment or reach out to me on twitter – i am @hsshah_ .
Published at DZone with permission of Hardik Shah. See the original article here.
Opinions expressed by DZone contributors are their own.