### Install protoc and Compile ESPHome API .proto Files Source: https://github.com/twocolors/esphome-native-api/blob/main/lib/protoc/README.md This snippet provides a sequence of bash commands to install the Protocol Buffers compiler (`protoc`), verify its version, download the official ESPHome API `.proto` definition files from GitHub, and then compile these definitions into JavaScript files using the commonjs import style. ```bash $ npm install -g protoc $ protoc --version libprotoc 3.20.3 $ wget -c https://raw.githubusercontent.com/esphome/aioesphomeapi/main/aioesphomeapi/api_options.proto $ wget -c https://raw.githubusercontent.com/esphome/aioesphomeapi/main/aioesphomeapi/api.proto $ protoc --js_out=import_style=commonjs:. api_options.proto api.proto ``` -------------------------------- ### Install ESPHome Native API Client Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md This command installs the `@2colors/esphome-native-api` library using npm, making it available for use in Node.js projects. ```bash $ npm i @2colors/esphome-native-api ``` -------------------------------- ### Initialize ESPHome Native API Client in JavaScript Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md This snippet demonstrates how to create and configure a new instance of the `Client` class from the `@2colors/esphome-native-api` library. It shows an example of the various optional parameters available for customizing connection behavior, initialization steps, and logging preferences. ```javascript const { Client } = require('@2colors/esphome-native-api'); const client = new Client({ clearSession = false, initializeDeviceInfo = true, initializeListEntities = true, initializeSubscribeStates = true, initializeSubscribeLogs = false, initializeSubscribeBLEAdvertisements = false, port = 6053, host, clientInfo = 'esphomenativeapi', encryptionKey = '', password = '', // Deprecated reconnect = true, reconnectInterval = 30000, pingInterval = 15000, pingAttempts = 3 }); ``` -------------------------------- ### Discover ESPHome Devices (Event-based) Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md This JavaScript example demonstrates event-driven discovery of ESPHome devices. It instantiates `Discovery`, attaches a listener for 'info' events to log each discovered device, and then initiates the discovery process. This allows for continuous monitoring of device presence. ```javascript const { Discovery } = require('@2colors/esphome-native-api'); const discovery = new Discovery(); discovery.on('info', console.log); /* { port: 6053, network: 'wifi', board: 'esp01_1m', platform: 'ESP8266', mac: 'c82b965b4153', version: '2023.11.4', host: 'bathroom-light.local', address: '192.168.0.119' } */ discovery.run(); ``` -------------------------------- ### ESPHome Native API Client Constructor Parameters Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Detailed documentation of the `Client` class constructor parameters, including their types, default values, and descriptions. This section covers connection settings, initialization flags, and authentication options. ```APIDOC Client constructor parameters: host: string (REQUIRED) - Host or IP address to connect to. port: number (optional, default: 6053) - Port to connect to. encryptionKey: string (optional, default: '') - The pre-shared key for encryption. This is a 32-byte base64 encoded string. password: string (optional, default: '') - Password used to authorize the client. (Deprecated: It is recommended to use the encryptionKey). reconnect: boolean (optional, default: true) - Indicates whether to reconnect automatically or not. reconnectInterval: number (optional, default: 30000) - Amount of milliseconds to wait before a new reconnection attempt. clearSession: boolean (optional, default: true) - Set to 'true' to forget any information after reconnection. initializeDeviceInfo: boolean (optional, default: true) - Set to 'true' to retrieve device info after connection is established. initializeListEntities: boolean (optional, default: true) - Set to 'true' to retrieve a list of device's entities after connection is established. initializeSubscribeStates: boolean (optional, default: true) - Set to 'true' to subscribe to entity state updates. initializeSubscribeLogs: boolean (optional, default: false) - Set to 'true' to subscribe to device logs. initializeSubscribeBLEAdvertisements: boolean (optional, default: false) - Set to 'true' to subscribe to BLE advertisements. clientInfo: string (optional, default: 'esphomenativeapi') - Name of the client to be sent to the ESPHome device. Useful for debugging and tracking connections. pingInterval: number (optional, default: 15000) - Ping interval in milliseconds. pingAttempts: number (optional, default: 3) - Number of failed ping attempts after which the connection is considered corrupted. ``` -------------------------------- ### JavaScript ESPHome Connection Instantiation Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Demonstrates how to create a new `Connection` instance using the `@2colors/esphome-native-api` library in JavaScript. This snippet shows the basic structure for initializing a connection with various configurable parameters. ```javascript const { Connection } = require('@2colors/esphome-native-api'); const connection = new Connection({ port = 6053, host, clientInfo = 'esphomenativeapi', encryptionKey = '', password = '', // Deprecated reconnect = true, reconnectInterval = 30000, pingInterval = 15000, pingAttempts = 3 }); ``` -------------------------------- ### ESPHome Connection Class API Reference Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Comprehensive API documentation for the `Connection` class, detailing its constructor parameters, attributes, and various methods for interacting with ESPHome devices. This includes connection management, device information retrieval, entity state subscriptions, log subscriptions, camera image requests, and Bluetooth functionalities. ```APIDOC Connection Class: Constructor: new Connection(options: object): Description: Initializes a new connection to an ESPHome device. Parameters: host: REQUIRED. string. Hostname or IP address of the ESPHome device. port: optional. number. Default: 6053. Port to connect to. encryptionKey: optional. string. Default: ''. The pre-shared 32-byte base64 encoded key for encryption. password: optional. string. Default: ''. Deprecated. Password for client authorization. Encryption key is recommended. reconnect: optional. boolean. Default: true. Whether to automatically reconnect on disconnection. reconnectInterval: optional. number. Default: 30000. Milliseconds to wait before a reconnection attempt. clientInfo: optional. string. Name of the client to send to the ESPHome device for tracking/debugging. pingInterval: optional. number. Default: 15000. Milliseconds between ping attempts to keep the connection alive. pingAttempts: optional. number. Default: 3. Number of failed pings before the connection is considered corrupted. Attributes: connected: boolean. True if the client is successfully introduced to the ESPHome device. authorized: boolean. True if the client is successfully logged in to the ESPHome device. Methods: connect(): void Description: Initiates a connection attempt to the ESPHome device. disconnect(): void Description: Closes the active connection. async deviceInfoService(): object Description: Subscribes to and returns device information. async getTimeService(): object Description: Subscribes to and returns the current time from the device. async listEntitiesService(): array Description: Subscribes to and returns a list of all entities on the device. subscribeStatesService(): void Description: Subscribes to real-time state changes of entities. subscribeLogsService(level = 5, dumpConfig = false): void Description: Subscribes to logs from the ESPHome device. Parameters: level: number. Default: 5. Log level filter. (0: NONE, 1: ERROR, 2: WARN, 3: INFO, 4: DEBUG, 5: DEBUG, 6: VERBOSE, 7: VERY_VERBOSE). dumpConfig: boolean. cameraImageService(single = true, stream = false): void Description: Requests camera images from the device. Parameters: single: boolean. Default: true. Request a single image. stream: boolean. Default: false. Request a continuous stream of images. subscribeBluetoothAdvertisementService(): void Description: Subscribes to Bluetooth advertisement state changes. unsubscribeBluetoothAdvertisementService(): void Description: Unsubscribes from Bluetooth advertisement state changes. async connectBluetoothDeviceService(address: int): void Description: Connects to a connectable BLE device. Parameters: address: int. The address of the BLE device. async disconnectBluetoothDeviceService(address: int): void Description: Disconnects from a connected BLE device. Parameters: address: int. The address of the BLE device. async listBluetoothGATTServicesService(address: int): array Description: MUST be connected to the BLE device. Lists GATT services of the connected BLE device. Parameters: address: int. The address of the BLE device. async readBluetoothGATTCharacteristicService(address: int, handle: any): any Description: MUST be connected to the BLE device. Reads a GATT Characteristic service. Parameters: address: int. The address of the BLE device. handle: The handle of the GATT characteristic. async writeBluetoothGATTCharacteristicService(address: int, handle: any, someUint8Array: Uint8Array, response = false): void Description: MUST be connected to the BLE device. Writes to a GATT Characteristic. Parameters: address: int. The address of the BLE device. handle: The handle of the GATT characteristic. someUint8Array: Uint8Array. The data to write. response: boolean. Default: false. async notifyBluetoothGATTCharacteristicService(address: int, handle: any): void Description: MUST be connected to the BLE device. Enables notifications for a GATT Characteristic. Parameters: address: int. The address of the BLE device. handle: The handle of the GATT characteristic. async readBluetoothGATTDescriptorService(address: int, handle: any): any Description: MUST be connected to the BLE device. Reads a GATT Descriptor. Parameters: address: int. The address of the BLE device. handle: The handle of the GATT descriptor. async writeBluetoothGATTDescriptorService(address: int, handle: any, someUint8Array: Uint8Array): void Description: MUST be connected to the BLE device. Writes to a GATT Descriptor. Parameters: address: int. The address of the BLE device. handle: The handle of the GATT descriptor. someUint8Array: Uint8Array. The data to write. CommandService(data: object): void Description: Sends a command to a specific entity type. See `static commandService` in Entity classes for general usage. Specific Command Services (examples): buttonCommandService(data) climateCommandService(data) coverCommandService(data) fanCommandService(data) lightCommandService(data) lockCommandService(data) numberCommandService(data) textCommandService(data) selectCommandService(data) sirenCommandService(data) switchCommandService(data) mediaplayerCommandService(data) ``` -------------------------------- ### Connect to ESPHome Device and Manage Entities Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md This JavaScript code demonstrates how to connect to an ESPHome device using the `Client` class, retrieve device information, and listen for new entities. It also shows how to control a light entity and monitor entity state changes. Configuration options include host, port, encryption key, and password. ```javascript const { Client } = require('@2colors/esphome-native-api'); const client = new Client({ host: '', port: 6053, // encryptionKey: '', // Use encryption key // password: '', // Insert password if you have any (Deprecated) }); client.connect(); client.on('deviceInfo', deviceInfo => { console.log('Device info:', deviceInfo); }); client.on('newEntity', entity => { console.log('New entity:', entity); // enable light if (entity.type === 'Light') { entity.setState(true); } // show state entity.on('state', (state) => console.log(state)); }); client.on('error', (error) => console.log(error)); ``` -------------------------------- ### Discovery Class Constructor API Reference Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md This section details the constructor for the `Discovery` class, which allows for configuring the mDNS discovery process. It lists various optional parameters for network interface, port, IP, TTL, loopback, and reuseAddr settings, influencing how the discovery service operates. ```APIDOC Discovery: __init__(options: object = optional) options: object (optional) multicast: boolean (optional, default: true) - Use UDP multicasting. interface: string (optional) - Explicitly specify a network interface. Defaults to all. port: number (optional, default: 5353) - Set the UDP port. ip: string (optional, default: '224.0.0.251') - Set the UDP IP. ttl: number (optional, default: 255) - Set the multicast TTL. loopback: boolean (optional, default: true) - Receive your own packets. reuseAddr: boolean (optional, default: true) - Set the reuseAddr option when creating the socket (requires Node.js >=0.11.13). bind: string (optional) - For work with `interface` (see link for more details). ``` -------------------------------- ### Discover ESPHome Devices (Promise-based) Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md This JavaScript snippet uses the `Discovery` function to find ESPHome devices on the network. It returns a promise that resolves with an array of discovered device information, including port, network, board, platform, MAC address, version, host, and IP address. ```javascript const { Discovery } = require('@2colors/esphome-native-api'); Discovery().then(results => { console.log(results); /* [ { port: 6053, network: 'wifi', board: 'esp01_1m', platform: 'ESP8266', mac: 'c82b965b4153', version: '2023.11.4', host: 'bathroom-light.local', address: '192.168.0.119' } ] */ }); ``` -------------------------------- ### ESPHome Native API Client Methods and Attributes Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Overview of the `Client` class's public methods and attributes, providing functionality for connecting, disconnecting, and checking connection/initialization status, as well as accessing discovered entities and the underlying connection instance. ```APIDOC Client methods: connect(): void - Starts the client connection process. disconnect(): void - Stops the client connection. Client attributes: connected: boolean - Indicates if the client is currently connected to ESPHome and authorized. initialized: boolean - Indicates if the client is connected, authorized, and all initialization steps (e.g., device info, entity list) are completed. entities: Array - An array of discovered entities. connection: Connection - The underlying connection instance. ``` -------------------------------- ### Subscribe to ESPHome Device Logs Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md This JavaScript code shows how to enable and receive logs from an ESPHome device. By setting `initializeSubscribeLogs` to `true` in the `Client` constructor, the client will subscribe to log messages, which can then be processed via the 'logs' event. ```javascript const { Client } = require('@2colors/esphome-native-api'); const client = new Client({ host: '', port: 6053, initializeSubscribeLogs: true }); client.on('logs', ({ message }) => { console.log(message); }); ``` -------------------------------- ### ESPHome Native API Client Events Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Documentation of events emitted by the `Client` instance, allowing applications to react to connection status changes, initialization completion, device information updates, new entity discoveries, logs, BLE advertisements, and errors. ```APIDOC Client events: 'connected': Emitted when the client successfully connects to ESPHome and is authorized. 'disconnected': Emitted when the connection is corrupted or intentionally closed. 'initialized': Emitted when the client is connected, authorized, and all initialization steps are done. 'deviceInfo': Emitted when device information is retrieved or updated. Activated with the 'initializeDeviceInfo' option. (Payload: object) 'newEntity': Emitted when a new entity is discovered. Activated with the 'initializeListEntities' option. (Payload: instance of an Entity class) 'logs': Emitted when ESPHome sends any logs. Activated with the 'initializeSubscribeLogs' option. (Payload: { level: string, tag: string, message: string, send_failed: boolean }) 'ble': Emitted when ESPHome sends any BLE Advertisements. Activated with the 'initializeSubscribeBLEAdvertisements' option. (Payload: { address: string, name: string, rssi: number, serviceUuidsList: Array, serviceDataList: Array, manufacturerDataList: Array, addressType: string }) 'error': Emitted when any error occurs during client operation. (Payload: Error object) ``` -------------------------------- ### ESPHome Native API Button Entity Methods Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Documents the static `commandService` method specific to the Button entity, used for sending commands to button components. ```APIDOC Button Entity methods: static commandService(connection: Connection, options: { key: string }): void connection: The connection instance. options: key: string (REQUIRED) - The key/ID of the button entity to command. ``` -------------------------------- ### Text Entity Command Service API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Documents the `static commandService` method used to send commands to a text entity on an ESPHome device. It requires a connection object and an object specifying the entity's key and the new state. ```APIDOC commandService(connection, { key, state }): Description: Sends command to text entity. Parameters: connection: The active connection object. key: REQUIRED. Key/ID of the text entity. state: REQUIRED. string. The new state for the text entity. Refer to `minLength` and `maxLength` attributes in config. ``` -------------------------------- ### ESPHome Native API Connection Events Reference Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md This section details the various events emitted by the ESPHome Native API client, providing insights into connection status, message handling, and authorization states. Each event is triggered under specific conditions, allowing developers to react to changes in the device's communication lifecycle. ```APIDOC message.: - description: Triggered when a valid message of a specific type is received from the ESPHome device. The first argument is the message content. This event is called before the more general 'message' event. reconnect: - description: Emitted when the client successfully reconnects to the ESPHome device after a disconnection. message: - description: Triggered when any valid message is received from the ESPHome device. The first argument is the message type, and the second is the message content. connected: - description: Emitted when the client successfully establishes an initial connection and is introduced to the ESPHome device. disconnected: - description: Emitted when the session with the ESPHome device is corrupted or terminated unexpectedly. authorized: - description: Emitted when the client successfully logs in and is authorized by the ESPHome device. unauthorized: - description: Emitted when the session is corrupted or the client fails to log in/is unauthorized. data: - description: Triggered when any raw data is received from the ESPHome device, regardless of its validity or parsing status. error: - description: Triggered when any error occurs during communication or processing with the ESPHome device. unhandledData: - description: Triggered when data is received but an error occurred during processing, leaving unprocessed data. ``` -------------------------------- ### Send Cover Command via ESPHome Native API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Sends control commands to an ESPHome cover entity, enabling operations like opening, closing, stopping, and setting specific positions or tilts. This service provides granular control over blinds, curtains, and other cover devices. ```APIDOC Cover Command Service: static commandService(connection, { key, legacyCommand, position, tilt, stop }) connection: The connection object to the ESPHome device. key: REQUIRED. key/id of entity legacyCommand: optional. 0 - OPEN, 1 - CLOSE, 2 - STOP. Deprecated: use `position` position: optional. float. 0.0 - CLOSED, 1.0 - OPEN. See `supportsPosition` attr in config tilt: optional. float. 0.0 - CLOSED, 1.0 - OPEN. See `supportsTilt` attr in config stop: optional. boolean ``` -------------------------------- ### Discovery Promise Function API Reference Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md This section describes the `Discovery` function when used in a promise-based manner. It accepts an optional `options` object, which can include a `timeout` parameter to specify how long to wait for discovery responses, along with all other options available to the `Discovery` constructor. ```APIDOC Discovery: (options: object = optional) -> Promise options: object (optional) timeout: number (optional, default: 5) - Time in seconds how long to wait for responses. ...: all options from Discovery constructor ``` -------------------------------- ### Send Light Command via ESPHome Native API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Sends control commands to an ESPHome light entity, enabling adjustments to state, brightness, color, color temperature, and effects. This service offers comprehensive control over various light attributes. ```APIDOC Light Command Service: static commandService(connection, { key, state, brightness, red, green, blue, colorMode, colorBrightness, white, colorTemperature, coldWhite, warmWhite, transitionLength, flashLength, effect }) connection: The connection object to the ESPHome device. key: REQUIRED. key/id of entity state: optional. boolean brightness: optional. float red: optional. integer 0-255 green: optional. integer 0-255 blue: optional. integer 0-255 colorMode: optional. integer. See `supportedColorModesList` attr in config colorBrightness: optional. float white: optional. integer 0-255 colorTemperature: optional. integer coldWhite: optional. float warmWhite: optional. float flashLength: optional. integer effect: optional. string. effect from effects array in config list ``` -------------------------------- ### Send Switch Command via ESPHome Native API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Sends a state command to an ESPHome switch entity, toggling its on/off state. This service is used for basic binary control of devices. ```APIDOC Switch Command Service: static commandService(connection, { key, state }) connection: The connection object to the ESPHome device. key: REQUIRED. key/id of entity state: REQUIRED. boolean ``` -------------------------------- ### ESPHome Native API Base Entity Properties and Events Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Describes the common attributes and events shared by all entity classes in the ESPHome Native API, providing a consistent interface for interacting with various components. ```APIDOC Base Entity properties: config: object - The entity's configuration received from ESPHome. state: any - The current state of the entity. type: string - The type of the component (e.g., 'binary_sensor', 'button'). name: string - The name of the entity. Base Entity events: 'state': Emitted when a new state is received for the entity. 'destroyed': Emitted when the corresponding client is no longer connected to this entity (e.g., due to the 'clearSession' option). ``` -------------------------------- ### Send Media Player Command via ESPHome Native API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Sends control commands to an ESPHome media player entity, including play, pause, stop, mute, unmute, volume adjustment, and media URL playback. This service enables remote control of audio/video devices. ```APIDOC Media Player Command Service: static commandService(connection, { key, command, volume, mediaUrl }) connection: The connection object to the ESPHome device. key: REQUIRED. key/id of entity command: REQUIRED. 0 - MEDIA_PLAYER_COMMAND_PLAY, 1 - MEDIA_PLAYER_COMMAND_PAUSE, 2 - MEDIA_PLAYER_COMMAND_STOP, 3 - MEDIA_PLAYER_COMMAND_MUTE, 4 - MEDIA_PLAYER_COMMAND_UNMUTE volume: optional. float mediaUrl: optional. string ``` -------------------------------- ### Send Climate Command via ESPHome Native API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Sends various control commands to an ESPHome climate entity, allowing adjustment of mode, temperature, fan, swing, and presets. This service enables comprehensive management of climate control devices. ```APIDOC Climate Command Service: static commandService(connection, { key, mode, targetTemperature, targetTemperatureLow, targetTemperatureHigh, legacyAway, fanMode, swingMode, customFanMode, preset, customPreset }) connection: The connection object to the ESPHome device. key: REQUIRED. key/id of entity mode: optional. 0 - OFF, 1 - AUTO, 2 - COOL, 3 - HEAT, 4 - FAN_ONLY, 5 - DRY. See `supportedModesList` attr in config targetTemperature: optional. float targetTemperatureLow: optional. float targetTemperatureHigh: optional. float legacyAway: optional. Boolean. Deprecated: use `preset` with AWAY fanMode: optional. 0 - ON, 1 - OFF, 2 - AUTO, 3 - LOW, 4 - MEDIUM, 5 - HIGH, 6 - MIDDLE, 7 - FOCUS, 8 - DIFFUSE, 9 - QUIET. See `supportedFanModesList` attr in config swingMode: optional. 0 - OFF, 1 - BOTH, 2 - VERTICAL, 3 - HORIZONTAL. See `supportedSwingModesList` attr in config customFanMode: optional. string. See `supportedCustomFanModesList` attr in config preset: optional. 0 - NONE, 1 - HOME, 2 - AWAY, 3 - BOOST, 4 - COMFORT, 5 - ECO, 6 - SLEEP, 7 - ACTIVITY. See `supportedPresetsList` attr in config customPreset: optional. string. See `supportedCustomPresetsList` attr in config ``` -------------------------------- ### Send Select Command via ESPHome Native API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Sends a state command to an ESPHome select entity, setting its value to one of the predefined options. This service is used for controlling entities with a discrete set of choices. ```APIDOC Select Command Service: static commandService(connection, { key, state }) connection: The connection object to the ESPHome device. key: REQUIRED. key/id of entity state: REQUIRED. string. See `optionsList` attr in config ``` -------------------------------- ### Send Lock Command via ESPHome Native API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Sends control commands to an ESPHome lock entity, allowing for locking, unlocking, or opening the lock, optionally with a code. This service provides secure management of smart locks. ```APIDOC Lock Command Service: static commandService(connection, { key, command, code }) connection: The connection object to the ESPHome device. key: REQUIRED. key/id of entity command: REQUIRED. 0 - UNLOCK, 1 - LOCK, 2 - OPEN code: optional. string. See `requiresCode` attr in config ``` -------------------------------- ### Send Number Command via ESPHome Native API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Sends a state command to an ESPHome number entity, setting its value within configured minimum, maximum, and step constraints. This service is used for controlling numerical inputs or outputs. ```APIDOC Number Command Service: static commandService(connection, { key, state }) connection: The connection object to the ESPHome device. key: REQUIRED. key/id of entity state: REQUIRED. float. See `minValue`, `maxValue`, and `step` attrs in config ``` -------------------------------- ### Send Fan Command via ESPHome Native API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Sends control commands to an ESPHome fan entity, allowing adjustment of state, speed, oscillation, direction, and speed level. This service enables remote management of fan functionalities. ```APIDOC Fan Command Service: static commandService(connection, { key, state, speed, oscillating, direction, speedLevel }) connection: The connection object to the ESPHome device. key: REQUIRED. key/id of entity state: optional. boolean speed: optional. 0 - LOW, 1 - MEDIUM, 2 - HIGH oscillating: optional. boolean direction: optional. 0 - FORWARD, 1 - REVERSE speedLevel: optional. integer. See `supportedSpeedLevels` attr in config ``` -------------------------------- ### Send Siren Command via ESPHome Native API Source: https://github.com/twocolors/esphome-native-api/blob/main/README.md Sends control commands to an ESPHome siren entity, allowing activation, tone selection, duration, and volume adjustment. This service provides remote control over alarm and notification devices. ```APIDOC Siren Command Service: static commandService(connection, { key, state, tone, duration, volume }) connection: The connection object to the ESPHome device. key: REQUIRED. key/id of entity state: REQUIRED. boolean tone: optional. string. See `tonesList` attr in config duration: optional. integer. See `supportsDuration` attr in config volume: optional. integer. See `supportsVolume` attr in config ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.