An intelligent Home Energy Management System (HEMS) that uses Artificial Neural Networks and Multi-Agent Reinforcement Learning to optimize electric vehicle charging and household energy consumption.
π― Overview
This project implements and evaluates four different models for integrating Plug-in Electric Vehicle (PEV) battery management into a smart home energy system. The system combines:
- Artificial Neural Networks (ANN) for electricity price prediction
- Multi-Agent Reinforcement Learning (MARL) for optimal decision making
- Real-world data integration from Nordic electricity markets and EV usage patterns
π Problem Statement
Electric vehicles are becoming increasingly popular, but their charging patterns can significantly impact household energy costs and grid stability. This project addresses:
- Peak demand issues when EVs charge simultaneously after work hours
- High electricity costs during peak pricing periods
- Grid stability concerns from uncoordinated charging
- User convenience vs. energy cost optimization trade-offs
π§ Technical Approach
System Architecture
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Price Data βββββΆβ Neural Network βββββΆβ Price Predictionβ
β (Nord Pool) β β (18 inputs) β β (24h ahead) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Device Agents ββββββ HEMS ββββββ Q-Learning β
β (EV, HVAC, etc.)β β Coordinator β β Optimizer β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
Core Components
Price Prediction Module (
ANN
)- 18 input features (time, weather, historical prices)
- Sigmoid activation function
- Levenberg-Marquardt training algorithm
Multi-Agent Decision System (
MARL
)- Independent Q-learning agents for each device
- Ξ΅-greedy exploration strategy
- Distributed optimization approach
Battery Management Models (4 implementations)
- Non-Shiftable, Shiftable, NaΓ―f, and Controllable approaches
π Models Implemented
1. Non-Shiftable Battery (NSL_Battery
)
Baseline model - Charges immediately when plugged in
- β Simple implementation
- β No cost optimization
- π― Reference point for comparisons
2. Shiftable Battery (SL_Battery
)
Time-shifting model - Delays charging to optimal windows
- β Significant cost savings (up to 1.99% improvement)
- β Reduces peak demand
- β Must charge continuously once started
- π§ Parameters:
k
(inconvenience cost),Tne
(charging duration)
3. NaΓ―f Battery (Naif_Battery
)
Greedy optimization - Charges during cheapest available hours
- β Best overall performance (up to 16.89% improvement)
- β Can split charging across multiple periods
- β Simple yet effective algorithm
- π§ Parameters:
deficit
(charge level target)
4. Controllable Battery (CL_Battery
)
Continuous optimization - Adjusts charging power dynamically
- β Maximum flexibility (up to 3.43% improvement)
- β Real-time adaptation
- β Most complex implementation
- π§ Parameters:
Ξ²
(satisfaction cost),action_number
(power levels)
π Performance Results
Scenario Analysis
The system was evaluated across three scenarios with different user priorities:
Scenario | Cost Focus | Comfort Focus | Best Model | Improvement |
---|---|---|---|---|
Ο = 0.3 | 70% | 30% | NaΓ―f_Battery.2 | 16.89% |
Ο = 0.5 | 50% | 50% | NaΓ―f_Battery.0 | 10.76% |
Ο = 0.8 | 20% | 80% | NaΓ―f_Battery.0 | 4.30% |
Key Findings
- NaΓ―f Battery models consistently outperformed complex RL approaches
- Flexibility beats optimization - ability to split charging sessions was crucial
- Context matters - optimal strategy depends on user priorities
- Diminishing returns - simple heuristics often sufficient
π§ Implementation Details
Device Classes
Each battery model inherits from base classes with specific behaviors:
class SL_Battery(Shiftable_load):
def function(self):
# Q-learning training loop
for episode in range(loops):
# Simulate charging scenarios
# Update Q-table based on rewards
# Execute optimal action
return energy_consumed, utility_cost
Q-Learning Implementation
# Q-value update rule
Q[state][action] = Q[state][action] + learning_rate * (
reward + discount_factor * max(Q[next_state]) - Q[state][action]
)
Reward Function
Balances cost optimization with user satisfaction:
def get_reward(self, price_index, start_time, energy_consumed):
cost_component = (1-p) * price[price_index] * energy_consumed
satisfaction_component = p * (k * (start_time - preferred_time))
return 1 / (cost_component + satisfaction_component + epsilon)
π Data Sources
- Electricity Prices: Nord Pool (2013-2014)
- EV Usage Patterns: Test-An-EV Project
- Home Energy Data: SmartHG Project
π§ͺ Evaluation Metrics
The system evaluates performance using four key criteria:
- Ξ% Energy Cost - Total electricity cost reduction
- Ξ% Energy Consumed - Change in total energy consumption
- Ξ% Average Charging Price - Average cost per kWh charged
- Ξ% Average Final SOC - Battery charge level achieved
Overall Score: (1-Ο) Γ (cost_metrics) - Ο Γ (satisfaction_metrics)
π οΈ Customization
Adding New Battery Models
- Create a new class inheriting from appropriate base class
- Implement the
function()
method with your optimization logic - Add initialization in
insert_devices()
function - Configure parameters in the device list
Modifying Reward Functions
Customize the reward calculation to reflect different optimization objectives:
def custom_reward(self, price, energy, time_delay, battery_health):
return weighted_sum([
price_component(price, energy),
comfort_component(time_delay),
longevity_component(battery_health)
])
π Research Context
This implementation is based on the research paper:
Lu, Renzhi et al. βDemand Response for Home Energy Management Using Reinforcement Learning and Artificial Neural Networkβ IEEE Transactions on Smart Grid 10 (2019): 6629-6639.
Key Contributions:
- Extended original work to focus on EV integration
- Implemented four distinct battery management strategies
- Comparative analysis across multiple user preference scenarios
- Real-world data validation with Nordic electricity markets
π Academic Usage
This project was developed as a bachelorβs thesis in Computer Science at Sapienza University of Rome. If you use this work in academic research, please cite:
@mastersthesis{imperati2021hems,
title={Valutazione di un Home Energy Management System basato su Reinforcement Learning},
author={Imperati, Vincenzo},
year={2021},
school={Sapienza UniversitΓ di Roma},
type={Bachelor's thesis}
}
π¬ Future Enhancements
- Real-time Integration - Connect with actual smart home devices
- Weather Integration - Incorporate weather forecasting for better predictions
- Solar Panel Support - Add renewable energy generation optimization
- Vehicle-to-Grid (V2G) - Bidirectional energy flow capabilities
- Mobile App Interface - User-friendly control and monitoring
- Cloud Deployment - Scalable cloud-based implementation
π€ Contributing
Contributions are welcome! Areas for improvement:
- Algorithm Enhancements - New optimization strategies
- Real-world Testing - Hardware integration and validation
- User Interface - Better visualization and control tools
- Documentation - Code comments and usage examples
- Performance - Optimization for larger scale deployments
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π¨βπ» Author
Vincenzo Imperati
- π Computer Science Student, Sapienza University of Rome
- π¨βπ« Supervisor: Prof. Igor Melatti
π Acknowledgments
- Prof. Igor Melatti - Thesis supervisor and guidance
- Nord Pool - Historical electricity price data
- Test-An-EV Project - Real-world EV usage patterns
- SmartHG Project - Home energy consumption datasets
- IEEE Smart Grid Community - Research foundation and inspiration