# ✅ Homebridge Oto Plugin - Setup Complete!

## Current Status
✅ Plugin installed globally and **running in Homebridge**  
✅ Homebridge is listening on port 51826  
✅ HomeKit pairing code: **031-45-154**

## What You Just Did
```bash
# Installed the plugin globally with npm link
npm install -g C:\Users\jonna\Development\homebridge-oto

# Homebridge found and loaded it automatically!
# [Homebridge] Loaded plugin: homebridge-oto@1.0.0
```

## Next Steps: Test with Real Oto Credentials

### Step 1: Update Your Homebridge Config
Edit: `C:\Users\jonna\.homebridge\config.json`

Replace the test credentials with your **actual Oto account details**:

```json
{
  "bridge": {
    "name": "Homebridge",
    "username": "CC:22:3D:E3:CE:30",
    "port": 51826,
    "pin": "031-45-154"
  },
  "platforms": [
    {
      "platform": "Oto",
      "name": "Oto Sprinklers",
      "email": "YOUR-OTO-EMAIL@example.com",
      "password": "YOUR-OTO-PASSWORD",
      "updateInterval": 30
    }
  ],
  "accessories": []
}
```

### Step 2: Start Homebridge
```bash
homebridge
```

Watch the logs for:
```
[Oto Sprinklers] Discovering Oto devices...
[Oto Sprinklers] Found X controller(s)
[Oto Sprinklers] Added accessory: Front Lawn Zone 1
[Oto Sprinklers] Added accessory: Front Lawn Zone 2
```

### Step 3: Pair with HomeKit
1. Open **HomeKit app** on your iPhone/iPad/Mac
2. Tap **+ Add** (top right)
3. Tap **Add Accessory**
4. **Scan the HomeKit code** (or enter `031-45-154`)
5. Enter **HomeKit setup code** when prompted
6. Assign rooms and zones
7. 🎉 **Done!** All your Oto zones appear as Valve accessories

## Testing Actions

Once paired, you can:

✅ **Turn on a zone** → Tap the valve in HomeKit → Zone starts watering  
✅ **Turn off a zone** → Tap again → Zone stops watering  
✅ **Set duration** → Hold the accessory → Adjust watering time (1-60 min)  
✅ **View status** → Real-time updates every 30 seconds  
✅ **Create automations** → Time-based, sensor-based, or manual triggers

## Troubleshooting

### "Failed to discover Oto devices"
- Check your email/password are correct
- Verify you can log in to the Oto mobile app
- Look for error details in Homebridge logs

### "No plugin was found for platform Oto"
```bash
# Reinstall the plugin
npm install -g C:\Users\jonna\Development\homebridge-oto
```

### Zones not appearing
- Ensure your Oto account has controllers and zones configured
- Check that controllers are online in the Oto mobile app
- Wait up to 30 seconds for first discovery

### HomeKit won't pair
- Make sure Homebridge is running
- Check the HomeKit code: `031-45-154`
- Try restarting Homebridge

## Development Mode

### Watch for changes
As you edit the source code, it auto-compiles:
```bash
npm run watch
```

### Rebuild manually
```bash
npm run build
```

### Restart Homebridge after changes
```
1. Press Ctrl+C to stop Homebridge
2. Run: homebridge
```

## Running Homebridge as a Service (Optional)

To run Homebridge in the background automatically:

**Windows (using NSSM):**
```bash
# Install NSSM (Node Simple Service Manager)
choco install nssm

# Create service
nssm install Homebridge homebridge --path C:\Users\jonna\.homebridge

# Start service
nssm start Homebridge

# View logs
nssm editlog Homebridge
```

## Config Reference

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `platform` | string | Required | Must be `"Oto"` |
| `email` | string | Required | Your Oto account email |
| `password` | string | Required | Your Oto account password |
| `apiBaseUrl` | string | `https://api.oto.com` | Oto API endpoint |
| `updateInterval` | number | 30 | Refresh interval in seconds (min: 10, max: 600) |

## Plugin Structure

```
homebridge-oto/
├── dist/                    # Compiled JavaScript (auto-generated)
├── src/
│   ├── index.ts            # Plugin entry point
│   ├── platform.ts         # Main platform plugin
│   ├── otoApi.ts           # Oto API client
│   ├── sprinklerAccessory.ts # HomeKit valve accessory
│   └── __tests__/          # Unit tests
├── config.schema.json      # HomeKit UI config schema
├── package.json            # Dependencies
└── tsconfig.json           # TypeScript config
```

## API Integration

The plugin communicates with the Oto API:

- **Endpoint**: `https://api.oto.com`
- **Auth**: OAuth Bearer token (auto-refreshed)
- **Rate limit**: 30-second polling interval
- **Timeout**: 10 seconds per request

## Need Help?

1. Check Homebridge logs: `homebridge` (console output)
2. Review `TESTING.md` for more details
3. Check GitHub issues: github.com/jonnadul/homebridge-oto

---

**You're all set!** 🚀 Your Oto sprinkler zones are now controllable from HomeKit!
