A Python-based smart home automation system that combines facial recognition, voice commands, and home automation features. The system can recognize users, provide voice feedback, control smart lights, check weather, and play music.
- Real-time face detection and recognition
- Automatic user login/logout based on facial recognition
- Voice greetings when recognized users are detected
- Multi-user support with session management
- Text-to-speech feedback using pyttsx3
- Voice announcements for user recognition
- Voice responses for system commands
- Smart Light Control: Control Kasa smart lights via IP address
- Turn lights on/off
- Adjust brightness
- Change colors (red, green, blue, white)
- Weather Information: Get real-time weather data
- Temperature
- Wind speed
- Precipitation
- Sunrise/sunset times
- Music Player: Play music files using mpg123
- Finger counting and gesture detection
- Visual feedback for hand gestures
- Configurable gesture responses
- Webcam for facial recognition
- Microphone (optional, for future voice input features)
- Smart lights compatible with Kasa protocol
- Python 3.7+
- OpenCV
- Face recognition libraries
- Internet connection for weather API
-
Clone the repository
git clone <repository-url> cd smartHome
-
Install required Python packages
pip install -r requirements.txt
Or install manually:
pip install pyttsx3 opencv-python face-recognition imutils requests cvzone PyYAML
-
Install system dependencies
# For Ubuntu/Debian sudo apt-get install mpg123 # For macOS brew install mpg123 # For Windows # Download mpg123 from https://www.mpg123.de/
-
Setup configuration
# Copy the example configuration cp config.example.yaml config.yaml # Edit the configuration file with your settings nano config.yaml
The system uses a YAML configuration file for all settings:
-
Copy the example configuration:
cp config.example.yaml config.yaml
-
Edit the configuration file with your specific settings:
- Update smart light IP addresses
- Set your location coordinates for weather
- Configure voice settings
- Adjust camera settings
The system requires pre-trained facial encodings. You need to:
- Create a
facial_recognition/directory - Add an
encodings.picklefile with known face encodings - Update the
encodings_filepath in yourconfig.yaml - The system will automatically copy this file to the working directory
Note: The encodings.pickle file should contain a dictionary with:
"encodings": List of face encodings"names": List of corresponding names
Update the smart light settings in your config.yaml:
smart_lights:
kasa_host: "192.168.12.238" # Your light's IP address
kasa_port: 9999 # Kasa port
default_brightness: 80 # Default brightnessThe system uses Meteomatics API for weather data. For production use:
- Set
use_mock_data: falsein your config - Update location coordinates in the weather section
- The system includes caching and error handling for API calls
Run the main driver:
python driver.pyThe system will:
- Initialize the facial recognition system
- Start the webcam feed
- Begin monitoring for recognized faces
- Provide voice feedback when users are detected
Once logged in, you can use these commands:
-
lights- Control smart lights- Choose "on" or "off"
- Set brightness (0-100)
- Choose color: red, green, blue, or white
-
weather- Get weather information- Choose: temp, wind, precip, sunrise, or sunset
-
music- Play music file (requiresmusic.mp3in directory) -
logout- Log out current user -
help- Display available commands
Hi. What would you like to do? lights
On or off? on
Brightness? 80
Color? blue
smartHome/
βββ driver.py # Main application driver
βββ logic.py # User management and command logic
βββ facial_req.py # Facial recognition system
βββ hand_req.py # Hand gesture recognition (experimental)
βββ config_manager.py # Configuration management
βββ error_handler.py # Error handling and recovery
βββ config.yaml # Configuration file (create from example)
βββ config.example.yaml # Example configuration
βββ requirements.txt # Python dependencies
βββ facial_recognition/ # Directory for face encodings
β βββ encodings.pickle # Pre-trained face data
βββ README.md # This file
All configuration is now managed through the config.yaml file. The system includes:
- Centralized Settings: All settings in one YAML file
- Validation: Automatic configuration validation on startup
- Defaults: Fallback to sensible defaults if configuration is missing
- Environment Support: Easy to modify for different environments
Voice Settings:
voice:
rate: 160 # Speech rate
voice_index: 16 # Voice selection
volume: 1.0 # Volume levelCamera Settings:
camera:
source: 0 # Camera source
framerate: 2 # Processing framerate
width: 500 # Frame widthSmart Light Settings:
smart_lights:
kasa_host: "192.168.12.238" # Your light's IP
colors:
red: [0, 100, 80] # HSV color valuesWeather Settings:
weather:
location:
latitude: 41.8781 # Your latitude
longitude: -87.6298 # Your longitude
use_mock_data: true # Use mock data for testingThe system now includes comprehensive error handling and recovery mechanisms:
- Custom Exceptions: Specific error types for different components
- Automatic Recovery: Attempts to recover from common errors
- Graceful Degradation: Continues operation when possible
- Detailed Logging: Comprehensive error logging with context
- Error Statistics: Track and monitor error patterns
-
Camera not found
- Check camera permissions
- Try different camera sources in config.yaml
- Verify camera is not in use by another application
-
Face recognition not working
- Ensure
encodings.picklefile exists and path is correct in config - Check lighting conditions
- Verify face is clearly visible
- Adjust tolerance setting in configuration
- Ensure
-
Voice not working
- Install system text-to-speech drivers
- Check audio output settings
- Verify voice index in configuration
-
Smart lights not responding
- Verify IP address is correct in config.yaml
- Check network connectivity
- Ensure Kasa CLI is installed
- Check light power and network status
-
Configuration errors
- Validate your config.yaml file
- Check for syntax errors
- Ensure all required sections are present
The system now provides detailed logging:
- Log File: Check
smartHome.logfor detailed error information - Console Output: Real-time status and error messages
- Error Recovery: Automatic attempts to recover from failures
To enable debug logging, set in your config.yaml:
system:
log_level: "DEBUG"- The system stores face encodings locally
- No data is transmitted to external servers (except weather API)
- Consider implementing additional authentication for sensitive operations
- Regularly update face encodings for security
- Voice command input
- Integration with more smart home devices
- Mobile app interface
- Scheduling and automation features
- Enhanced security features
- Support for more weather APIs
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Check the troubleshooting section
- Review the code comments
- Create an issue in the repository
Note: This is a demonstration project. For production use, implement proper security measures and error handling.