### Complete Example: Basic GET Endpoint Source: https://shelly-api-docs.shelly.cloud/gen2/Scripts/APIs/HTTPServer This example shows how to create a basic GET endpoint that returns device information and system status, including error handling for incorrect methods. ```javascript // Simple GET endpoint that returns device information Httpserver.registerEndpoint("info", function(request, response) { if (request.method !== "GET") { response.code = 405; // Method Not Allowed response.body = "Only GET method is allowed"; response.send(); return; } let deviceInfo = Shelly.getDeviceInfo(); let status = Shelly.getComponentStatus("sys"); response.body = JSON.stringify({ device: { id: deviceInfo.id, model: deviceInfo.model, fw_version: deviceInfo.fw_id }, system: { uptime: status.uptime, ram_free: status.ram_free, ram_size: status.ram_size } }); response.headers = [["Content-Type", "application/json"]]; response.code = 200; response.send(); }); ``` -------------------------------- ### Start BLE Associations Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/BLE Examples for initiating BLE associations with specified parameters using HTTP GET, cURL, and the mos tool. Parameters include target, param, duration, and RSSI threshold. ```http http://192.168.33.1/rpc/BLE.StartAssociations?target=8¶m=200&duration=120&rssi_thr=-80 ``` ```bash curl -X POST -d '{"id":1,"method":"BLE.StartAssociations","params":{"target":8,"param":200,"duration":120,"rssi_thr":-80}}' http://${SHELLY}/rpc ``` ```bash mos --port ${PORT} call BLE.StartAssociations '{"target":8,"param":200,"duration":120,"rssi_thr":-80}' ``` -------------------------------- ### SetConfig Request Examples Source: https://shelly-api-docs.shelly.cloud/gen2/Devices/ShellyX/XT1 Examples of how to set the configuration for a service. These demonstrate HTTP GET, Curl, and Mos commands. ```http http://192.168.33.1/rpc/Service.SetConfig?id=0&config={"name":"Water valve"} ``` ```curl curl -X POST -d '{"id":1,"method":"Service.SetConfig","params":{"id":0,"config":{"name":"Water valve"}}}' http://${SHELLY}/rpc ``` ```shell mos --port ${PORT} call Service.SetConfig '{"id":0,"config":{"name":"Water valve"}}' ``` -------------------------------- ### GetStatus Request Examples Source: https://shelly-api-docs.shelly.cloud/gen2/Devices/ShellyX/XT1 Examples of how to get the status of a service. These demonstrate HTTP GET, Curl, and Mos commands. ```http http://192.168.33.1/rpc/Service.GetStatus?id=0 ``` ```curl curl -X POST -d '{"id":1,"method":"Service.GetStatus","params":{"id":0}}' http://${SHELLY}/rpc ``` ```shell mos --port ${PORT} call Service.GetStatus '{"id":0}' ``` -------------------------------- ### Shelly HTTP GET Request Example Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/HTTP Demonstrates how to perform an HTTP GET request to a Shelly device. This example shows the direct URL format for the request. ```http http://192.168.33.1/rpc/HTTP.GET?url="http://10.33.53.21/rpc/Shelly.GetDeviceInfo" ``` -------------------------------- ### BTHomeDevice.GetKnownObjects RPC Examples Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeDevice Examples for retrieving known objects associated with a BTHomeDevice. Includes HTTP GET, cURL, and mos commands. ```http http://192.168.33.1/rpc/BTHomeDevice.GetKnownObjects?id=200 ``` ```bash curl -X POST -d '{"id":1,"method":"BTHomeDevice.GetKnownObjects","params":{"id":200}}' http://${SHELLY}/rpc ``` ```bash mos --port ${PORT} call BTHomeDevice.GetKnownObjects '{"id":200}' ``` -------------------------------- ### AddOn.GetInfo HTTP GET Response Example Source: https://shelly-api-docs.shelly.cloud/gen2/Addons/ShellyProSensorAddon Example of a successful HTTP GET response for AddOn.GetInfo, detailing the addon's type, hardware version, firmware version, and supported IOs. ```json { "type": "ProSensorAddon", "hw_ver": "1.0", "fw_ver": "1.0.0", "supported_ios": { "digital_in": [ 0, 1 ], "analog_in": [ 0, 1 ], "digital_out": [ 0 ], "ds18b20": [ 0, 1 ], "dht22": [ 0, 1 ] } } ``` -------------------------------- ### Shelly Cury GetConfig Request Examples Source: https://shelly-api-docs.shelly.cloud/gen2/Devices/PoweredByShelly/ShellyCury Examples for requesting the Cury configuration. Includes HTTP GET, cURL, and mos commands. ```http http://192.168.33.1/rpc/Cury.GetConfig?id=0 ``` ```bash curl -X POST -d '{"id":1,"method":"Cury.GetConfig","params":{"id":0}}' http://${SHELLY}/rpc ``` ```bash mos --port ${PORT} call Cury.GetConfig '{"id":0}' ``` -------------------------------- ### Read Coils with MbRtuClient Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/MbRtuClient Examples for reading Modbus Coils using HTTP GET, cURL, and mos. Requires specifying device ID, slave ID, starting address, and quantity. ```http http://192.168.33.1/rpc/MbRtuClient.ReadCoils?id=0&sid=2&addr=10&qty=5 ``` ```curl curl -X POST -d '{"id":1,"method":"MbRtuClient.ReadCoils","params":{"id":0,"sid":2,"addr":10,"qty":5}}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call MbRtuClient.ReadCoils '{"id":0,"sid":2,"addr":10,"qty":5}' ``` -------------------------------- ### BLE.Scanner.start() Example Source: https://shelly-api-docs.shelly.cloud/gen2/Scripts/APIs/BLE Example demonstrating how to start scanning for BLE devices, check for a specific service (e.g., temperature sensor), parse the service data, and log the temperature. ```APIDOC ## Temperature Sensor Monitor Example ### Description This example demonstrates how to monitor BLE temperature sensors. It starts an infinite scan for BLE devices, checks the advertisement data for the temperature service ('181a'), parses the service data, and logs the temperature if found. ### Code Example ```javascript // Monitor BLE temperature sensors BLE.Scanner.start({ duration_ms: BLE.Scanner.INFINITE_SCAN, active: false }, function(event, result) { if (event !== BLE.Scanner.SCAN_RESULT) return; // Check for temperature service if (BLE.GAP.hasService(result.advData, "181a")) { let serviceData = BLE.GAP.parseServiceData(result.advData, "181a"); if (serviceData.length >= 2) { // Parse temperature (example format) let temp = (serviceData.charCodeAt(0) | (serviceData.charCodeAt(1) << 8)) / 100; console.log("Temperature from", result.addr, ":", temp, "°C"); } } }); ``` ``` -------------------------------- ### BTHomeControl.StartLearning Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeControl Starts the process of adding new mappings by learning from a BLU device. ```APIDOC ## BTHomeControl.StartLearning ### Description Starts the process of adding mappings by learning from a BLU device. This can also be triggered by pressing the desired Input 4 times. ### Method POST ### Endpoint /rpc/BTHomeControl.StartLearning ### Parameters #### Request Body - **input_id** (string) - Required - The ID of the input on the Shelly WiFi device to map. ``` -------------------------------- ### Read Discrete Inputs with MbRtuClient Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/MbRtuClient Examples for reading Modbus Discrete Inputs using HTTP GET, cURL, and mos. Requires specifying device ID, slave ID, starting address, and quantity. ```http http://192.168.33.1/rpc/MbRtuClient.ReadDiscreteInputs?id=0&sid=2&addr=0&qty=4 ``` ```curl curl -X POST -d '{"id":1,"method":"MbRtuClient.ReadDiscreteInputs","params":{"id":0,"sid":2,"addr":0,"qty":4}}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call MbRtuClient.ReadDiscreteInputs '{"id":0,"sid":2,"addr":0,"qty":4}' ``` -------------------------------- ### Quick Example: Virtual Components Interaction Source: https://shelly-api-docs.shelly.cloud/gen2/Scripts/APIs/Virtual Demonstrates how to get handles to virtual components, set their values, read values, configure them, and listen for changes. Use this for a comprehensive overview of virtual component usage. ```javascript // Get handles to virtual components let temperature = Virtual.getHandle("number:200"); let status = Virtual.getHandle("text:200"); let alarm = Virtual.getHandle("boolean:200"); // Set values temperature.setValue(23.5); status.setValue("Normal"); alarm.setValue(false); // Read values console.log("Temperature:", temperature.getValue()); // Configure the temperature component temperature.setConfig({ name: "Room Temperature", persisted: true, min: -40, max: 85, default_value: 20, meta: { ui: { unit: "°C", step: 0.1 } } }); // Listen for changes temperature.on("change", function(event) { console.log("Temperature changed to", event.value); if (event.value > 30) { alarm.setValue(true); status.setValue("High temperature alert!"); } }); ``` -------------------------------- ### Read Input Registers with MbRtuClient Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/MbRtuClient Examples for reading Modbus Input Registers using HTTP GET, cURL, and mos. Requires specifying device ID, slave ID, starting address, and quantity. ```http http://192.168.33.1/rpc/MbRtuClient.ReadInputRegisters?id=0&sid=1&addr=300&qty=3 ``` ```curl curl -X POST -d '{"id":1,"method":"MbRtuClient.ReadInputRegisters","params":{"id":0,"sid":1,"addr":300,"qty":3}}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call MbRtuClient.ReadInputRegisters '{"id":0,"sid":1,"addr":300,"qty":3}' ``` -------------------------------- ### Temperature Monitor with Alarm Example Source: https://shelly-api-docs.shelly.cloud/gen2/Scripts/APIs/Virtual A comprehensive example demonstrating how to set up virtual components for temperature monitoring, including status updates, alarms, and button resets. ```javascript // Virtual components for temperature monitoring let currentTemp = Virtual.getHandle("number:200"); let tempStatus = Virtual.getHandle("text:201"); let highTempAlarm = Virtual.getHandle("boolean:202"); let resetButton = Virtual.getHandle("button:203"); // Configure temperature sensor currentTemp.setConfig({ name: "Temperature Sensor", persisted: true, min: -50, max: 150, default_value: 20, meta: { ui: { unit: "°C", step: 0.1 } } }); // Configure status text tempStatus.setConfig({ name: "Status", persisted: false, default_value: "Normal" }); // Temperature threshold const TEMP_THRESHOLD = 35; // Monitor temperature changes currentTemp.on("change", function(event) { console.log("Temperature:", event.value, "°C"); if (event.value > TEMP_THRESHOLD) { highTempAlarm.setValue(true); tempStatus.setValue("HIGH TEMPERATURE: " + event.value + "°C"); // Send alert Shelly.call("HTTP.Request", { method: "GET", url: "http://alert.server/high-temp?value=" + event.value }); } else { highTempAlarm.setValue(false); tempStatus.setValue("Normal: " + event.value + "°C"); } }); // Reset button resetButton.on("single_push", function() { console.log("Reset pressed"); highTempAlarm.setValue(false); tempStatus.setValue("System reset"); }); // Simulate temperature readings (in real use, read from actual sensor) Timer.set(5000, true, function() { let mockTemp = 20 + Math.random() * 30; currentTemp.setValue(mockTemp); }); console.log("Temperature monitor started"); ``` -------------------------------- ### Read Holding Registers with MbRtuClient Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/MbRtuClient Examples for reading Modbus Holding Registers using HTTP GET, cURL, and mos. Requires specifying device ID, slave ID, starting address, and quantity. ```http http://192.168.33.1/rpc/MbRtuClient.ReadHoldingRegisters?id=0&sid=1&addr=100&qty=2 ``` ```curl curl -X POST -d '{"id":1,"method":"MbRtuClient.ReadHoldingRegisters","params":{"id":0,"sid":1,"addr":100,"qty":2}}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call MbRtuClient.ReadHoldingRegisters '{"id":0,"sid":1,"addr":100,"qty":2}' ``` -------------------------------- ### Sys.GetConfig Response Example (Device) Source: https://shelly-api-docs.shelly.cloud/docs-ble/Devices/BLU_ZB/trv Example response from Sys.GetConfig showing device configuration details. ```JSON { "device": { "name": "" }, "location": { "lat": 0, "lon": 0 }, "ui": { "lock": false, "t_units": "C", "flip": false, "brightness": 7, "power_save": true }, "ble": { "interval_ms": 333, "beacon_count": 5 }, "cfg_rev": 1 } ``` -------------------------------- ### BTHomeDevice.GetConfig RPC Examples Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeDevice Examples for retrieving the configuration of a BTHomeDevice. Includes HTTP GET, cURL, and mos commands. The configuration includes device ID, address, name, and meta information. ```http http://192.168.33.1/rpc/BTHomeDevice.GetConfig?id=200 ``` ```bash curl -X POST -d '{"id":1,"method":"BTHomeDevice.GetConfig","params":{"id":200}}' http://${SHELLY}/rpc ``` ```bash mos --port ${PORT} call BTHomeDevice.GetConfig '{"id":200}' ``` -------------------------------- ### Write Holding Registers with MbRtuClient Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/MbRtuClient Examples for writing Modbus Holding Registers using HTTP GET, cURL, and mos. Requires specifying device ID, slave ID, starting address, and values to write. ```http http://192.168.33.1/rpc/MbRtuClient.WriteHoldingRegisters?id=0&sid=3&addr=400&values=[1000,2000] ``` ```curl curl -X POST -d '{"id":1,"method":"MbRtuClient.WriteHoldingRegisters","params":{"id":0,"sid":3,"addr":400,"values":[1000,2000]}}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call MbRtuClient.WriteHoldingRegisters '{"id":0,"sid":3,"addr":400,"values":[1000,2000]}' ``` -------------------------------- ### BTHomeDevice.SetConfig RPC Examples Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeDevice Examples for setting the configuration of a BTHomeDevice. Includes HTTP GET, cURL, and mos commands. The configuration can include the device name. ```http http://192.168.33.1/rpc/BTHomeDevice.SetConfig?id=200&config={"name":"Bathroom temperature"} ``` ```bash curl -X POST -d '{"id":1,"method":"BTHomeDevice.SetConfig","params":{"id":200,"config":{"name":"Bathroom temperature"}}}' http://${SHELLY}/rpc ``` ```bash mos --port ${PORT} call BTHomeDevice.SetConfig '{"id":200,"config":{"name":"Bathroom temperature"}}' ``` -------------------------------- ### Get Matter Setup Code via HTTP GET Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Matter Use this endpoint to retrieve the Matter setup code for a device. No specific setup is required beyond network access. ```http http://192.168.33.1/rpc/Matter.GetSetupCode? ``` -------------------------------- ### BTHomeControl.StartLearning Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeControl Initiates the learning mode for a specific BTHome input, allowing new devices to be paired. Supports HTTP GET, cURL, and MOS calls. ```APIDOC ## BTHomeControl.StartLearning ### Description Starts the learning process for a specified BTHome input, enabling the device to learn new remote controls. ### Method GET ### Endpoint `/rpc/BTHomeControl.StartLearning?input_id={input_id}` ### Parameters #### Query Parameters - **input_id** (integer) - Required - The ID of the input to start learning on. ### Request Example ```http http://192.168.33.1/rpc/BTHomeControl.StartLearning?input_id=2 ``` ### Response #### Success Response (200) Returns `null` upon successful initiation of learning mode. #### Response Example ```json null ``` ``` -------------------------------- ### Start Script - HTTP GET Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Script Starts a specified script using an HTTP GET request. The script ID is provided in the URL. ```http http://192.168.33.1/rpc/Script.Start?id=1 ``` -------------------------------- ### RGBCCT.Toggle Example Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/RGBCCT Demonstrates how to toggle the RGBCCT light. Includes HTTP GET, cURL, and mos tool requests. ```http http://192.168.33.1/rpc/RGBCCT.Toggle?id=0 ``` ```curl curl -X POST -d '{"id":1,"method":"RGBCCT.Toggle","params":{"id":0}}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call RGBCCT.Toggle '{"id":0}' ``` -------------------------------- ### Start BTHome Learning Mode (HTTP GET) Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeControl Initiate BTHome learning mode for a specific input ID using an HTTP GET request. ```http http://192.168.33.1/rpc/BTHomeControl.StartLearning?input_id=2 ``` -------------------------------- ### Shelly.Reboot HTTP GET Request Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Shelly Example HTTP GET request for Shelly.Reboot. ```http http://192.168.33.1/rpc/Shelly.Reboot ``` -------------------------------- ### Shelly.ResetWiFiConfig HTTP GET Request Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Shelly Example HTTP GET request for Shelly.ResetWiFiConfig. ```http http://192.168.33.1/rpc/Shelly.ResetWiFiConfig ``` -------------------------------- ### Shelly.FactoryReset HTTP GET Request Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Shelly Example HTTP GET request for Shelly.FactoryReset. ```http http://192.168.33.1/rpc/Shelly.FactoryReset ``` -------------------------------- ### Set Light over MQTT Example Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Light Set light state, brightness, transition, and toggle duration via MQTT. Ensure MQTT server and device ID are exported as environment variables. ```shell export MQTT_SERVER="broker.hivemq.com" export MQTT_PORT=1883 export SHELLY_ID="shellyprodm1pm-441793ce3f08" # The of your device mosquitto_pub -h ${MQTT_SERVER} -p ${MQTT_PORT} -t ${SHELLY_ID}/command/light:0 -m set,true,100,5,10 ``` -------------------------------- ### Light.Set RPC Calls Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Light Examples of how to set the state of a specific light using HTTP GET, Curl, and Mos commands. These examples demonstrate setting the light on, its brightness, and transition duration. ```http http://192.168.33.1/rpc/Light.Set?id=0&on=true&brightness=50&transition_duration=20 ``` ```curl curl -X POST -d '{"id":1,"method":"Light.Set","params":{"id":0,"on":true,"brightness":50,"transition_duration":20}}' http://${SHELLY}/rpc ``` ```bash mos --port ${PORT} call Light.Set '{"id":0,"on":true,"brightness":50,"transition_duration":20}' ``` -------------------------------- ### Shelly.CheckForUpdate HTTP GET Request Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Shelly Example HTTP GET request for Shelly.CheckForUpdate. ```http http://192.168.33.1/rpc/Shelly.CheckForUpdate ``` -------------------------------- ### Shelly.DetectLocation HTTP GET Request Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Shelly Example HTTP GET request for Shelly.DetectLocation. ```http http://192.168.33.1/rpc/Shelly.DetectLocation ``` -------------------------------- ### BTHomeControl.StartLearning Response (cURL) Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeControl Example response from the BTHomeControl.StartLearning cURL request. ```json { "id": 1, "src": "shelly1pmg3-84fce73fe000", "params": null } ``` -------------------------------- ### Shelly HTTP GET Response Example Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/HTTP Provides an example of the expected JSON response from a Shelly HTTP GET request. It includes status code, headers, and the response body. ```json { "code": 200, "message": "OK", "headers": { "Server": "ShellyHTTP/1.0.0", "Content-Type": "application/json", "Content-Length": "232", "Connection": "close" }, "body": "{\"id\":\"shellydev1-f008d1e2cb4c\", \"mac\":\"F008D1E2CB4C\", \"model\":\"SNSW-devX16EU\", \"gen\":2, \"fw_id\":\"20210908-124312/0.7.0-29-g0df1661-145-rpc-http-get-improvements-2\", \"ver\":\"0.7.0\", \"app\":\"Dev1\", \"auth_en\":false,\"auth_domain\":null} " } ``` -------------------------------- ### RGBCCT.Set Request Examples Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/RGBCCT Examples for setting parameters of an RGBCCT device, including on/off state, brightness, RGB color, color temperature, and transition duration. Supports HTTP GET, cURL, and mos commands. ```http http://192.168.33.1/rpc/RGBCCT.Set?id=0&on=true&brightness=50&rgb=[20,30,40]&ct=4000&transition_duration=20 ``` ```curl curl -X POST -d '{"id":1,"method":"RGBCCT.Set","params":{"id":0,"on":true,"brightness":50,"rgb":[20,30,40],"ct":4000,"transition_duration":20}}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call RGBCCT.Set '{"id":0,"on":true,"brightness":50,"rgb":[20,30,40],"ct":4000,"transition_duration":20}' ``` -------------------------------- ### Enable Auto-Start via HTTP GET Source: https://shelly-api-docs.shelly.cloud/gen2/Scripts/Overview Use this HTTP GET request to configure a script to automatically start on device boot. The script ID and configuration are provided in the URL. ```http http://192.168.33.1/rpc/Script.SetConfig?id=1&config={"enable":true} ``` -------------------------------- ### Get Remote Device Info Request Examples Source: https://shelly-api-docs.shelly.cloud/gen2/Devices/Gen3/ShellyBluGwG3 Examples for requesting remote device information using HTTP GET, cURL, and mos. The 'id' parameter specifies the target device. ```http http://192.168.33.1/rpc/BluTrv.GetRemoteDeviceInfo?id=200 ``` ```bash curl -X POST -d '{"id":1,"method":"BluTrv.GetRemoteDeviceInfo","params":{"id":200}}' http://${SHELLY}/rpc ``` ```bash mos --port ${PORT} call BluTrv.GetRemoteDeviceInfo '{"id":200}' ``` -------------------------------- ### Input.SetConfig Example Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Input Demonstrates how to set the configuration for an Input component. Supports HTTP GET, Curl, and Mos requests. Note that some configuration changes may require a device restart. ```http http://192.168.33.1/rpc/Input.SetConfig?id=0&config={"name":"Input0"} ``` ```curl curl -X POST -d '{"id":1,"method":"Input.SetConfig","params":{"id":0,"config":{"name":"Input0"}}}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call Input.SetConfig '{"id":0,"config":{"name":"Input0"}}' ``` ```json { "restart_required": false } ``` ```json { "id": 1, "src": "shellypro1-84cca87c1f90", "params": { "restart_required": false } } ``` ```json { "restart_required": false } ``` -------------------------------- ### Start BTHome Device Discovery via mos tool Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome Start BTHome device discovery using the mos tool. Specify the port and the duration for the discovery process. ```bash mos --port ${PORT} call BTHome.StartDeviceDiscovery '{"duration":25}' ``` -------------------------------- ### Button.GetConfig Example Source: https://shelly-api-docs.shelly.cloud/gen2/Devices/ShellyX/XT1 Example of how to get the configuration for a Button component using different methods. ```APIDOC ## Button.GetConfig Example ### Description Examples for retrieving the configuration of a Button component. ### HTTP GET Request `http://192.168.33.1/rpc/Button.GetConfig?owner="service:0"&role="open"` ### Curl Request ```bash curl -X POST -d '{"id":1,"method":"Button.GetConfig","params":{"owner":"service:0","role":"open"}}' http://${SHELLY}/rpc ``` ### Mos Request ```bash mos --port ${PORT} call Button.GetConfig '{"owner":"service:0","role":"open"}' ``` ### Response Example ```json { "id": 201, "name": "Open", "meta": { "ui": { "view": "button" } }, "owner": "service:0", "access": "crw" } ``` ``` -------------------------------- ### Zigbee.GetStatus Example Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Zigbee Use these examples to get the current network status of the Zigbee component. ```http http://192.168.33.1/rpc/Zigbee.GetStatus ``` ```curl curl -X POST -d '{"id":1,"method":"Zigbee.GetStatus"}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call Zigbee.GetStatus ``` -------------------------------- ### Sys.SetConfig Response Example (With ID) Source: https://shelly-api-docs.shelly.cloud/docs-ble/Devices/BLU_ZB/trv Example response from Sys.SetConfig including an ID and source device information. ```JSON { "id": 1, "src": "shellyplus2pm-a8032ab636ec", "params": null } ``` -------------------------------- ### BTHomeDevice.GetConfig Response Examples Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeDevice Response examples for the BTHomeDevice.GetConfig RPC call, showing device details like ID, address, name, and meta. ```json { "id": 200, "addr": "3c:2e:f5:71:d5:2a", "name": "Bathroom temperature", "meta": null } ``` ```json { "id": 1, "src": "shelly1pmminig3-84fce63fe000", "params": { "id": 200, "addr": "3c:2e:f5:71:d5:2a", "name": "Bathroom temperature", "meta": null } } ``` ```json { "id": 200, "addr": "3c:2e:f5:71:d5:2a", "name": "Bathroom temperature", "meta": null } ``` -------------------------------- ### BTHomeControl.Enumerate HTTP GET Response Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeControl Example response from an HTTP GET request to BTHomeControl.Enumerate. ```json { "light:0": 200, "light:1": 201, "light:2": 202 } ``` -------------------------------- ### BTHomeControl.List Response (HTTP GET) Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeControl Example response from the BTHomeControl.List HTTP GET request. ```json { "id": 200, "output": "switch:0", "inputs": [ { "bthomedevice:200": { "58:0": { "single_push": { "action": "on" } }, "58:1": { "single_push": { "action": "off" } } } }, { "bthomedevice:201": { "58:0": { "single_push": { "action": "toggle" } } } } ], "offset": 0, "total": 2 } ``` -------------------------------- ### Start BTHome Learning Mode (mos) Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome/BTHomeControl Initiate BTHome learning mode for a specific input ID using a mos command. ```shell mos --port ${PORT} call BTHomeControl.StartLearning '{"input_id":2}' ``` -------------------------------- ### Shelly Core Quick Example Source: https://shelly-api-docs.shelly.cloud/gen2/Scripts/APIs/Shelly Control a switch, listen for button presses, and get temperature readings using the Shelly Core API. ```javascript // Control a switch Shelly.call("Switch.Set", {id: 0, on: true}, function(result, error_code) { if (error_code === 0) { console.log("Switch turned on"); } }); // Listen for button presses Shelly.addEventHandler(function(event) { if (event.component === "input:0" && event.info.event === "single_push") { console.log("Button pressed!"); // React to button press Shelly.call("Switch.Toggle", {id: 0}); } }); // Get temperature reading let temp = Shelly.getComponentStatus("temperature:0"); if (temp) { console.log("Temperature:", temp.tC, "°C"); } ``` -------------------------------- ### Zigbee.WriteAttr HTTP GET Response Source: https://shelly-api-docs.shelly.cloud/gen2/Integrations/Zigbee/ZigbeeRPC Example response for a Zigbee.WriteAttr HTTP GET request. ```json { "success": true, "status_str": "ZB_ZCL_STATUS_SUCCESS" } ``` -------------------------------- ### Zigbee.ReadAttr HTTP GET Response Source: https://shelly-api-docs.shelly.cloud/gen2/Integrations/Zigbee/ZigbeeRPC Example response for a Zigbee.ReadAttr HTTP GET request. ```json { "success": true, "type": 16, "value": "01", "len": 1 } ``` -------------------------------- ### Schedule.List Example Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Schedule Demonstrates how to retrieve a list of all configured schedule entries. Available via HTTP GET, Curl, and Mos. ```http http://192.168.33.1/rpc/Schedule.List ``` ```curl curl -X POST -d '{"id":1,"method":"Schedule.List"}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call Schedule.List ``` -------------------------------- ### Quick Example: Registering a status endpoint Source: https://shelly-api-docs.shelly.cloud/gen2/Scripts/APIs/HTTPServer This example demonstrates how to register a simple status endpoint that returns device information. ```javascript // Register a simple status endpoint Httpserver.registerEndpoint("status", function(request, response) { // Set response body response.body = JSON.stringify({ message: "Device is online", timestamp: Date.now(), uptime: Shelly.getUptimeMs() }); // Set response headers response.headers = [ ["Content-Type", "application/json"], ["X-Device-Id", Shelly.getDeviceInfo().id] ]; // Set HTTP status code response.code = 200; // Send the response response.send(); }); console.log("Endpoint registered at /script//status"); ``` -------------------------------- ### BluTrv.GetConfig HTTP GET Response Source: https://shelly-api-docs.shelly.cloud/gen2/Devices/Gen3/ShellyBluGwG3 Example response for BluTrv.GetConfig via HTTP GET. ```json { "id": 200, "addr": "28:68:47:f0:2a:b9", "name": null, "trv": "bthomedevice:200", "temp_sensors": [ "bthomesensor:200" ], "dw_sensors": [], "meta": null } ``` -------------------------------- ### Shelly.CheckForUpdate HTTP GET Response Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Shelly Example response for Shelly.CheckForUpdate via HTTP GET. ```json { "beta": { "version": "0.5.1", "build_id": "20210610-122509/g4bbec18" } } ``` -------------------------------- ### Schedule.Create Example Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Schedule Demonstrates how to create a new schedule entry. Requires a timespec and a list of calls to be executed at the specified time. Available via HTTP GET, Curl, and Mos. ```http http://192.168.33.1/rpc/Schedule.Create?timespec="0 0 22 * * FRI"&calls=[{"method":"Shelly.GetDeviceInfo"}] ``` ```curl curl -X POST -d '{"id":1,"method":"Schedule.Create","params":{"timespec":"0 0 22 * * FRI","calls":[{"method":"Shelly.GetDeviceInfo"}]}}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call Schedule.Create '{"timespec":"0 0 22 * * FRI","calls":[{"method":"Shelly.GetDeviceInfo"}]}' ``` -------------------------------- ### Shelly.DetectLocation HTTP GET Response Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Shelly Example response for Shelly.DetectLocation via HTTP GET. ```json { "tz": "Europe/Sofia", "lat": 42.67236, "lon": 23.38738 } ``` -------------------------------- ### Sys.GetConfig Response Example (Full) Source: https://shelly-api-docs.shelly.cloud/docs-ble/Devices/BLU_ZB/trv A comprehensive example of a Sys.GetConfig response, including all configuration parameters. ```JSON { "id": 1, "params": { "device": { "name": "" }, "location": { "lat": 0, "lon": 0 }, "ui": { "lock": false, "t_units": "C", "flip": false, "brightness": 7, "power_save": true }, "ble": { "interval_ms": 333, "beacon_count": 5 }, "cfg_rev": 1 } } ``` -------------------------------- ### Zigbee.StartNetworkSteering Example Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Zigbee Initiate network steering for the Zigbee component using these examples. This method does not take parameters. ```http http://192.168.33.1/rpc/Zigbee.StartNetworkSteering ``` ```curl curl -X POST -d '{"id":1,"method":"Zigbee.StartNetworkSteering"}' http://${SHELLY}/rpc ``` ```mos mos --port ${PORT} call Zigbee.StartNetworkSteering ``` -------------------------------- ### Shelly.ListTimezones HTTP GET Response Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Shelly Example response for Shelly.ListTimezones via HTTP GET. ```json { "timezones": [ "Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa", "Africa/Algiers", "Africa/Asmara", "Africa/Asmera" ], "offset": 0, "total": 597 } ``` -------------------------------- ### EMData.GetStatus HTTP GET Response Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/EMData Example response for an EMData.GetStatus HTTP GET request. ```json { "id": 0, "a_total_act_energy": 0, "a_total_act_ret_energy": 0, "b_total_act_energy": 0, "b_total_act_ret_energy": 0, "c_total_act_energy": 0, "c_total_act_ret_energy": 0, "total_act": 0, "total_act_ret": 0 } ``` -------------------------------- ### BTHome.StartDeviceDiscovery Source: https://shelly-api-docs.shelly.cloud/gen2/DynamicComponents/BTHome Starts the discovery process for BTHome devices. ```APIDOC ## BTHome.StartDeviceDiscovery ### Description Starts active scan for discovery of BTHome devices. During the scanning process, `device_discovered` events are emitted, providing information about the discovered device. Upon completion of the scanning process, a `discovery_done` event is dispatched. ### Method POST ### Endpoint /rpc/BTHome.StartDeviceDiscovery ### Parameters #### Request Body - **duration** (number) - Optional - Duration for the scan in seconds, default value is 30s. ### Request Example ```json { "duration": 60 } ``` ### Response #### Success Response (200) - **result** (null) - Indicates success. #### Response Example ```json { "result": null } ``` ``` -------------------------------- ### Webhook.Update HTTP GET Response Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Webhook Example response for a successful Webhook.Update HTTP GET request. ```json { "rev": 4 } ``` -------------------------------- ### Matter.GetSetupCode Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Matter Retrieves the Matter setup code, including a QR code and a manual code, for onboarding a new Matter device. ```APIDOC ## Matter.GetSetupCode ### Description Retrieves the Matter setup code, which includes a QR code and a manual code, necessary for onboarding a new Matter device. ### Method GET ### Endpoint /rpc/Matter.GetSetupCode ### Parameters This endpoint does not require any parameters. ### Response #### Success Response (200) - **qr_code** (string) - The QR code string for Matter device setup. - **manual_code** (string) - The manual code string for Matter device setup. #### Response Example ```json { "qr_code": "MT:00000O-O03.3QG5.000", "manual_code": "00576700759" } ``` ``` -------------------------------- ### Webhook.Create HTTP GET Response Source: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Webhook Example response for a successful Webhook.Create HTTP GET request. ```json { "id": 3, "rev": 1 } ```