# Node-RED Contrib Symi

[![npm version](https://badge.fury.io/js/node-red-contrib-symi.svg)](https://badge.fury.io/js/node-red-contrib-symi)
[![npm downloads](https://img.shields.io/npm/dm/node-red-contrib-symi.svg)](https://www.npmjs.com/package/node-red-contrib-symi)

Node-RED nodes for smart home device communication with Home Assistant integration, supporting multiple protocols including HassKit, Clowire, Alive, LF and complete Symi protocols.

## Features

### 🔌 Dual Communication Support
- **TCP Network Communication**: For Ethernet-connected devices
- **Serial Communication**: RS485/RS232 support with full configuration options

### 🏠 Device Support
- **Climate Control**: Temperature, humidity, HVAC systems
- **Lighting**: Switches, dimmers, RGB controls
- **HVAC**: Air conditioning, heating systems
- **Curtains**: Motorized blinds and curtains
- **Heating**: Floor heating systems
- **Ventilation**: Fresh air systems
- **Scene Control**: Multi-device scene management
- **Panel Control**: Touch panel interfaces

### 📡 Protocol Support
- **CLOWIRE**: 9-byte frame protocol with CRC16 checksum
- **HASSKIT**: 8-byte frame protocol for climate control
- **ALIVE**: Heartbeat and keep-alive mechanism
- **LF**: Lightweight protocol for simple devices
- **SYMI (亖米)**: 15-byte frame protocol with comprehensive device support

## Installation

```bash
npm install node-red-contrib-symi
```

## Quick Start

1. **Install the package** in your Node-RED environment
2. **Restart Node-RED** to load the new nodes
3. **Find the nodes** in the "symi" category in the palette
4. **Configure communication**:
   - Drag a "symi config" node to configure TCP or Serial connection
   - Choose your communication method and set parameters
5. **Add devices**: Drag device nodes and link them to your config

## Configuration

### TCP Network Configuration
```
Host: 192.168.1.100
Port: 8666
```

### Serial Communication Configuration
```
Serial Port: /dev/ttyUSB0 (Linux) or COM1 (Windows)
Baud Rate: 9600, 19200, 38400, 115200
Data Bits: 5, 6, 7, 8
Stop Bits: 1, 2
Parity: None, Even, Odd
```

### Device Parameters
- **Device UID**: Unique identifier for each device (e.g., 1001, 2001)
- **Device Address**: Bus address for the device (1-255)
- **Device Channel**: Internal channel number for multi-channel devices

## Available Nodes

### Configuration Node
- **symi config**: Communication configuration (TCP/Serial)

### Device Nodes
- **climate board**: Climate control and monitoring
- **switch board**: Switch and relay control
- **light board**: Lighting control and dimming
- **hvac board**: HVAC system control
- **curtain board**: Curtain and blind control
- **heating board**: Floor heating control
- **ventilation board**: Fresh air system control
- **scene board**: Scene management
- **panel board**: Touch panel interface

## Protocol Details

### SYMI Protocol (亖米)
15-byte frame structure supporting:
- **0x01**: Light devices (on/off, dimming, color)
- **0x02**: Air conditioning (temperature, mode, fan speed)
- **0x03**: Curtains (open/close, position)
- **0x05**: Floor heating (temperature control)
- **0x06**: Fresh air systems (fan control, air quality)

### CLOWIRE Protocol
9-byte frame with CRC16 checksum for reliable communication.

### HASSKIT Protocol
8-byte frame optimized for Home Assistant integration.

## Examples

### Basic Switch Control
```javascript
// Configure TCP connection
{
  "connectionType": "tcp",
  "host": "192.168.1.100",
  "port": 8666
}

// Switch device
{
  "deviceUID": 1001,
  "deviceAddress": 1,
  "deviceChannel": 0,
  "protocol": "CLOWIRE"
}
```

### Serial RS485 Setup
```javascript
// Configure Serial connection
{
  "connectionType": "serial",
  "serialPort": "/dev/ttyUSB0",
  "baudRate": 9600,
  "dataBits": 8,
  "stopBits": 1,
  "parity": "none"
}
```

## Requirements

- **Node.js**: >= 14.0.0
- **Node-RED**: >= 3.0.0

## Dependencies

- `serialport`: Serial communication support
- `@serialport/parser-readline`: Serial data parsing
- `ws`: WebSocket communication
- `async-lock`: Asynchronous operation locking

## Changelog

### v2.2.0
- ✅ Added serial communication support (RS485/RS232)
- ✅ Dual communication mode (TCP + Serial)
- ✅ Complete serial configuration options
- ✅ Dynamic connection type switching
- ✅ Preserved all original protocol functionality
- ✅ Enhanced device configuration documentation

### v2.1.0
- Initial release with TCP communication
- Support for 5 protocols and 10 device types
- Home Assistant integration

## License

MIT

## Support

- **GitHub**: [https://github.com/symi-daguo/node-red-contrib-symi](https://github.com/symi-daguo/node-red-contrib-symi)
- **Issues**: [https://github.com/symi-daguo/node-red-contrib-symi/issues](https://github.com/symi-daguo/node-red-contrib-symi/issues)
