Advanced IoT Smart Home Energy Management System
Powered by AI-driven Predictive Analytics, Real-time Monitoring, and Automated Optimization
Features • Quick Start • Documentation • Contributing • Support
- Overview
- Key Features
- Technology Stack
- Architecture
- Quick Start
- Configuration
- API Documentation
- Testing
- Deployment
- Security
- Contributing
- License
- Support
- Roadmap
NexusHome IoT Platform is a comprehensive smart home energy management solution that leverages modern IoT protocols, machine learning, and real-time data processing to optimize energy consumption, reduce costs, and automate home operations.
The platform supports multi-protocol device communication (MQTT, HTTP, CoAP, Matter), provides advanced analytics through ML.NET, and delivers real-time updates via SignalR WebSocket connections.
- Energy Savings: Reduce energy consumption by up to 30% through AI-powered optimization
- Predictive Maintenance: Detect device failures before they happen with 90%+ accuracy
- Real-time Control: Monitor and control all devices instantly from anywhere
- Universal Compatibility: Support for all major IoT protocols and device standards
- Enterprise Ready: Production-grade security, scalability, and monitoring
- Multi-protocol device support (MQTT, HTTP, CoAP, Matter)
- Real-time device status monitoring via SignalR
- Automated device discovery and provisioning
- Room-based device organization
- Device health monitoring and diagnostics
- Predictive Maintenance: ML.NET models for failure prediction
- Energy Optimization: Dynamic power management based on usage patterns
- Smart Automation: Learning-based device automation rules
- Anomaly Detection: Real-time identification of unusual behavior
- Load Forecasting: Predict future energy consumption patterns
- Interactive real-time dashboards
- Historical data analysis and trend identification
- Cost optimization reports and recommendations
- Energy consumption breakdown by device and room
- Performance metrics and system health monitoring
- JWT-based authentication with role-based access control
- Device certificate authentication
- End-to-end TLS/SSL encryption
- API rate limiting and DDoS protection
- Comprehensive audit logging
- RESTful API with OpenAPI documentation
- SignalR hubs for real-time communication
- MQTT broker integration
- Azure IoT Hub support (optional)
- Weather API integration for smart optimization
|
|
- SQL Server - Primary relational database
- Redis - High-performance caching and session storage
- InfluxDB - Time-series data storage
- Docker & Docker Compose - Containerized deployment
- Grafana - Advanced data visualization
- Prometheus - Metrics collection and monitoring
- GitHub Actions - CI/CD automation
The platform follows a clean, layered architecture pattern:
┌─────────────────────────────────────────────────────────────┐
│ Presentation Layer │
│ (Blazor WebAssembly + REST API) │
├─────────────────────────────────────────────────────────────┤
│ Application Layer │
│ ┌──────────────────┬──────────────────┐ │
│ │ API Controllers │ SignalR Hubs │ │
│ └──────────────────┴──────────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Business Logic Layer │
│ ┌──────────────┬─────────────┬────────────┬──────────┐ │
│ │ Device │ Energy │ AI/ML │ Auto- │ │
│ │ Management │ Analytics │ Services │ mation │ │
│ └──────────────┴─────────────┴────────────┴──────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Infrastructure Layer │
│ ┌──────────────┬─────────────┬────────────┐ │
│ │ Data Access │ External │ Message │ │
│ │ (EF Core) │ APIs │ Queue │ │
│ └──────────────┴─────────────┴────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Data Storage Layer │
│ SQL Server │ InfluxDB │ Redis │
└─────────────────────────────────────────────────────────────┘
- Clean Architecture - Separation of concerns with dependency inversion
- Repository Pattern - Data access abstraction
- CQRS - Command Query Responsibility Segregation
- Event-Driven - Asynchronous processing with background services
- Dependency Injection - Loose coupling and testability
Before you begin, ensure you have:
- .NET 8.0 SDK
- Docker Desktop
- SQL Server or SQL Server Express
- Git
- IDE: Visual Studio 2022 or VS Code
- Clone the repository
git clone https://github.com/aaron-seq/NexusHome_IoT.git
cd NexusHome_IoT- Setup environment
# Create necessary directories
mkdir -p logs data uploads certificates
# Copy configuration file
cp appsettings.json appsettings.Development.json- Configure database
# Install EF Core tools
dotnet tool install --global dotnet-ef
# Update connection string in appsettings.Development.json
# Then create and apply migrations
dotnet ef migrations add InitialCreate
dotnet ef database update- Run the application
# Restore dependencies
dotnet restore
# Build the project
dotnet build
# Run in development mode
dotnet run- Access the application
- Main Application: http://localhost:5000
- API Documentation: http://localhost:5000/swagger
- Health Check: http://localhost:5000/health
For a complete stack deployment:
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose downServices will be available at:
- Application: http://localhost:5000
- Grafana: http://localhost:3000
- Prometheus: http://localhost:9090
Key configuration options:
# Database
ConnectionStrings__DefaultConnection="Server=localhost;Database=NexusHomeIoT;Trusted_Connection=true"
ConnectionStrings__Redis="localhost:6379"
# Security
JwtAuthentication__SecretKey="your-secret-key-min-32-characters"
JwtAuthentication__Issuer="NexusHome.IoT"
JwtAuthentication__Audience="NexusHome.Clients"
JwtAuthentication__ExpirationMinutes=60
# MQTT Configuration
MqttBroker__Host="localhost"
MqttBroker__Port=1883
MqttBroker__Username="nexususer"
MqttBroker__Password="your-secure-password"
# External Services
WeatherApi__ApiKey="your-openweather-api-key"
WeatherApi__BaseUrl="https://api.openweathermap.org/data/2.5"- appsettings.json - Base configuration
- appsettings.Development.json - Development overrides
- appsettings.Production.json - Production settings
- docker-compose.yml - Docker service orchestration
All API endpoints require JWT authentication:
POST /api/auth/login
Content-Type: application/json
{
"username": "admin",
"password": "your-password"
}GET /api/devices # List all devices
GET /api/devices/{id} # Get device details
POST /api/devices/{id}/toggle # Toggle device state
POST /api/devices/telemetry # Submit telemetry data
GET /api/devices/{id}/energy # Get energy consumptionGET /api/energy/consumption # Total consumption data
GET /api/energy/cost # Cost analysis
GET /api/energy/forecast # Usage predictions
GET /api/energy/optimization # Optimization suggestionsGET /api/automation/rules # List automation rules
POST /api/automation/rules # Create new rule
PUT /api/automation/rules/{id} # Update rule
DELETE /api/automation/rules/{id} # Delete ruleConnect to SignalR hubs for real-time updates:
const connection = new signalR.HubConnectionBuilder()
.withUrl("/hubs/device-status")
.build();
// Subscribe to device updates
connection.on("DeviceStatusChanged", (device) => {
console.log(`Device ${device.id} status: ${device.status}`);
});
await connection.start();For complete API documentation, visit /swagger when running the application.
# Run all tests
dotnet test
# Run with code coverage
dotnet test --collect:"XPlat Code Coverage"
# Run specific test category
dotnet test --filter "Category=Integration"# Run integration tests
dotnet test --filter "Category=Integration"
# Test with real database
dotnet test --filter "Category=DatabaseIntegration"Using k6 for performance testing:
# Install k6
brew install k6 # macOS
# Run load test
k6 run --vus 50 --duration 60s scripts/load-test.js# Test device endpoint
curl -X GET "http://localhost:5000/api/devices" \
-H "Accept: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
# Submit telemetry
curl -X POST "http://localhost:5000/api/devices/telemetry" \
-H "Content-Type: application/json" \
-d '{
"deviceId": "smart-thermostat-01",
"sensorData": {"temperature": 23.5, "humidity": 45},
"timestamp": "2025-11-08T10:00:00Z"
}'Before deploying to production:
- Update all secrets and API keys
- Configure production database connection
- Enable HTTPS and configure SSL certificates
- Set up monitoring and alerting
- Configure backup strategy
- Review security settings and rate limits
- Set up log aggregation
- Configure CDN for static assets
- Enable database connection pooling
- Set up automated backups
# Build production image
docker build -t nexushome-iot:v2.1.0 -f Dockerfile.prod .
# Run production container
docker run -d \
-p 80:80 \
-p 443:443 \
--name nexushome-prod \
--env-file .env.production \
--restart unless-stopped \
nexushome-iot:v2.1.0# Login to Azure
az login
# Create resource group
az group create --name nexushome-rg --location eastus
# Deploy to App Service
az webapp up --name nexushome-iot --resource-group nexushome-rg --runtime "DOTNET|8.0"# Push to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin YOUR_ECR_REPO
docker tag nexushome-iot:latest YOUR_ECR_REPO/nexushome-iot:latest
docker push YOUR_ECR_REPO/nexushome-iot:latest
# Deploy to ECS (using task definition)
aws ecs update-service --cluster nexushome-cluster --service nexushome-service --force-new-deployment# Apply Kubernetes manifests
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/secrets.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
kubectl apply -f k8s/ingress.yaml
# Check deployment status
kubectl get pods -n nexushome
kubectl logs -f deployment/nexushome-iot -n nexushomeThe platform implements multiple security layers:
- JWT tokens with configurable expiration
- Role-based access control (Admin, User, Device)
- API key authentication for IoT devices
- Refresh token rotation
- Password hashing with BCrypt
- SQL injection protection via parameterized queries
- Input validation and sanitization
- XSS protection with CSP headers
- CSRF token validation
- Encrypted data at rest and in transit
- HTTPS enforcement (TLS 1.2+)
- CORS policy configuration
- Rate limiting (100 requests/minute per IP)
- DDoS protection via reverse proxy
- IP whitelisting for admin endpoints
- Device certificate-based authentication
- Encrypted MQTT communication
- Device provisioning workflow
- Anomaly detection for suspicious activity
{
"SecuritySettings": {
"RateLimiting": {
"Enabled": true,
"RequestsPerMinute": 100
},
"Cors": {
"AllowedOrigins": ["https://yourdomain.com"],
"AllowedMethods": ["GET", "POST", "PUT", "DELETE"],
"AllowCredentials": true
},
"HttpsRedirection": true,
"HstsMaxAge": 31536000
}
}If you discover a security vulnerability, please email [email protected]. Do not open a public issue.
For more details, see SECURITY.md.
We welcome contributions from the community! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated.
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Make your changes
- Run tests
dotnet test dotnet format --verify-no-changes - Commit your changes
git commit -m "Add amazing feature" - Push to your branch
git push origin feature/amazing-feature
- Open a Pull Request
- Follow C# coding conventions and style guidelines
- Write unit tests for new features
- Update documentation as needed
- Keep pull requests focused and atomic
- Reference relevant issues in PR descriptions
For detailed guidelines, see CONTRIBUTING.md.
This project adheres to a Code of Conduct. By participating, you are expected to uphold this code.
See CODE_OF_CONDUCT.md for details.
This project is licensed under the MIT License. You are free to use, modify, and distribute this software.
See LICENSE for the full license text.
MIT License
Copyright (c) 2025 Aaron Sequeira
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files...
- API Documentation: Available at
/swaggerwhen running - Architecture Guide: See docs/ARCHITECTURE.md
- Deployment Guide: See docs/DEPLOYMENT.md
- Troubleshooting: See docs/TROUBLESHOOTING.md
- GitHub Issues: Report bugs or request features
- GitHub Discussions: Ask questions and share ideas
- Stack Overflow: Tag questions with
nexushome-iot
- Email: [email protected]
- LinkedIn: Aaron Sequeira
- GitHub: @aaron-seq
- Voice assistant integration (Alexa, Google Assistant)
- Cross-platform mobile app (React Native)
- Enhanced ML models for energy prediction
- Multi-tenant architecture support
- Advanced reporting and export features
- Edge computing support for local processing
- Blockchain-based device identity management
- Solar panel and battery integration
- Community energy sharing marketplace
- Advanced weather correlation
- Global smart grid integration
- Carbon footprint tracking and offsetting
- Peer-to-peer energy trading
- Machine learning model marketplace
- IoT device ecosystem partnerships
Special thanks to:
- Microsoft .NET Team for the excellent .NET 8 framework
- Eclipse Mosquitto for the reliable MQTT broker
- ML.NET Team for machine learning capabilities
- Open Source Community for amazing libraries and tools
- Contributors who have helped improve this project
Built with care by Aaron Sequeira and the NexusHome community
If you find this project helpful, please consider giving it a star!