833 words
4 minutes
Home Energy Management System with Reinforcement Learning
VincenzoImp
/
bachelor-thesis
Waiting for api.github.com...
00K
0K
0K
Waiting...

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#

  1. Price Prediction Module (ANN)

    • 18 input features (time, weather, historical prices)
    • Sigmoid activation function
    • Levenberg-Marquardt training algorithm
  2. Multi-Agent Decision System (MARL)

    • Independent Q-learning agents for each device
    • Ξ΅-greedy exploration strategy
    • Distributed optimization approach
  3. 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:

ScenarioCost FocusComfort FocusBest ModelImprovement
ρ = 0.370%30%Naïf_Battery.216.89%
ρ = 0.550%50%Naïf_Battery.010.76%
ρ = 0.820%80%Naïf_Battery.04.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#

πŸ§ͺ Evaluation Metrics#

The system evaluates performance using four key criteria:

  1. Ξ”% Energy Cost - Total electricity cost reduction
  2. Ξ”% Energy Consumed - Change in total energy consumption
  3. Ξ”% Average Charging Price - Average cost per kWh charged
  4. Ξ”% Average Final SOC - Battery charge level achieved

Overall Score: (1-ρ) Γ— (cost_metrics) - ρ Γ— (satisfaction_metrics)

πŸ› οΈ Customization#

Adding New Battery Models#

  1. Create a new class inheriting from appropriate base class
  2. Implement the function() method with your optimization logic
  3. Add initialization in insert_devices() function
  4. 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:

  1. Algorithm Enhancements - New optimization strategies
  2. Real-world Testing - Hardware integration and validation
  3. User Interface - Better visualization and control tools
  4. Documentation - Code comments and usage examples
  5. 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
Home Energy Management System with Reinforcement Learning
https://vincenzo.imperati.dev/posts/bachelor-thesis/
Author
Vincenzo Imperati
Published at
2021-07-15