# 🏠 Homebridge Solar Monitor

A Homebridge plugin that scrapes real-time solar production data from e-SenZ and integrates with HomeKit via Pushover notifications.

## ✨ Features

- 🔄 **Real-time Data Scraping**: Scrapes live solar production data from e-SenZ website
- 📱 **Pushover Notifications**: Sends notifications to multiple users via Pushover
- 🏠 **HomeKit Integration**: Creates HomeKit accessories for solar monitoring
- ⏰ **Smart Scheduling**: Scrapes data hourly during solar hours (6 AM - 6:30 PM IST)
- 🚀 **Auto-installation**: Automatic dependency installation on Raspberry Pi

## 🚀 Quick Installation

### 1. Install Plugin
```bash
npm install -g homebridge-solar-monitor-ivk
```

### 2. Install Dependencies (Raspberry Pi)
```bash
# Navigate to plugin directory
cd /var/lib/homebridge/node_modules/homebridge-solar-monitor-ivk

# Run auto-installation script
chmod +x install_dependencies.sh
./install_dependencies.sh
```

### 3. Configure Homebridge
Add to your `config.json`:

```json
{
  "accessories": [
    {
      "accessory": "SolarMonitor",
      "name": "Solar Monitor",
      "username": "your_esenz_username",
      "password": "your_esenz_password",
      "pushover_token": "your_pushover_token",
      "pushover_users": ["user_key_1", "user_key_2"],
      "scrape_interval": 3600000
    }
  ]
}
```

### 4. Restart Homebridge
```bash
sudo systemctl restart homebridge
```

## 🔧 Configuration

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `accessory` | string | ✅ | Must be exactly `"SolarMonitor"` |
| `name` | string | ✅ | Display name for HomeKit |
| `username` | string | ✅ | e-SenZ login username |
| `password` | string | ✅ | e-SenZ login password |
| `pushover_token` | string | ✅ | Pushover app token |
| `pushover_users` | array | ✅ | Array of Pushover user keys |
| `scrape_interval` | number | ❌ | Scrape interval in ms (default: 1 hour) |

## 🐛 Troubleshooting

### ChromeDriver Issues
If you get "ChromeDriver not found" errors:

```bash
# Check if ChromeDriver is installed
chromedriver --version

# If not found, install manually
sudo apt-get install -y chromium-chromedriver
sudo ln -s /usr/bin/chromedriver /usr/local/bin/chromedriver
```

### Plugin Not Loading
1. Check accessory name is exactly `"SolarMonitor"` (no spaces)
2. Verify all required fields are present in config.json
3. Check Homebridge logs: `sudo journalctl -u homebridge -f`

### Python Dependencies
If Python modules are missing:

```bash
cd /var/lib/homebridge/node_modules/homebridge-solar-monitor-ivk
pip3 install -r requirements.txt
```

### SSL Certificate Issues
The plugin uses the correct e-SenZ URL: `https://esenz.co.in/esenzCustomerLoginV3.aspx`

## 📊 Data Scraped

The plugin scrapes the following solar production data:
- Current Power (W/kW)
- Today's Energy (kWh)
- Yesterday's Energy (kWh)
- Monthly Energy (kWh)
- Total Energy (kWh)
- Generation Factor (GF)
- Capacity Utilization Factor (CUF)
- Performance Ratio (PR)

## 🔔 Notifications

Pushover notifications are sent:
- When solar production starts (6 AM IST)
- When solar production ends (6:30 PM IST)
- On significant production changes
- On scraping errors

## 🏗️ Architecture

- **Homebridge Plugin**: Node.js plugin for HomeKit integration
- **Python Scraper**: Selenium-based web scraper for e-SenZ
- **ChromeDriver**: Headless browser automation
- **Pushover API**: Multi-user notification system

## 📝 Logs

- Plugin logs: Homebridge logs (`sudo journalctl -u homebridge -f`)
- Scraper logs: `solar_scraper.log` in plugin directory

## 🔄 Updates

To update the plugin:

```bash
npm update -g homebridge-solar-monitor-ivk
cd /var/lib/homebridge/node_modules/homebridge-solar-monitor-ivk
./install_dependencies.sh
sudo systemctl restart homebridge
```

## 📄 License

MIT License - see LICENSE file for details.

## 🤝 Support

For issues and support:
1. Check the troubleshooting section above
2. Review Homebridge logs
3. Check scraper logs in plugin directory
4. Verify e-SenZ credentials and website accessibility 