# daikin-ts

A TypeScript library for controlling Daikin air conditioners over WiFi.

## Description

This is a TypeScript port of [pydaikin](https://github.com/fredrike/pydaikin), providing a type-safe way to interact with Daikin air conditioner units via their local WiFi interface.

## Supported Devices

- **BRP069** - Standard WiFi adapter
- **BRP072C** - WiFi adapter with HTTPS (requires API key)
- **BRP084** - Firmware 2.8.0+ adapters
- **AirBase** - Devices with zone support
- **SkyFi** - Legacy SkyFi devices

## Installation

```bash
npm install daikin-ts
```

## Usage

```typescript
import { DaikinFactory } from 'daikin-ts';

// For BRP072C devices (with API key)
const device = await DaikinFactory('192.168.1.100', { key: 'YOUR_API_KEY' });

// Or auto-detect device type
const device = await DaikinFactory('192.168.1.100');

// Get device status
console.log(`Power: ${device.values.get('pow')}`);
console.log(`Mode: ${device.values.get('mode')}`);
console.log(`Target Temp: ${device.targetTemperature}°C`);
console.log(`Inside Temp: ${device.insideTemperature}°C`);
console.log(`Outside Temp: ${device.outsideTemperature}°C`);

// Set control values
await device.set({
  mode: 'cool',
  stemp: '22.0',  // Use decimal format!
  f_rate: 'auto',
  f_dir: 'off',
});

// Advanced modes
await device.setAdvancedMode('powerful', 'on');
await device.setStreamer('on');

// Holiday mode
await device.setHoliday('on');
```

## API Key

For BRP072C devices, you'll need to get the API key from the device:
1. Remove the front grille from the indoor unit
2. The API key is printed on a sticker on the circuit board

## Temperature Format

When setting temperature, always use decimal format:

```typescript
// ✅ Correct
await device.set({ stemp: '22.0' });

// ❌ May not work
await device.set({ stemp: '22' });
```

## Test Scripts

The `scripts/` directory contains utility scripts for testing and controlling your Daikin device.

### Available Scripts

| Script | Description |
|--------|-------------|
| `device-status.ts` | View current device status |
| `restore-defaults.ts` | Restore device to default settings |
| `interactive.ts` | Interactive menu for testing controls |

### Usage

All scripts support CLI arguments or interactive prompts:

```bash
# Interactive mode (prompts for IP)
npx tsx scripts/device-status.ts

# With IP address
npx tsx scripts/device-status.ts --ip 192.168.1.100

# With IP and API key (for BRP072C)
npx tsx scripts/device-status.ts -i 192.168.1.100 -k YOUR_API_KEY

# With IP and password (for SkyFi)
npx tsx scripts/device-status.ts -i 192.168.1.100 -p YOUR_PASSWORD
```

### Interactive Control Menu

```bash
npx tsx scripts/interactive.ts --ip 192.168.1.100 -k YOUR_API_KEY
```

This provides a menu to test:
- View current status
- Basic control (on/off, mode, temperature)
- Fan rate test
- Fan direction test
- Advanced modes (powerful/econo)
- Streamer test
- Holiday mode
- Humidity control
- Restore defaults

### Disclaimer

These test scripts have been tested with BRP072C devices. Other device types (BRP069, BRP084, AirBase, SkyFi) should work but are untested due to lack of hardware.

## License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0).

This is a TypeScript port of [pydaikin](https://github.com/fredrike/pydaikin), which is also licensed under GPL-3.0.

## Links

- [npm package](https://npmjs.com/package/daikin-ts)
- [GitHub repository](https://github.com/leroylim/daikin-ts)
- [Issue tracker](https://github.com/leroylim/daikin-ts/issues)

## Related Projects

- [pydaikin](https://github.com/fredrike/pydaikin) - Python library (original)
- [daikin-control](https://github.com/ael-code/daikin-control) - Unofficial Daikin API documentation
