Energieverwaltung
- C# 95.5%
- PLpgSQL 3.4%
- Dockerfile 1.1%
Resolved conflicts: - README.md: Kept comprehensive local documentation |
||
|---|---|---|
| docker | ||
| src | ||
| tests | ||
| .dockerignore | ||
| .env.example | ||
| .gitignore | ||
| docker-compose.override.yml | ||
| docker-compose.yml | ||
| Dockerfile | ||
| EnergyControl.slnx | ||
| LICENSE | ||
| README.md | ||
EnergyControl - Energy Management System
A comprehensive C# .NET 9 solution for monitoring and analyzing energy consumption from multiple sources including FRITZ!Smart devices and energy supplier APIs.
Features
- Real-time Energy Monitoring: Collect live energy data from FRITZ!Box Smart Energy devices
- Historical Data Integration: Sync historical consumption data from energy suppliers (EKD)
- PostgreSQL + TimescaleDB: Optimized time-series data storage
- Command Line Interface: Full-featured CLI for device management and data collection
- Extensible Architecture: Plugin-based system for adding new data sources
- Docker Support: Complete containerized deployment
- Future-Ready: Prepared for AI predictions and additional UIs (Blazor, MAUI, React)
Architecture
src/
├── Core/
│ └── EnergyControl.Core/ # Domain models, interfaces
├── Infrastructure/
│ ├── EnergyControl.Data/ # Entity Framework, repositories
│ └── EnergyControl.Integrations/ # FRITZ!Box, EKD API clients
├── Services/
│ ├── EnergyControl.DataCollection/ # Background data collection
│ └── EnergyControl.Api/ # Web API (future)
└── UI/
├── EnergyControl.CLI/ # Command line interface
├── EnergyControl.Blazor/ # Web dashboard (future)
└── EnergyControl.Maui/ # Mobile app (future)
Quick Start with Docker
-
Clone and configure:
git clone <repository-url> cd EnergyControl cp .env.example .env # Edit .env with your FRITZ!Box and EKD credentials -
Start the system:
docker-compose up -d -
Initialize and discover devices:
docker-compose exec energycontrol-cli dotnet EnergyControl.CLI.dll device discover -
Start data collection:
docker-compose exec energycontrol-cli dotnet EnergyControl.CLI.dll collect start
CLI Commands
Device Management
# Discover FRITZ!Box energy devices
dotnet EnergyControl.CLI.dll device discover
# List all devices
dotnet EnergyControl.CLI.dll device list
# Show device status
dotnet EnergyControl.CLI.dll device status <device-name>
# Register device manually
dotnet EnergyControl.CLI.dll device register --name "Kitchen Outlet" --type "FRITZ!DECT 200" --mac "34:31:C4:XX:XX:XX"
Data Collection
# Start real-time collection for all devices
dotnet EnergyControl.CLI.dll collect start
# Collect single reading
dotnet EnergyControl.CLI.dll collect once <device-name>
# Test provider connections
dotnet EnergyControl.CLI.dll collect test-providers
Historical Data
# Sync historical data from EKD
dotnet EnergyControl.CLI.dll history sync --supplier EKD --from 2024-01-01
# Show energy history
dotnet EnergyControl.CLI.dll history show --device <device-name> --from 2024-01-01
# Export data to CSV
dotnet EnergyControl.CLI.dll history export --output energy_data.csv
System Status
# System health check
dotnet EnergyControl.CLI.dll status system
# Device statuses
dotnet EnergyControl.CLI.dll status devices
# Database status
dotnet EnergyControl.CLI.dll status database
Configuration
Configuration is managed through appsettings.json and environment variables:
{
"EnergyControl": {
"Database": {
"ConnectionString": "Host=localhost;Database=EnergyControl;Username=postgres;Password=energia123;"
},
"FritzBox": {
"BaseUrl": "https://fritz.box",
"Username": "your_username",
"Password": "your_password",
"PollingInterval": "00:00:30"
},
"Ekd": {
"ApiBaseUrl": "https://api.ekd.de",
"ApiToken": "your_token",
"CustomerNumber": "your_customer_number"
}
}
}
Development
Prerequisites
- .NET 9 SDK
- Docker and Docker Compose
- PostgreSQL (for local development)
Local Development
# Restore packages
dotnet restore
# Build solution
dotnet build
# Run CLI locally
cd src/UI/EnergyControl.CLI
dotnet run -- device list
# Run tests
dotnet test
# Create database migration
cd src/Infrastructure/EnergyControl.Data
dotnet ef migrations add <MigrationName>
Development with Docker
# Start development environment
docker-compose -f docker-compose.yml -f docker-compose.override.yml up -d
# View logs
docker-compose logs -f energycontrol-cli
# Access development CLI
docker-compose exec energycontrol-cli bash
Data Sources
FRITZ!Box Smart Energy Devices
- Supported: FRITZ!Smart Energy 250, FRITZ!DECT 200, FRITZ!DECT 210
- Data: Real-time power, voltage, current, temperature
- Authentication: FRITZ!Box challenge-response
- Discovery: Automatic via Smart Home API
Energy Supplier APIs (EKD)
- Data: Historical consumption, tariffs, billing
- Authentication: OAuth 2.0 with API tokens
- Sync: Configurable intervals (daily/weekly)
- Format: JSON REST API
Database Schema
Key Tables
Devices: Energy monitoring devicesEnergyReadings: Time-series energy measurements (hypertable)EnergySuppliers: Energy provider informationCustomerAccounts: Supplier account detailsHistoricalConsumptions: Supplier consumption data (hypertable)Tariffs: Energy pricing information
TimescaleDB Optimizations
- Hypertables for time-series data
- Automatic data compression (7+ days)
- Continuous aggregates (hourly/daily)
- Retention policies (2 years)
Monitoring & Admin
Included Tools
- pgAdmin: Database administration (http://localhost:8080)
- Grafana: Energy visualization (http://localhost:3000)
- Health Checks: System and component monitoring
Access Credentials
- pgAdmin:
admin@energycontrol.local/admin123 - Grafana:
admin/admin123
Extensibility
The system is designed for easy extension:
Adding New Data Sources
- Implement
IRealtimeEnergyProviderorIHistoricalEnergyProvider - Add configuration to
EnergyControlConfiguration - Register in DI container
- Create integration tests
Adding New UIs
- Create new project in
src/UI/ - Reference Core and Data projects
- Configure authentication and API endpoints
- Add to docker-compose for deployment
Future Roadmap
- Blazor Web Dashboard: Real-time energy monitoring web interface
- .NET MAUI Mobile App: Cross-platform mobile energy tracking
- React Frontend: Advanced data visualization and analytics
- AI/ML Predictions: Consumption forecasting and optimization
- Weather Integration: Correlate energy usage with weather data
- Solar Panel Integration: Track solar generation and grid feed-in
- Smart Home Automation: Energy-based device control
- Cost Optimization: Automated tariff analysis and recommendations
Contributing
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues and questions:
- Create GitHub Issues for bugs and feature requests
- Check existing documentation and CLI help
- Review logs in
/logsdirectory ordocker-compose logs
EnergyControl - Comprehensive energy management for the modern smart home.