Home Automation using Hombot: A User-Centric IoT Story
Motivation
Home automation has fascinated me for years. The concept of creating a system that is cost-effective, flexible, and extensible has always been my dream. Inspired by discussions on IoT forums, I started this personal project many years ago, working on it during weekends. Though work occasionally got in the way, I eventually completed Phase 1 of Hombot, an affordable and scalable home automation solution.
Introduction
Imagine walking into your home after a long day and saying, "Turn on the lights," and the lights instantly respond to your voice. What if this convenience came with a cheaper price tag and flexibility as compared to traditional home automation solutions? Enter Hombot—an innovative, cost-effective, and extensible IoT solution designed to make home automation accessible to all. This story explores the inspiration, design, and components of Hombot, an elegant framework developed with a clear purpose: to simplify life through technology.
Project supports the following wake words as of now: Ok Google, Hey Google, Computer, Alexa, with the possibility of custom wake words, as provided by the Porcupine library.
System Architecture: An Overview
The Hombot system’s architecture seamlessly integrates clients, servers, and controllers to deliver a cohesive user experience:
Hombot Clients: Capture user speech through a microphone. Use Porcupine for wake word detection. Convert audio to text using Google’s Speech-to-Text engine. Send the text to the Hombot Server via TCP/IP sockets.
Hombot Server: Processes speech-text to identify intents using intent executors. Delegates tasks to executors (currently, an MQTT executor). Sends MQTT commands to the appliance controller via an MQTT broker.
Appliance Controller (MQTT Clients): Built around the NodeMCU 8266 module, this controller receives commands via MQTT and operates relay modules to control devices like lights and fans
Architecture
Technology Stack
Hombot leverages a diverse range of open source libraries and tools to deliver its functionality:
Speech Recognition: Google Speech-to-Text engine.
Wake Word Detection: Porcupine library.
Audio Processing: PortAudio library.
GPIO Control: Go-RPIO library.
MQTT Communication: Eclipse Paho MQTT Go client for the server and PubSubClient for Appliance controller.
Programming Language: The entire project is written in Golang for its performance and concurrency capabilities.
The Result: Affordable and Scalable Automation
The Hombot framework provides a practical, scalable solution to home automation. By offloading intensive processing tasks to a central server and using affordable hardware for clients and controllers, the system achieves a perfect balance between cost and functionality
Future Potential
While the current implementation focuses on controlling lights and fans, the Hombot framework is built for expansion. At the heart of this systems there is an "intent executor".
Intent executor is a plugin that does the actual work of executing the intents.
It is the plugin that makes the whole system extensible.
There is a file entities.json which holds all the configuration to derive intents and their executor plugin. intent_handler extracts the intents and their executor from incoming text and passes on to the executorfactory, responsible for managing the executor plugin.
In this prototype an MQTT executor plugin is used for controlling the appliance controller via the MQTT commands. Simply put plugin is a library loaded dynamically as an when required.
Future updates could integrate additional intent executors, such as API executors, to interact with a broader range of devices and services like TV. The extensible design ensures Hombot can adapt to future requirements, keeping it relevant for years to come.
Conclusion
Hombot isn’t just a home automation solution; it’s a glimpse into the future of smart living. By prioritizing affordability, scalability, and extensibility, Hombot democratizes home automation, making it accessible to all. Whether you’re a tech enthusiast or someone looking for convenience, Hombot is a testament to how thoughtful design and technology can transform everyday life.
The full source code is available on GitHub for those eager to explore and contribute to this exciting project. The journey of Hombot has just begun, and the possibilities are endless!
Internals
Building the Hombot System
Hardware Components
Raspberry Pi 3 or above will suffice for both Hombot Client and Hombot Server as a Proof of Concept
USB Mic for Raspberry pi available off the shelf in local market or Amazon.
NodeMCU ESP8266 module available off the shelf in local market.
Relay module(s) operating on 5v DC available off the shelf in local market.
5v Power supply using off the shelf available good quality power adapter.
Jumper wires for connections.
Step-by-Step Guide
Set up the Raspberry Pi
Flash the SD card with the latest Raspbian OS
Boot the Pi and connect the USB microphone
Test microphone functionality using the arecord and aplay commands. For aplay you will need to connect a wired headphone or a Bluetooth speaker to Pi.
Connect two LEDs (with 600 Ohm resistors) to GPIO pins 17 and 18 for status indicators.
Connect the Pi to your home Wi-Fi network
Building the Server and Client applications
Prerequisites
Register for the Google Speech-to-Text API and download the credentials.
You would need to create a account and enable the API for use.
You would also need to generate credentials and download the KEY file for use on RaspberryPi. Set the path of this file on RaspberryPi into an environment variable GOOGLE_APPLICATION_CREDENTIALS.
Register for Porcupine Wake Word Detection at Porcupine Wake Word Detection & Keyword Spotting - Picovoice. Use forever-free plan to start with
Install Portaudio on Raspberry Pi (sudo apt install portaudio19-dev)
Install Mosquitto, an open source MQTT broker, on the Raspberry Pi which you plan to make the Hombot Server.
Note: Only if you are NOT running Mosquitto MQTT broker on Hombot Server update the below variables
set iot_server: to the IP address where Mosquitto MQTT broker is running else no change is required.
user and pass you can leave as "" if you are NOT using security on Mosquitto MQTT broker else specify your broker username and password.
Building the source code
Clone the repository in $HOME/go/src folder.
CD to the base folder where you downloaded the source code for e.g., /> cd go/src/hombot
Run the 2 build scripts in the folder “scripts” and you are good to go.
Note: First time build might take lot of time as it will download all the dependencies. See go.mod file for list of dependencies.
Starting the Server and the Client
Here is how you can run the Hombot Server and Client manually
Go to the base folder where you downloaded the Hombot code and
run the below command to start the Hombot server
/> ./hombotsrv/hbsrv
run the below command to start the Hombot client
/> ./hb
Both server and client will create log files in the /tmp folder of the Raspberry Pi
Building the Appliance Controller
Appliance controller is built using components mentioned below.
NodeMCU ESP8266 module available off the shelf in local market.
Relay module(s) operating on 5v DC available off the shelf in local market.
Power supply using off the shelf available good quality power adapter providing 5v.
Jumper wires for connections
Note: The pins marked in Yellow are the ones used in my prototype for turning on 1 light and 1 fan (with 5 speed). Driving a total of 6 relays. Vin supplied is 5V from the power adapter
How the 6 IO pins are driven
Note: You need not go into the details about this unless you want to change pins on your controller or use other other pins also.
To control the pins 32 byte integer value is passed to the appliance controller code. The least significant 2 bytes used for turning the pin ON while the most significant 2 bytes are used for turning the pins off.
The below table provides the values for various operations. For Fan Speed as 1 bit is turned ON the other bits are turned OFF hence both, the 2-byte sets are utilized. The bits used in each value are marked in BOLD.
Step-by-Step Guide for building appliance controller
Flashing the firmware
Prerequisites
Update the following variables in the firmware code file hombot_device.ino.
ssid: set it to the SSID of your home wi-fi network.
pass: set it to the password to connect to your home wi-fi network.
mqtt_server: set it to the IP address of your Raspberry Pi where Mosquitto Broker is running. This is also your Hombot Server.
mqtt_user and mqtt_pass you can leave as NULL if you are NOT using security on Mosquitto MQTT broker.
Note: Use static IP for your Hombot Server & Client and Appliance Controller
Flashing
After making the above changes flash the firmware hombot_device.ino to NodeMCU ESP8266 (Arduino IDE recommended).
There are several articles on internet on how to flash the firmware to NodeMCU ESP8266 using Arduino IDE. For e.g., Flash NodeMCU dev board with Arduino Sketch | by Grace Huang | Grace Learns IoT | Medium, NodeMcu ESP8266 First Time Setup With Arduino IDE : 10 Steps - Instructables
Connections
Connect the NodeMCU pins D1, D2, D3, D5, D6, D7 to the trigger pin (marked as IN) of the relays.
Connect the VCC and Gnd to 5v and Gnd from the power supply.
Connect Vin and Gnd of NodeMCU to 5v and Gnd from the power supply.
Once the connections are done you are good to go
For power supply cut open the 5v adapter and remove the internal circuit. Solder wires to directly to the 5v and Gnd terminals on the pcb
Use a small switch if required and house everything into a small box as shown below.
Note: Do not connect 5v to 3.3v pin of NodeMCU else it will burn the NodeMCU
Testing the Hombot Client & Server
Use NodeRed to simulate the appliance controller and view MQTT commands from the Hombot Server.
Follow the instructions here https://nodered.org/ for Installing NodeRed on your machine. Ensure that the machine where NodeRed is running is in same network as your Raspberry Pi.
Once installed open NodeRed console in a browser and import JSON data from hombot_test_flow.json (available in code) into it. You should get a flow something like below
Events messages: These are the commands sent from Hombot Server to appliance controller
Monitoring messages: These are the informational messages sent by the appliance controller to MQTT broker.
Error messages: These are the error messages sent by the appliance controller to MQTT broker.
Once the flow is imported into NodeRed the commands sent by the Hombot Server to Appliance controller will be visible in the NodeRed debug window. If the commands are coming it means Hombot Server is setup correctly.
IT leader | SIAM | PMO/SMO | Program Management | Digital Transformation | Process Consultant |SIAM Consulting | IT Operations |
7moVery nice easy to implement practical model.
Head of Technology and Cloud Center of Excellence, Smart Mobility Services. India
7moThe blog by Ritesh Tandon "Home Automation Using Hombot: A User-Centric IoT Story" offers an insightful exploration into the integration of IoT devices for enhancing home automation. The author's emphasis on user-centric design ensures that the technology remains accessible and practical for everyday users. The detailed walkthrough of Hombot's features and its seamless integration into daily routines provides readers with a clear understanding of its capabilities and benefits. There might be future future enhancements which could complement this offering such as: 1. Integration with Emerging Standards: Incorporating support for the "Matter standard " could enhance interoperability, enabling it to communicate seamlessly with a broader range of smart home devices. 2. Advanced Energy Management: Implementing features like energy consumption monitoring and optimization can help users reduce their carbon footprint and utility costs. 3. Enhanced Security Features: Integrating advanced security protocols and real-time monitoring . I congratulate Ritesh Tandon for his deep understanding of the related technologies and applied them in an effective way. I wish he can take it further including future commercialization opportunities.
Architect, Advanced automation,at Kyndryl India Ltd
7moNice article Ritesh Tandon