Advanced IoT-enabled Smart Home Energy Management System with AI-powered Predictive Analytics, Real-time Monitoring, and Automated Optimization.
- Multi-Protocol Device Support: MQTT, HTTP, CoAP, Matter protocol compatibility
- Real-time Device Monitoring: Live status updates via SignalR WebSocket connections
- Energy Consumption Tracking: Detailed power usage analytics and cost calculations
- Room-based Organization: Logical grouping and management of devices by location
- Predictive Maintenance: ML.NET-based failure prediction with 90%+ accuracy
- Energy Optimization: Dynamic power management based on usage patterns and pricing
- Smart Automation: Rule-based and learning-based device automation
- Anomaly Detection: Real-time identification of unusual device behavior
- Interactive Dashboards: Real-time energy consumption and device status displays
- Historical Data Analysis: Comprehensive reporting with trend identification
- Cost Optimization Reports: Detailed savings analysis and recommendations
- Performance Metrics: System health monitoring and diagnostic tools
- JWT Authentication: Secure token-based user authentication
- Role-Based Access Control: Multi-tier permission system
- Device Certificates: Secure device-to-platform communication
- End-to-End Encryption: TLS/SSL protection for all data transmission
- .NET 8.0 - Latest LTS version with performance enhancements
- ASP.NET Core - High-performance web framework
- Entity Framework Core 8.0 - Advanced ORM with SQL Server support
- SignalR - Real-time bi-directional communication
- MQTTnet - High-performance MQTT client/server
- Azure IoT Hub - Cloud-based device management (optional)
- Matter Protocol - Universal IoT connectivity standard
- WebSocket - Real-time web communication
- SQL Server - Primary relational database
- Redis - High-performance caching and session storage
- InfluxDB - Time-series data storage
- ML.NET - Machine learning and predictive analytics
- Docker & Docker Compose - Containerized deployment
- Grafana - Advanced data visualization
- Prometheus - Metrics collection and monitoring
- Serilog - Structured logging with multiple sinks
Ensure you have the following installed on your development machine:
- .NET 8.0 SDK (Download here)
- Docker Desktop (Download here)
- SQL Server or SQL Server Express (Download here)
- Visual Studio 2022 or VS Code (recommended)
- Git for version control
# Clone the repository
git clone https://github.com/aaronseq12/NexusHome_IoT.git
cd NexusHome_IoT
# Create necessary directories
mkdir logs data uploads certificates
# Copy environment configuration
cp appsettings.json appsettings.Development.json
# Update connection string in appsettings.Development.json
# Default: "Server=localhost;Database=NexusHomeIoT;Trusted_Connection=true;MultipleActiveResultSets=true;TrustServerCertificate=true"
# Install EF Core tools (if not already installed)
dotnet tool install --global dotnet-ef
# Create and apply database migrations
dotnet ef migrations add InitialCreate
dotnet ef database update
# Start SQL Server container
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=NexusHome@2025!" \
-p 1433:1433 --name nexus-sqlserver -d \
mcr.microsoft.com/mssql/server:2022-latest
# Update connection string to use SQL Server authentication
# "Server=localhost;Database=NexusHomeIoT;User=sa;Password=NexusHome@2025!;TrustServerCertificate=true"
# Create MQTT configuration directory
mkdir -p Configuration
# Create basic Mosquitto configuration
cat > Configuration/mosquitto.conf << EOF
listener 1883
listener 9001
protocol websockets
allow_anonymous true
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
log_type all
EOF
# Start MQTT broker
docker run -it -p 1883:1883 -p 9001:9001 \
-v \$(pwd)/Configuration/mosquitto.conf:/mosquitto/config/mosquitto.conf \
eclipse-mosquitto:2.0
# Ubuntu/Debian
sudo apt-get install mosquitto mosquitto-clients
# macOS
brew install mosquitto
# Windows - Download from https://mosquitto.org/download/
# Restore NuGet packages
dotnet restore
# Build the application
dotnet build
# Run the application
dotnet run
# Application will be available at:
# - HTTP: http://localhost:5000
# - HTTPS: https://localhost:5001
# - API Documentation: http://localhost:5000/api-docs
# Start all services (recommended for full experience)
docker-compose up -d
# View logs
docker-compose logs -f nexushome-app
# Stop all services
docker-compose down
- Web Interface: Navigate to
http://localhost:5000 - API Documentation: Visit
http://localhost:5000/api-docs - Health Check: Check
http://localhost:5000/health/ready - Grafana Dashboard: Access
http://localhost:3000(admin/NexusHome@2025!)
GET /api/devices \# Get all devices
GET /api/devices/{deviceId} \# Get specific device
POST /api/devices/{deviceId}/toggle \# Toggle device state
POST /api/devices/telemetry \# Submit device data
GET /api/devices/{deviceId}/energy \# Get energy consumption
GET /api/energy/consumption \# Total consumption data
GET /api/energy/cost \# Cost analysis
GET /api/energy/forecast \# Energy usage predictions
GET /api/automation/rules \# Get all automation rules
POST /api/automation/rules \# Create new rule
PUT /api/automation/rules/{id} \# Update rule
DELETE /api/automation/rules/{id} \# Delete rule
// Connect to device status hub
const connection = new signalR.HubConnectionBuilder()
.withUrl("/hubs/device-status")
.build();
// Subscribe to device updates
connection.invoke("JoinDeviceGroup", "smart-thermostat-01");
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (Blazor + React) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β API Gateway + Load Balancer β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Application Layer β
β βββ Controllers (REST API) β
β βββ SignalR Hubs (Real-time) β
β βββ Background Services β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Business Logic Layer β
β βββ Device Management β
β βββ Energy Analytics β
β βββ AI/ML Services β
β βββ Automation Engine β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Infrastructure Layer β
β βββ Data Access (EF Core) β
β βββ External APIs β
β βββ Message Queuing (MQTT) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Data Storage Layer β
β βββ SQL Server (Operational) β
β βββ InfluxDB (Time Series) β
β βββ Redis (Caching) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Database Configuration
ConnectionStrings__DefaultConnection="Server=localhost;Database=NexusHomeIoT;Trusted_Connection=true"
ConnectionStrings__Redis="localhost:6379"
# Security Settings
JwtAuthentication__SecretKey="your-secret-key-here"
JwtAuthentication__Issuer="NexusHome.IoT"
JwtAuthentication__Audience="NexusHome.Clients"
# MQTT Configuration
MqttBroker__Host="localhost"
MqttBroker__Port=1883
MqttBroker__Username="nexususer"
MqttBroker__Password="your-mqtt-password"
# External APIs
WeatherApi__ApiKey="your-openweather-api-key"
ConnectionStrings: Database and external service connectionsJwtAuthentication: JWT token configurationMqttBroker: MQTT broker settings and topic configurationEnergyOptimization: AI/ML model parametersSecuritySettings: Rate limiting and security policiesLogging: Structured logging configuration
# Run all tests
dotnet test
# Run with coverage
dotnet test --collect:"XPlat Code Coverage"
# Run specific test category
dotnet test --filter "Category=Integration"
# Using curl to test device endpoint
curl -X GET "http://localhost:5000/api/devices" \
-H "Accept: application/json"
# Submit device 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-10-06T20:45:00Z"
}'
# Install k6 for load testing
# Test API performance
k6 run --vus 10 --duration 30s scripts/load-test.js
- Application Health:
/health/ready- Application readiness - Database Health:
/health/live- Database connectivity - External Dependencies: MQTT, Redis, external APIs
- Structured Logging: Serilog with JSON formatting
- Metrics Collection: Prometheus-compatible endpoints
- Distributed Tracing: Built-in ASP.NET Core tracing
- Performance Counters: Real-time application metrics
- Grafana: System performance and business metrics
- Application Insights: Azure-based monitoring (optional)
- Custom Dashboards: Energy consumption and device analytics
# Local development with hot reload
dotnet watch run
# Docker development environment
docker-compose -f docker-compose.yml -f docker-compose.override.yml up
# Build production image
docker build -t nexushome-iot:latest .
# Run with production configuration
docker run -d -p 80:80 --name nexushome-prod \
--env-file .env.production \
nexushome-iot:latest
- Azure App Service: Direct deployment with Azure integration
- AWS ECS/Fargate: Container-based deployment
- Google Cloud Run: Serverless container deployment
- Kubernetes: Scalable orchestrated deployment
# Install Vercel CLI
npm i -g vercel
# Configure for .NET deployment
# Note: Vercel has limited .NET support, consider API-only deployment
vercel --prod
- JWT tokens with configurable expiration
- Role-based access control (RBAC)
- API key authentication for devices
- OAuth 2.0 integration support
- SQL injection protection via Entity Framework
- Input validation and sanitization
- HTTPS enforcement in production
- Secure password hashing (BCrypt)
- CORS configuration for web access
- Rate limiting to prevent abuse
- Security headers middleware
- IP whitelisting support
- Device certificate authentication
- Encrypted MQTT communication
- Device provisioning and lifecycle management
- Regular security updates and patches
- C# Coding Conventions: Microsoft C# coding standards
- API Design: RESTful principles with OpenAPI documentation
- Database Design: Normalized schema with proper indexing
- Error Handling: Comprehensive exception handling and logging
- Clean Architecture: Separation of concerns with dependency inversion
- Repository Pattern: Data access abstraction
- CQRS: Command Query Responsibility Segregation for complex operations
- Event-Driven: Asynchronous processing with background services
- Async/Await: Non-blocking I/O operations
- Caching Strategy: Multi-level caching with Redis
- Database Optimization: Query optimization and connection pooling
- Resource Management: Proper disposal and memory management
We welcome contributions to the NexusHome IoT Platform! Please read our contributing guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Install development dependencies
dotnet tool restore
# Run pre-commit hooks
dotnet format --verify-no-changes
dotnet test
# Update documentation
# Update CHANGELOG.md with your changes
- All submissions require review approval
- Automated tests must pass
- Code coverage should not decrease
- Follow established coding standards
This project is licensed under the MIT License - see the LICENSE file for details.
- 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 the amazing libraries and tools
- API Documentation: Available at
/api-docswhen running - Architecture Docs: See
/docsdirectory - Deployment Guides: Platform-specific deployment instructions
- GitHub Issues: Bug reports and feature requests
- GitHub Discussions: Community Q&A and discussions
- Stack Overflow: Tag questions with
nexushome-iot
- Email: [email protected]
- LinkedIn: Aaron Sequeira
- GitHub: @aaronseq12
- Voice control integration (Alexa, Google Assistant)
- Mobile app (React Native/Flutter)
- Advanced AI models for energy prediction
- Multi-tenant architecture support
- Edge computing support
- Blockchain-based device identity
- Advanced solar panel integration
- Community energy sharing features
- Global smart grid integration
- Carbon footprint tracking
- Advanced weather correlation
- Machine learning model marketplace
Happy Coding!
Built with β€οΈ by Aaron Sequeira and the NexusHome community
Now let me provide you with the essential startup commands:
## **How to Run Locally - Step by Step**
1. **Update your project files** with the code I provided above
2. **Install prerequisites**:
```bash
# Install .NET 8 SDK (if not already installed)
# Download from: https://dotnet.microsoft.com/download/dotnet/8.0
# Verify installation
dotnet --version
- Create the directory structure:
mkdir -p Core/Domain Core/Services/Interfaces
mkdir -p Infrastructure/Data Infrastructure/Services Infrastructure/Configuration
mkdir -p Application/Hubs Application/DTOs
mkdir -p API/Controllers API/Middleware
mkdir -p Configuration Scripts- Database setup (Choose one option):
Option A - SQL Server Express (Recommended):
# Install Entity Framework tools
dotnet tool install --global dotnet-ef
# Create migration
dotnet ef migrations add InitialCreate
# Update database
dotnet ef database updateOption B - Docker SQL Server:
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=NexusHome@2025!" \
-p 1433:1433 --name nexus-sqlserver -d \
mcr.microsoft.com/mssql/server:2022-latest- Run the application:
# Restore packages
dotnet restore
# Build the project
dotnet build
# Run in development mode
dotnet run- Access the application:
- Main App: http://localhost:5000
- API Docs: http://localhost:5000/api-docs
- Health Check: http://localhost:5000/health/ready
The application will start with demo data and you can begin testing the APIs immediately!