### Setup WiFi Configures the device to connect to a specified WiFi network. Success indicates the configuration was sent; confirm connection status using the Get Network Status interface. ```APIDOC ## POST /cgi-bin/api/v1/setWiFiSta ### Description Configures the device to connect to a specified WiFi network. ### Method POST ### Endpoint /cgi-bin/api/v1/setWiFiSta ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **ssid** (String) - ESSID of the target WiFi network. - **pwd** (String) - Password of the target WiFi network. - **authType** (String) - Encryption type of the WiFi network. ### Request Example ```json { "ssid": "MyWiFi", "pwd": "password123", "authType": "WPA2-PSK" } ``` ### Response #### Success Response (200) - **code** (String) - The error code; "000000" means success. #### Response Example ```json { "code": "000000" } ``` ``` -------------------------------- ### Setup WiFi Connection (HTTP) Configures the device to connect to a specified WiFi network. The request requires the network's SSID, password, and authentication type. Successful execution indicates the configuration was sent; actual network status should be confirmed using the Get Network Status interface. ```http POST /cgi-bin/api/v1/setWiFiSta Content-Type: application/json Body: ssid: String, ESSID of target WiFi network; pwd: String, Password of target WiFi network; authType: String, Encryption type of the WiFi network; ``` -------------------------------- ### Setup WiFi Configures the device to connect to a specified WiFi network using its SSID and password. ```APIDOC ## POST /api/v1/wifi/sta ### Description Configures the device to connect to a specified WiFi network. The success of this call only confirms that the configuration was sent; use the `Get Network Status` interface to verify the device's actual network connection status. ### Method POST ### Endpoint /api/v1/wifi/sta ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **ssid** (String) - Required. The SSID of the target WiFi network. - **pwd** (String) - Required. The password for the target WiFi network. ### Request Example ```json { "ssid": "MyWiFiNetwork", "pwd": "MyPassword123" } ``` ### Response #### Success Response (200) - **code** (String) - Status code, "000000" indicates success. #### Response Example ```json { "code": "000000" } ``` ``` -------------------------------- ### Get Network Status Retrieves the current network status, including IP address and SSID, and internet connectivity. ```APIDOC ## GET /api/v1/network/state ### Description Retrieves the current network status of the device, including the WiFi IP address, connected SSID, and internet connectivity status. ### Method GET ### Endpoint /api/v1/network/state ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` GET /api/v1/network/state ``` ### Response #### Success Response (200) - **code** (String) - Status code, "000000" indicates success. - **data.wifi.ip** (String, Optional) - The current IP address of the WiFi interface. Empty if not connected. - **data.wifi.ssid** (String, Optional) - The SSID of the currently connected WiFi network. - **data.internet** (Bool, Optional) - Indicates whether the device is connected to the internet. #### Response Example ```json { "code": "000000", "data": { "wifi": { "ip": "192.168.1.100", "ssid": "MyWiFiNetwork" }, "internet": true } } ``` ``` -------------------------------- ### Setup WiFi API (AP Mode V1) Configures the device's WiFi connection by sending the SSID and password. Success only confirms the configuration was sent; use Get Network Status to verify connection. Accessed via HTTP POST. ```HTTP POST /api/v1/wifi/sta Content-Type: application/json Body: ssid: String, SSID of target WiFi network; pwd: String, Password of target WiFi network; ``` -------------------------------- ### HTTP Callback Request Header Example Example of required headers for an HTTP callback request from YoSmart. Specifies Content-Type, KTT-CSID, and KTT-SEC for identifying the device and verifying the data. ```http POST _${Callback_URL}_ Content-Type: application/json KTT-CSID: ${CSID} KTT-SEC: MD5(Body.toString()+CSSecKey) ``` -------------------------------- ### Control YoSmart Devices with Device Token using Hub.getState This snippet shows how to control YoSmart devices, such as getting their state, using the device token obtained in the previous step. It details the API call format and provides example request and response JSON payloads for the Hub.getState method. ```JSON { "method":"Hub.getState", "time":${timestamp}, "targetDevice":"****4c160300****", "token":"****b642-781e-450f-ba86-df28bdea****", "params":{ } } ``` ```JSON { "code": "000000", "time": 1572354630744, "msgid": 1572354631, "method": "Hub.getState", "data": { "version": "0316", "wifi": { "ssid": "YoSmart", "enable": true, "ip": "192.168.1.164", "gateway": "192.168.1.1", "mask": "255.255.255.0" }, "eth": { "enable": false } } } ``` -------------------------------- ### HTTP POST Request Header Example Example of required headers for an HTTP POST request to the YoSmart API. Includes Content-Type, KTT-YS-BRAND, YS-CSID, and YS-SEC for authentication and data formatting. ```http POST /openApi Content-Type: application/json KTT-YS-BRAND: yolink YS-CSID: ${CSID} YS-SEC: MD5(Body.toString()+CSSecKey) ``` -------------------------------- ### ElectronicFence.startUpgrade Initiates the firmware upgrade process for the Electronic Fence device. Requires the version ID of the firmware to be installed. ```APIDOC ## POST ElectronicFence.startUpgrade ### Description Start the firmware upgrade process for the Electronic Fence device. ### Method POST ### Endpoint /api/device/ElectronicFence/startUpgrade ### Parameters #### Query Parameters - **method** (String) - Necessary - ElectronicFence.startUpgrade - **targetDevice** (String) - Necessary - DeviceId of this device - **token** (String) - Necessary - Net Token of this device #### Request Body - **params.versionId** (String) - Necessary - Version Id you want to upgrade ### Request Example ```json { "method": "ElectronicFence.startUpgrade", "targetDevice": "your_device_id", "token": "your_net_token", "params": { "versionId": "2" } } ``` ### Response #### Success Response (200) - **data.isStarted** (Boolean) - Is upgrading started #### Response Example ```json { "data": { "isStarted": true } } ``` ``` -------------------------------- ### Scan WiFi Networks Initiates a scan for available WiFi networks. This operation may take some time, so a timeout of at least 8 seconds is recommended. ```APIDOC ## GET /cgi-bin/api/v1/scan ### Description Scans for available WiFi networks. ### Method GET ### Endpoint /cgi-bin/api/v1/scan ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **code** (String) - The error code; "000000" means success. - **data** (Array) - Array of WiFi network details. - **ssid** (String) - ESSID of the WiFi network. - **bssid** (String) - BSSID of the WiFi network. - **authType** (String) - Encryption type of the WiFi network. Refer to 'Code Map Of WiFi Encryption' for details. - **rssi** (Integer) - Signal strength of the WiFi network. #### Response Example ```json { "code": "000000", "data": [ { "ssid": "MyWiFi", "bssid": "00:11:22:33:44:55", "authType": "WPA2-PSK", "rssi": -50 } ] } ``` ``` -------------------------------- ### ElectronicFence: Start Firmware Upgrade Initiates the firmware upgrade process for an electronic fence device. Requires the device ID, network token, and the specific version ID to upgrade to. The response indicates whether the upgrade process has started. ```API Call POST /api/v1/device/upgrade { "method": "ElectronicFence.startUpgrade", "targetDevice": "DEVICE_ID", "token": "NETWORK_TOKEN", "params": { "versionId": "VERSION_ID_TO_UPGRADE" } } ``` -------------------------------- ### Scan WiFi Networks Scans for available WiFi networks in the vicinity and returns their SSIDs and signal strengths. ```APIDOC ## GET /api/v1/wifi/scan ### Description Scans for available WiFi networks in the vicinity. Note that this operation may take some time; ensure a timeout greater than 8 seconds is set for the request. ### Method GET ### Endpoint /api/v1/wifi/scan ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` GET /api/v1/wifi/scan ``` ### Response #### Success Response (200) - **code** (String) - Status code, "000000" indicates success. - **data[*]** (Array) - An array of available WiFi networks. - **data[*].ssid** (String) - SSID of the WiFi network. - **data[*].rssi** (Integer) - Signal strength of the WiFi network. #### Response Example ```json { "code": "000000", "data": [ { "ssid": "HomeWiFi", "rssi": -55 }, { "ssid": "CoffeeShopWiFi", "rssi": -70 } ] } ``` ``` -------------------------------- ### Get Device List Retrieve a list of devices associated with your Local Hub using an access token. ```APIDOC ## POST /open/yolink/v2/api ### Description Retrieve a list of devices connected to your Local Hub. Requires an active access token. ### Method POST ### Endpoint `http://{Your Local Hub IP Address}:1080/open/yolink/v2/api` ### Parameters #### Request Body - **method** (string) - Required - Must be 'Home.getDeviceList'. ### Request Example ```json { "method": "Home.getDeviceList" } ``` ### Response #### Success Response (200) - **code** (string) - Response code, '000000' indicates success. - **time** (integer) - Timestamp of the response. - **msgid** (integer) - Message ID. - **method** (string) - The method called. - **desc** (string) - Description of the response. - **data** (object) - Contains device information: - **deviceId** (string) - Unique identifier for the device. - **name** (string) - The name of the device. - **token** (string) - The device-specific token for control operations. - **type** (string) - The type of the device. #### Response Example ```json { "code": "000000", "time": 1739325898971, "msgid": 1739325898971, "method": "Home.getDeviceList", "desc": "Success", "data": { "deviceId": "****4c010001****", "name": "Door Sensor", "token": "****2C89C9FE5C30509B9B6****", "type": "DoorSensor" } } ``` ``` -------------------------------- ### Start Curtain Upgrade Initiates the firmware upgrade process for the Yosmart curtain. You must provide the device ID, a network token, and the version ID for the desired upgrade. ```API method: Curtain.startUpgrade targetDevice: token: params.versionId: data.isStarted: ``` -------------------------------- ### 14. AutoLock.startUpgrade - Start Firmware Upgrade Initiates the firmware upgrade process for the smart lock to a specified version. ```APIDOC ## POST /api/lock/upgrade/start ### Description Initiates the firmware upgrade process for the smart lock to a specified version. ### Method POST ### Endpoint /api/lock/upgrade/start ### Parameters #### Request Body - **targetDevice** (String) - Necessary - DeviceId of this device; - **token** (String) - Necessary - Net Token of this device; - **params.versionId** (String) - Necessary - Version Id you want to upgrade; ### Request Example ```json { "method": "AutoLock.startUpgrade", "targetDevice": "YOUR_DEVICE_ID", "token": "YOUR_NET_TOKEN", "params": { "versionId": "V2" } } ``` ### Response #### Success Response (200) - **data.isStarted** (Boolean) - Necessary - Indicates if the upgrade has started successfully. #### Response Example ```json { "data": { "isStarted": true } } ``` ``` -------------------------------- ### Scan WiFi Networks (HTTP) Initiates a scan for available WiFi networks. Note that this operation can take time, so a timeout greater than 8 seconds is recommended. The response includes details such as SSID, BSSID, authentication type, and signal strength. ```http GET /cgi-bin/api/v1/scan ``` -------------------------------- ### Exit WiFi Configuration Mode Exits the WiFi configuration mode. The device will also automatically exit this mode after 4 minutes. ```APIDOC ## POST /api/v1/wifi/config/exit ### Description Exits the WiFi configuration mode of the device. The device will also automatically exit this state after 4 minutes of inactivity. ### Method POST ### Endpoint /api/v1/wifi/config/exit ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` POST /api/v1/wifi/config/exit ``` ### Response #### Success Response (200) - **code** (String) - Status code, "000000" indicates success. #### Response Example ```json { "code": "000000" } ``` ``` -------------------------------- ### Exit AP Mode (HTTP) Exits the device's Access Point (AP) mode and returns it to Station (STA) mode. This is a simple POST request with no body required. ```http POST /cgi-bin/api/v1/exitAPMode Content-Type: application/json ``` -------------------------------- ### Get Network Status API (AP Mode V2) Retrieves network information for Ethernet connections. This API is used for devices in AP Mode V2. Accessed via HTTP GET. ```HTTP GET /cgi-bin/api/v1/getNetState ``` -------------------------------- ### Outlet.startUpgrade Initiates the firmware upgrade process for the device. ```APIDOC ## Outlet.startUpgrade ### Description Start the firmware upgrade process for the device. ### Method POST ### Endpoint /api/outlet/startUpgrade ### Parameters #### Request Body - **method** (String, Necessary) - Should be "Outlet.startUpgrade". - **targetDevice** (String, Necessary) - DeviceId of the device. - **token** (String, Necessary) - Net Token of the device. - **params.versionId** (String, Necessary) - The Version ID to upgrade to. ### Request Example ```json { "method": "Outlet.startUpgrade", "targetDevice": "your_device_id", "token": "your_net_token", "params": { "versionId": "v2" } } ``` ### Response #### Success Response (200) - **data.isStarted** (Boolean) - Indicates if the upgrade process has started. #### Response Example ```json { "data": { "isStarted": true } } ``` ``` -------------------------------- ### Switch.startUpgrade Initiates a firmware upgrade for the switch. ```APIDOC ## POST /websites/doc_yosmart/Switch/startUpgrade ### Description Initiates a firmware upgrade for the switch. ### Method POST ### Endpoint /websites/doc_yosmart/Switch/startUpgrade ### Parameters #### Query Parameters - **targetDevice** (String, Necessary) - DeviceId of this device. - **token** (String, Necessary) - Net Token of this device. #### Request Body - **params.versionId** (String, Necessary) - Version Id you want to upgrade. ### Request Example ```json { "params": { "versionId": "v2" } } ``` ### Response #### Success Response (200) - **data.isStarted** (Boolean) - Is upgrading started. #### Response Example ```json { "data": { "isStarted": true } } ``` ``` -------------------------------- ### Get Network Status (AP V2) Retrieves network status information for the device using the AP V2 protocol. ```APIDOC ## GET /cgi-bin/api/v1/getNetState ### Description Retrieves network status information for the device. This endpoint is part of the AP V2 protocol for WiFi setup. ### Method GET ### Endpoint /cgi-bin/api/v1/getNetState ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` GET /cgi-bin/api/v1/getNetState ``` ### Response #### Success Response (200) - ***** (Any) - Contains information about the ethernet connection. The exact structure may vary. #### Response Example ```json { "*: Info of ethernet": "Ethernet connected" } ``` ``` -------------------------------- ### YoSmart API Protocol Example Demonstrates the basic structure for interacting with the Device Production API, including request headers and body format. The API uses JSON for requests and responses, and requires an access token for authorization. ```json { "method": "exampleMethod", "params": {} } ``` -------------------------------- ### Curtain.startUpgrade Initiates a firmware upgrade for the Curtain device. ```APIDOC ## Curtain.startUpgrade ### Description Start firmware upgrade for the Curtain device. ### Method POST ### Endpoint /websites/doc_yosmart ### Parameters #### Request Body - **method** (String) - Necessary - Curtain.startUpgrade - **targetDevice** (String) - Necessary - DeviceId of this device; - **token** (String) - Necessary - Net Token of this device; - **params** (Object) - Upgrade parameters. - **versionId** (String) - Necessary - Version Id you want to upgrade; ### Request Example { "method": "Curtain.startUpgrade", "targetDevice": "DEVICE_ID", "token": "NET_TOKEN", "params": { "versionId": "NEW_VERSION_ID" } } ### Response #### Success Response (200) - **data** (Object) - Upgrade status. - **isStarted** (Boolean) - Indicates if the upgrade has started. ``` -------------------------------- ### Get Network Status API (AP Mode V1) Retrieves the current network status of the device, including IP address, connected WiFi SSID, and internet connectivity. Requires the device to be in WiFi configuration mode and accessed via HTTP. ```HTTP GET /api/v1/network/state ``` -------------------------------- ### Subscribe to Device Events Subscribe to receive real-time events from devices using MQTT. ```APIDOC ## MQTT Subscription ### Description Subscribe to a specific MQTT topic to receive real-time event reports from devices connected to your Local Hub. ### Method MQTT ### Endpoint `mqtts://{Your Local Hub IP Address}:18080` ### Parameters - **Username**: `${ClientId}` - **Password**: `${ClientSecret or AccessToken}` - **Topic**: `ylsubnet/${sub-net Id}/+/report` ### Command Example ```bash mosquitto_sub -u ${ClientId} -P ${ClientSecret or AccessToken} -p 18080 -h ${Your Local Hub IP Address} -t ylsubnet/${sub-net Id}/+/report ``` ``` -------------------------------- ### IPCamera.startRecording Initiates local video recording on the IPCamera device. You can optionally specify whether to include audio in the recording and set a duration for the recording. ```APIDOC ## POST /api/ipcamera/startRecording ### Description Starts local video recording on the IPCamera device. ### Method POST ### Endpoint /api/ipcamera/startRecording ### Parameters #### Query Parameters - **targetDevice** (String) - Necessary - DeviceId of the device you use; - **token** (String) - Necessary - Net token of the device you use; #### Request Body - **params.audioEnable** (Boolean) - Optional - Specifies whether to record audio. Defaults to true. - **params.duration** (Integer) - Optional - The duration of the recording in minutes. ### Request Example ```json { "method": "IPCamera.startRecording", "targetDevice": "YOUR_DEVICE_ID", "token": "YOUR_NET_TOKEN", "params": { "audioEnable": false, "duration": 10 } } ``` ### Response #### Success Response (200) - **data.success** (Boolean) - Indicates if the video recording has started successfully. - **data.code** (Integer) - If the code is 200, the video recording has started. #### Response Example ```json { "data": { "success": true, "code": 200 } } ``` ``` -------------------------------- ### Start LeakSensor Upgrade Initiates the firmware upgrade process for the LeakSensor. Requires the device ID, network token, and the version ID to upgrade to. Returns a boolean indicating if the upgrade has started. ```N/A method: LeakSensor.startUpgrade targetDevice: token: params.versionId: data.isStarted: ``` -------------------------------- ### MultiOutlet.startUpgrade Initiates the firmware upgrade process for the MultiOutlet device to a specified version. ```APIDOC ## POST /websites/doc_yosmart/MultiOutlet/startUpgrade ### Description Start the firmware upgrade process for a MultiOutlet device. ### Method POST ### Endpoint /websites/doc_yosmart/MultiOutlet/startUpgrade ### Parameters #### Query Parameters - **targetDevice** (String, Necessary) - DeviceId of this device. - **token** (String, Necessary) - Net Token of this device. #### Request Body - **params.versionId** (String, Necessary) - The Version ID to which you want to upgrade. ### Request Example ```json { "params": { "versionId": "v1.0.6" } } ``` ### Response #### Success Response (200) - **data.isStarted** (Boolean) - Indicates whether the upgrade process has started. ### Response Example ```json { "data": { "isStarted": true } } ``` ``` -------------------------------- ### InfraredForward.startUpgrade API Initiates the firmware upgrade process for the InfraredForward device to a specified version. ```APIDOC ## POST /infraredforward/startUpgrade ### Description Start Upgrade. ### Method POST ### Endpoint /infraredforward/startUpgrade ### Parameters #### Query Parameters - **targetDevice** (String) - Necessary - DeviceId of this device; - **token** (String) - Necessary - Net Token of this device; #### Request Body - **params.versionId** (String) - Necessary - Version Id you want to upgrade; ### Request Example ```json { "params": { "versionId": "v2" } } ``` ### Response #### Success Response (200) - **data.isStarted** (Boolean) - Is upgrading started; #### Response Example ```json { "response": { "data": { "isStarted": true } } } ``` ``` -------------------------------- ### Manipulator.startUpgrade Initiates the firmware upgrade process for the Manipulator device. ```APIDOC ## POST Manipulator.startUpgrade ### Description Start the firmware upgrade process for the Manipulator device. ### Method POST ### Endpoint /device/manipulator/startUpgrade ### Parameters #### Request Body - **method** (String, Necessary) - Must be 'Manipulator.startUpgrade' - **targetDevice** (String, Necessary) - DeviceId of this device - **token** (String, Necessary) - Net Token of this device - **params.versionId** (String, Necessary) - The Version ID to upgrade to ### Request Example ```json { "method": "Manipulator.startUpgrade", "targetDevice": "YOUR_DEVICE_ID", "token": "YOUR_NET_TOKEN", "params": { "versionId": "v2_0_0" } } ``` ### Response #### Success Response (200) - **data.isStarted** (Boolean) - Indicates if the upgrade process has started #### Response Example ```json { "data": { "isStarted": true } } ``` ``` -------------------------------- ### Control Devices Request Payload - Get State (JSON) A sample JSON payload for controlling a device, specifically to get its state. It includes the method 'Hub.getState', a timestamp, the target device ID, and the device-specific token. ```json { "method":"Hub.getState", "time":${timestamp}, "targetDevice":"****4c160300****", "token":"****b642-781e-450f-ba86-df28bdea****", "params":{} } ``` -------------------------------- ### POST /websites/doc_yosmart/Dimmer.startUpgrade Initiates the upgrade process for a dimmer device. ```APIDOC ## POST /websites/doc_yosmart/Dimmer.startUpgrade ### Description Starts the upgrade process for a dimmer device. ### Method POST ### Endpoint /websites/doc_yosmart/Dimmer.startUpgrade ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **method** (String) - Necessary - Dimmer.startUpgrade - **targetDevice** (String) - Necessary - DeviceId of this device - **token** (String) - Necessary - Net Token of this device - **params.versionId** (String) - Necessary - Version Id you want to upgrade ### Request Example ```json { "method": "Dimmer.startUpgrade", "targetDevice": "", "token": "", "params": { "versionId": "1.0.0" } } ``` ### Response #### Success Response (200) - **data.isStarted** (Boolean) - Necessary - Is upgrading started #### Response Example ```json { "data": { "isStarted": true } } ``` ``` -------------------------------- ### Sprinkler.startUpgrade Initiates the firmware upgrade process for the sprinkler. ```APIDOC ## POST /websites/doc_yosmart/Sprinkler.startUpgrade ### Description Starts the firmware upgrade for the sprinkler. ### Method POST ### Endpoint /websites/doc_yosmart/Sprinkler.startUpgrade ### Parameters #### Query Parameters - **method** (String) - Necessary - Sprinkler.startUpgrade - **targetDevice** (String) - Necessary - DeviceId of this device; - **token** (String) - Necessary - Net Token of this device; #### Request Body - **params.versionId** (String) - Necessary - Version Id you want to upgrade; ### Request Example ```json { "method": "Sprinkler.startUpgrade", "targetDevice": "your_device_id", "token": "your_net_token", "params": { "versionId": "v2" } } ``` ### Response #### Success Response (200) - **data.isStarted** (Boolean) - Necessary - Is upgrading started; #### Response Example ```json { "data": { "isStarted": true } } ``` ``` -------------------------------- ### Outlet.startUpgrade Initiates the firmware upgrade process for the smart outlet to a specified version. ```APIDOC ## POST /api/outlet/startUpgrade ### Description Start the firmware upgrade process for the device. ### Method POST ### Endpoint /api/outlet/startUpgrade ### Parameters #### Query Parameters - **targetDevice** (String, Necessary) - DeviceId of this device. - **token** (String, Necessary) - Net Token of this device. #### Request Body - **params.versionId** (String, Necessary) - The Version Id you want to upgrade to. ### Request Example ```json { "params": { "versionId": "v2" } } ``` ### Response #### Success Response (200) - **data.isStarted** (Boolean) - Indicates if the upgrade process has started. #### Response Example ```json { "data": { "isStarted": true } } ``` ``` -------------------------------- ### 12. AutoLock.getLogs - Get Lock Logs Retrieves the operation logs from the smart lock. ```APIDOC ## POST /api/lock/logs/get ### Description Retrieves the operation logs from the smart lock. ### Method POST ### Endpoint /api/lock/logs/get ### Parameters #### Request Body - **targetDevice** (String) - Necessary - DeviceId of the Lock you use; - **token** (String) - Necessary - Net token of the Lock you use; ### Request Example ```json { "method": "AutoLock.getLogs", "targetDevice": "YOUR_DEVICE_ID", "token": "YOUR_NET_TOKEN" } ``` ### Response #### Success Response (200) - **logs** (Array) - An array of log objects, each containing log details. #### Response Example ```json { "logs": [ { "timestamp": "2023-10-27T10:00:00Z", "event": "Door unlocked", "user": "User1" } ] } ``` ``` -------------------------------- ### YoSmart API Overview General information about the YoSmart API, including who can use it and how it works. ```APIDOC ## YoSmart API Overview ### Description The YoSmart API is provided by YoSmart Cloud to control and access data from YoSmart Inc. and YoLink brand devices. ### Usage - **Business Partners**: Use CSID for authentication. CSID allows access to large-scale devices and devices from other users (requires contact for CSID and access rights). - **Product Users**: Create UAC within the application for authentication. UAC allows access only to devices under the user's account. ### How it Works The API is accessed via the internet and supports both HTTP and MQTT protocols. The HTTP interface uses JSON RPC, not RESTful specifications, for data transfer. ### API Host (US) `api.yosmart.com` ### Data Packet Types - **BDDP**: Basic Downlink Data Packet - **BUDP**: Basic Uplink Data Packet ### Modules - **Protocol**: Describes API access methods. - **Methods - ***: Describes API functions and their DataPackets. - **Methods - Account**: Describes DataPackets for device management. - **Methods - YoLink Devices**: Describes DataPackets for YoLink product access. - **Methods - YoSmart Devices**: Describes DataPackets for YoSmart SmartHome product access. ### Contact Information - **YoSmart Service**: service@yosmart.com - **R&D Team**: yaochi@yosmart.com ``` -------------------------------- ### Lock.getState API Gets the current status of the lock device by retrieving the newest status directly from the device. ```APIDOC ## POST /websites/doc_yosmart/Lock.getState ### Description Gets the current status of the device (Get the newest status from the device). ### Method POST ### Endpoint /websites/doc_yosmart/Lock.getState ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * **method** (String, Necessary) - Lock.getState * **targetDevice** (String, Necessary) - DeviceId of the Lock you use. * **token** (String, Necessary) - Net token of the Lock you use. ### Request Example ```json { "method": "Lock.getState", "targetDevice": "", "token": "" } ``` ### Response #### Success Response (200) * **data.state.state** (String, Necessary) - State of lock, ["locked", "unlocked"] * **data.state.battery** (Integer, Necessary) - Level of device's battery, 0 to 4 means empty to full * **data.version** (String, Necessary) - Firmware Version of device * **data.tz** (Integer, Necessary) - Timezone of device. -12 ~ 12 #### Response Example ```json { "data": { "state": { "state": "unlocked", "battery": 4 }, "version": "1.0.1", "tz": 9 } } ``` ``` -------------------------------- ### Bind YoLink Devices This section describes how to bind YoLink devices using the Manage.addYoLinkDevice method. ```APIDOC ## POST /api/manage/addYoLinkDevice ### Description Applies for a CSID and binds YoLink devices to your account. ### Method POST ### Endpoint /api/manage/addYoLinkDevice ### Parameters #### Request Body - **method** (string) - Required - The method name, "Manage.addYoLinkDevice". - **time** (integer) - Required - Timestamp of the request. - **params** (object) - Required - Parameters for the method. - **sn** (string) - Required - The serial number (QR-Code) of the YoLink device. ### Request Example ```json { "method":"Manage.addYoLinkDevice", "time":1572322745846, "params":{ "sn":"****060212B6481EBD4EC7696728****" } } ``` ### Response #### Success Response (200) - **code** (string) - Response code, "000000" for success. - **time** (integer) - Timestamp of the response. - **msgid** (integer) - Message ID. - **method** (string) - The method called. - **data** (object) - Data related to the bound device. - **deviceId** (string) - The unique identifier for the device. - **deviceUDID** (string) - The unique UDID for the device. - **name** (string) - The name of the device. - **token** (string) - The network token for controlling the device. - **type** (string) - The type of the device. #### Response Example ```json { "code": "000000", "time": 1572322745846, "msgid": 1572322745, "method": "Manage.addYoLinkDevice", "data": { "deviceId": "****4c160300****", "deviceUDID": "****ae3685504566af434e0f093c****", "name": "YoLink Hub", "token": "****b642-781e-450f-ba86-df28bdea****", "type": "Hub" } } ``` ``` -------------------------------- ### Exit AP Mode Exits the Access Point (AP) mode and returns the hub to Station (STA) mode. ```APIDOC ## POST /cgi-bin/api/v1/exitAPMode ### Description Exits AP mode and returns the hub to STA mode. ### Method POST ### Endpoint /cgi-bin/api/v1/exitAPMode ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **code** (String) - The error code; "000000" means success. #### Response Example ```json { "code": "000000" } ``` ``` -------------------------------- ### Switch.startUpgrade Initiates the firmware upgrade process for the switch to a specified version. ```APIDOC ## POST /websites/doc_yosmart/Switch/startUpgrade ### Description Initiate the firmware upgrade process for the switch. ### Method POST ### Endpoint /websites/doc_yosmart/Switch/startUpgrade ### Parameters #### Query Parameters - **method** (String, Necessary) - Switch.startUpgrade - **targetDevice** (String, Necessary) - DeviceId of this device - **token** (String, Necessary) - Net Token of this device #### Request Body - **params.versionId** (String, Necessary) - Version Id you want to upgrade. ### Request Example { "example": { "params": { "versionId": "v2_1" } } } ### Response #### Success Response (200) - **data.isStarted** (Boolean, Necessary) - Is upgrading started. #### Response Example { "example": { "data": { "isStarted": true } } } ``` -------------------------------- ### 13. AutoLock.getVersion - Get Firmware Version Retrieves the current firmware version and information about the latest available version for the smart lock. ```APIDOC ## POST /api/lock/version/get ### Description Retrieves the current firmware version and information about the latest available version for the smart lock. ### Method POST ### Endpoint /api/lock/version/get ### Parameters #### Request Body - **targetDevice** (String) - Necessary - DeviceId of this device; - **token** (String) - Necessary - Net Token of this device; ### Request Example ```json { "method": "AutoLock.getVersion", "targetDevice": "YOUR_DEVICE_ID", "token": "YOUR_NET_TOKEN" } ``` ### Response #### Success Response (200) - **data.version** (String) - Necessary - Current Version; - **data.newVersion.versionId** (String) - Optional - Id of the newest version; - **data.newVersion.versionCode** (String) - Optional - Code of the newest version; - **data.newVersion.fileSize** (String) - Optional - File Size of the newest version; #### Response Example ```json { "data": { "version": "1.0.0", "newVersion": { "versionId": "V2", "versionCode": "2.0.0", "fileSize": "1024 KB" } } } ``` ``` -------------------------------- ### GET /api/watermeter/leak_schedules Retrieves the leak schedules for the Water Meter Controller. This endpoint allows users to fetch the configured leak detection parameters. ```APIDOC ## GET /api/watermeter/leak_schedules ### Description Get Water Meter Controller leak schedules. ### Method GET ### Endpoint /api/watermeter/leak_schedules ### Parameters #### Query Parameters - **method** (String) - Required - Manipulator.getSchedules - **targetDevice** (String) - Required - DeviceId of the Water Meter Controller you use - **token** (String) - Required - Net token of the Water Meter Controller you use ### Request Example ```json { "method": "Manipulator.getSchedules", "targetDevice": "", "token": "" } ``` ### Response #### Success Response (200) - **data** (Array) - An array of leak schedule objects. - **data[index].isValid** (Boolean) - Enabled/Disabled - **data[index].index** (Integer) - Index of this record - **data[index].on** (String) - Time to turn on; HH:mm - **data[index].off** (String) - Time to turn off; HH:mm - **data[index].week** (Integer) - Mask of effected days(Sunday to Saturday) - **data[index].leakLimit** (Integer) - Leak limit in meter unit #### Response Example ```json { "data": [ { "isValid": true, "index": 0, "on": "00:00", "off": "00:00", "week": 1, "leakLimit": 100 } ] } ``` ``` -------------------------------- ### GET /Thermostat.getSchedules Retrieves the configured schedule list for the thermostat, including weekday schedules with specific temperature points. ```APIDOC ## GET /Thermostat.getSchedules ### Description Get the schedule list for the thermostat. This includes configured schedules for weekdays. ### Method GET ### Endpoint /Thermostat.getSchedules ### Parameters #### Path Parameters None #### Query Parameters - **method** (String) - Necessary - 'Thermostat.getSchedules' - **targetDevice** (String) - Necessary - DeviceId of the Thermostat you use - **token** (String) - Necessary - Net token of the Thermostat you use #### Request Body None ### Request Example ```json { "method": "Thermostat.getSchedules", "targetDevice": "YOUR_DEVICE_ID", "token": "YOUR_NET_TOKEN" } ``` ### Response #### Success Response (200) - **data.sches** (Array) - Schedules for weekdays (from Monday to Saturday). - **data.sches[weekday]** (Array) - 4 points for one day. Times of these points must be continuous. - **data.sches[weekday][index].time** (String) - Time of this point, HH:MM formatted. - **data.sches[weekday][index].lowTemp** (Float) - Lower temperature of this point in Celsius. - **data.sches[weekday][index].highTemp** (Float) - Upper temperature of this point in Celsius. #### Response Example ```json { "data": { "sches": { "Monday": [ {"time": "06:00", "lowTemp": 18.0, "highTemp": 22.0}, {"time": "09:00", "lowTemp": 17.0, "highTemp": 21.0}, {"time": "17:00", "lowTemp": 19.0, "highTemp": 23.0}, {"time": "22:00", "lowTemp": 16.0, "highTemp": 20.0} ], "Tuesday": [ {"time": "06:00", "lowTemp": 18.5, "highTemp": 22.5}, {"time": "09:00", "lowTemp": 17.5, "highTemp": 21.5}, {"time": "17:00", "lowTemp": 19.5, "highTemp": 23.5}, {"time": "22:00", "lowTemp": 16.5, "highTemp": 20.5} ] } } } ``` ``` -------------------------------- ### Subscribe to Device Events using mosquitto_sub This command allows you to subscribe to real-time event reports from YoSmart devices using MQTT. You need to provide client credentials (ClientId and ClientSecret or AccessToken), port, hub IP address, and the topic format. ```bash mosquitto_sub -u ${ClientId} -P ${ClientSecret or AccessToken} -p 18080 -h ${Your Local Hub IP Address} -t ylsubnet/${sub-net Id}/+/report ```