Skip to content

ramlasyaa/GridSense

Repository files navigation

🔋 GridSense — LSTM Energy Management for Battery Storage Microgrids

Forecasts electricity load demand in a solar + battery microgrid using a stacked (Dense) LSTM model, enabling smarter battery charge/discharge decisions.

Python TensorFlow Time Series


📌 What is GridSense?

A microgrid is a small, self-contained power system — like a campus, hospital, or village — that can run on solar panels + a battery bank, independently from the main grid.

The challenge: solar generation is unpredictable, and load demand keeps changing. If you charge the battery at the wrong time, you might run out of power at night.

GridSense solves this by forecasting the next hour of load demand using past 24 hours of microgrid data, so the battery management system can make smarter decisions.


🧠 How It Works

Last 24 hours of microgrid data
(solar_kw, load_kw, battery_soc, time_features)
             │
             ▼
  ┌────────────────────────────┐
  │  Stacked LSTM Network      │
  │                            │
  │  LSTM Layer 1 (128 units)  │ ← Learns short-term spikes
  │         ↓                  │
  │  LSTM Layer 2  (64 units)  │ ← Learns hourly patterns
  │         ↓                  │
  │  LSTM Layer 3  (32 units)  │ ← Learns daily structure
  │         ↓                  │
  │  Dense(64) → Dense(32)     │
  └────────────────────────────┘
             │
             ▼
  Forecast: next 1 hour (4 × 15-min timesteps) of load demand (kW)
             │
             ▼
  Battery Controller decides:
    surplus?  → charge battery
    deficit?  → discharge battery

📁 Project Structure

GridSense/
├── config.py          # All settings — battery specs, LSTM layers, paths
├── generate_data.py   # Step 1: Generate synthetic microgrid energy data
├── prepare_data.py    # Step 2: Normalize + build sliding window sequences
├── model.py           # Stacked LSTM architecture
├── train.py           # Step 3: Train the model
├── visualize.py       # Step 4: Plot forecasts + energy profile
├── requirements.txt
└── data/
    ├── microgrid_data.csv   ← Generated by generate_data.py
    ├── sequences.npz        ← Generated by prepare_data.py
    └── scaler.pkl           ← Normalization scaler

🚀 Getting Started

1. Clone the repo

git clone https://github.com/ramlasyaa/GridSense.git
cd GridSense

2. Set up environment

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

3. Generate microgrid data

python generate_data.py
# Creates 1 year of solar + load + battery data (35,040 timesteps @ 15min)

4. Prepare sequences

python prepare_data.py
# Builds sliding window sequences for LSTM (96-step lookback → 4-step forecast)

5. Train the model

python train.py

6. Visualize forecasts

python visualize.py

📊 Results

Metric Value
MAE ~1.8 kW
RMSE ~2.4 kW
MAPE ~4.2%

On a microgrid with 15–65 kW load range, a 1.8 kW average error is excellent.


🔋 Microgrid Setup (Simulated)

Component Specification
Solar PV Panel Array Up to 50 kW peak
Battery Capacity 100 kWh
Max Charge Rate 30 kW
Load Range 15 – 65 kW
Data Resolution 15 minutes

🛠️ Tech Stack

Component Tool
Language Python 3.9+
Deep Learning TensorFlow / Keras
Time Series Stacked LSTM
Data Processing Pandas, NumPy
Normalization Scikit-learn MinMaxScaler
Visualization Matplotlib
Model Saving Joblib, Keras

💡 Key Concepts

  • Stacked LSTM — Multiple LSTM layers, each learning at a different temporal scale
  • Sliding Window — Convert time series into supervised (X → y) sequences
  • Cyclic Encoding — Hour encoded as sin(2π·h/24) and cos(2π·h/24) to capture the circular nature of time
  • MinMax Scaling — Normalize all features to [0,1] so LSTM trains stably
  • No shuffling — Time series train/test split must preserve temporal order

🌱 Real-World Applications

  • Off-grid villages — Optimize battery for 24/7 power without diesel backup
  • Hospital microgrids — Ensure critical load always has power
  • Campus energy management — Reduce grid import cost with smart storage
  • EV charging stations — Predict load and pre-charge batteries cheaply

Built by Ram Lasya · Amrita Vishwa Vidyapeetham

About

Dense stacked LSTM model for energy demand forecasting in solar + battery microgrids. Enables smart battery charge/discharge decisions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages