Bluetooth Low Energy
The Bluetooth Low Energy component is called BLE
. It handles bluetooth services of a device. The Bluetooth Low Energy component uses BLE
as RPC namespace and provides the methods:
BLE.GetConfig
to obtain the component's configurationBLE.SetConfig
to update the component's configurationBLE.GetStatus
to obtain the component's status
It uses the key ble
when enumerated in objects including multiple component payloads, like Shelly.GetStatus
.
Observer
Observer
is obsoleted as of 1.5.0-beta1
. Since 1.5.0-beta1
observer functionality is automatic using the Enhanced Scan Manager.
To support Shelly Bluetooth peripheral devices, the BLE component can act as a perpetual BT LE Observer. When enabled via the observer.enable
configuration flag, the device will run a constant passive Bluetooth LE scan. The observer functionality is applicable for the CloudRelay and BTHome features.
Enabling the observer relay functionality might impact BLE advertisement scanner in scripts. A requested interval and window for scanning in scripting might get adjusted to allow for the coexistence of both functionalities.
Observer is not applicable for battery-operated devices.
CloudRelay
CloudRelay
is a feature of the BLE
component supporting Shelly BLU devices managed by the Shelly Cloud relaying received advertisement packets to Shelly Cloud service, to enable scene triggers. It publicly exports List
and ListInfos
methods, while other functions are internal only. Prior to 1.5.0-beta1
CloudRelay
functionality required the Bluetooth Observer
to be enabled. Since 1.5.0-beta1
necessary functionality is enabled automatically if needed.
Bluetooth Scan
Shelly devices hardware supports only one running Bluetooth scan at a given moment, but several device features require using such scan and a scan manager is needed. The scan manager serves as an arbiter of the scan requests and clients can request receiving the results of the scan. Currently Bluetooth Cloud Relay, BTHome and the Scripts BLE Scanner can act as Scan Manager clients. The Scan Manager was rewritten and improved since 1.5.0-beta1
. The Scan Manager interface itself is not exposed externally but the two implementaions introduce some differences in the behavior of clients.
ScanManager
Effective prior to 1.5.0-beta1
This Scan Manager is based on the concept of scan owner
. The first client requesting a Bluettoth scan becomes the owner
and further requests will fail, but the clients can subscribe for events of the currently running scan. The owner
is cleared when the scan ends. The owner
also determines the scan options and they cannot be changed until ownership is released. With this Scan Manager Cloud Relay
and BTHome
share the scan with the Observer functionality and Scripts
compete for the scan.
Enhanced Scan Manager
Effective since 1.5.0-beta1
This Scan Manager effectively is the owner of the scan and it starts and stops it as needed. Clients request delivery of scan events and the manager keeps track and tries to satisfy all requests, starting a scan and merging the options supplied with each request effectively applying the most aggressive combination. A client needs to submit a scan request and cannot just subscribe to existing scan. With this Scan Manager Cloud Relay
and BTHome
transparently for the user submit scan requests when needed and share the same scan options. In Scripts
each script can submit a scan request with the BLE.Scanner.Start method and receive scan events after subscribing. The Scan Manager will adjust the scan parameters according to the options supplied and its merge algorithm. In some cases if there are more than one scan requests the effective scan options may be different from the requested.
Scan Options
Property | Type | Description |
---|---|---|
| number | duration of the scan in ms, |
| boolean | start an active scan if |
| number | scan interval in ms. Defaults to 241. |
| number | scan window in ms. Defaults to 61 in Scripts. |
since 1.5.0-beta1
Property | Type | Description |
---|---|---|
| number | RSSI threshold for delivered scan results, filtered to those with RSSI greater than the threshold. Defaults to |
Methods
BLE.SetConfig
Properties:
Property | Type | Description |
---|---|---|
| object | Configuration that the method takes |
Find more about the config properties in config section
BLE.GetConfig
Find the BLE.GetConfig response properties in config section
BLE.GetStatus
Find more about the status response properties in status section
BLE.CloudRelay.List
Returns a list of MAC adresses for the devices managed by the Cloud.
Request:
The method doesn't take any paramters.
Response:
Property | Type | Description |
---|---|---|
| number | Internal revision of the list |
| array of strings | The list of MAC addresses for the managed devices |
BLE.CloudRelay.ListInfos
Returns extended information about data received from the devices managed by the Cloud. The response is paginated.
Request:
Property | Type | Description |
---|---|---|
| number | optional offset of the first item to return, defaults to |
Response:
Property | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| number | Unix timestamp of the repsonse | ||||||||||||||||||||||||
| number | Offset in the list of the first item in the current page | ||||||||||||||||||||||||
| number | Number of items in the current page | ||||||||||||||||||||||||
| number | Total number of items in the list | ||||||||||||||||||||||||
| array of objects |
|
BLE.StartBluTrvAssociations
Available only on devices that support BLUTRV devices. Currently Shelly BLU Gateway Gen3
Associate BLUTRV device with the gateway or associate already associated BLUTRV device with BTHome temperature and/or window sensors (BLUHT, BLUDW) which can either be existing or will be added.
Request:
Property | Type | Description |
---|---|---|
| number | optional If not specified discover and associate new BLUTRV device with the gateway or Id of the BluTrv component instance to perform sensor associations (device doesn't need to be in pairing mode in this case) |
| number | optional Max discovery duration, seconds. Defaults to 30 if not provided. |
| number | optional Defaults to -80 if not provided. |
Response:
null
on success or error
StartBluTrvAssociations
will add a status entry when active and will emit status change notifications on start and end.
AssociationsStarted
status change:
{"blutrv_assoc":{"duration":30,"started_at":1729259344}}
AssociationsEnded
status change:
{"blutrv_assoc":null}
Configuration
The configuration of the Bluetooth Low Energy component shows whether the bluetooth connection is enabled.
Property | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
| boolean | True if bluetooth is enabled, false otherwise | ||||||
| object | Configuration of the rpc service
|
as of 1.6.0-beta1
Property | Type | Description |
---|---|---|
| boolean | When set to |
Obsoleted as of 1.5.0-beta1
Property | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
| object | Configuration of the BT LE observer
|
Currently only rpc service is implemented, but a global enable
flag is maintained for possible other future BLE functionality implementation. If either of the enable
flags is set to false
the device is not advertised. Prior to 1.6.0-beta1
changing configuration requires restart. Since restart is not required, see also note above.
Runtime change of bluetooth status introduced with 1.6.0-beta1
is handled transperantly in BTHome
, Cloud Relay
and Scirpts
stopping and starting initiated bluetooth scans as needed.
Status
Property | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
| object | BluTrvAssociations information, present only when associations are active
|
Examples
BLE.GetStatus example
- BLE.GetStatus HTTP GET Request
- BLE.GetStatus Curl Request
- BLE.GetStatus Mos Request
http://192.168.33.1/rpc/BLE.GetStatus
curl -X POST -d '{"id":1,"method":"BLE.GetStatus"}' http://${SHELLY}/rpc
mos --port ${PORT} call BLE.GetStatus
Response
- BLE.GetStatus HTTP GET Response
- BLE.GetStatus Curl Response
- BLE.GetStatus Mos Response
{}
{
"id": 1,
"src": "shellyplus1pm-441793ce3f08",
"params": {}
}
{}
BLE.GetConfig example
- BLE.GetConfig HTTP GET Request
- BLE.GetConfig Curl Request
- BLE.GetConfig Mos Request
http://192.168.33.1/rpc/BLE.GetConfig
curl -X POST -d '{"id":1,"method":"BLE.GetConfig"}' http://${SHELLY}/rpc
mos --port ${PORT} call BLE.GetConfig
Response
- BLE.GetConfig HTTP GET Response
- BLE.GetConfig Curl Response
- BLE.GetConfig Mos Response
{
"enable": true,
"rpc": {
"enable": true
}
}
{
"id": 1,
"src": "shellyplus1pm-441793ce3f08",
"params": {
"enable": true,
"rpc": {
"enable": true
}
}
}
{
"enable": true,
"rpc": {
"enable": true
}
}
BLE.SetConfig example
- BLE.SetConfig HTTP GET Request
- BLE.SetConfig Curl Request
- BLE.SetConfig Mos Request
http://192.168.33.1/rpc/BLE.SetConfig?config={"enable":true,"rpc":{"enable":true}}
curl -X POST -d '{"id":1,"method":"BLE.SetConfig","params":{"config":{"enable":true,"rpc":{"enable":true}}}}' http://${SHELLY}/rpc
mos --port ${PORT} call BLE.SetConfig '{"config":{"enable":true,"rpc":{"enable":true}}}'
Response
- BLE.SetConfig HTTP GET Response
- BLE.SetConfig Curl Response
- BLE.SetConfig Mos Response
{
"restart_required": true
}
{
"id": 1,
"src": "shellyplus1pm-441793ce3f08",
"params": {
"restart_required": true
}
}
{
"restart_required": true
}
BLE.CloudRelay.List example
- BLE.CloudRelay.List HTTP GET Request
- BLE.CloudRelay.List Curl Request
- BLE.CloudRelay.List Mos Request
http://192.168.33.1/rpc/BLE.CloudRelay.List
curl -X POST -d '{"id":1,"method":"BLE.CloudRelay.List"}' http://${SHELLY}/rpc
mos --port ${PORT} call BLE.CloudRelay.List
Response
- BLE.CloudRelay.List HTTP GET Response
- BLE.CloudRelay.List Curl Response
- BLE.CloudRelay.List Mos Response
{
"rev": 8,
"addrs": [
"5c:c7:c1:f0:db:60"
]
}
{
"id": 1,
"src": "shellyplus1pm-441793ce3f08",
"params": {
"rev": 8,
"addrs": [
"5c:c7:c1:f0:db:60"
]
}
}
{
"rev": 8,
"addrs": [
"5c:c7:c1:f0:db:60"
]
}
BLE.CloudRelay.ListInfos example
- BLE.CloudRelay.ListInfos HTTP GET Request
- BLE.CloudRelay.ListInfos Curl Request
- BLE.CloudRelay.ListInfos Mos Request
http://192.168.33.1/rpc/BLE.CloudRelay.ListInfos
curl -X POST -d '{"id":1,"method":"BLE.CloudRelay.ListInfos"}' http://${SHELLY}/rpc
mos --port ${PORT} call BLE.CloudRelay.ListInfos
Response
- BLE.CloudRelay.ListInfos HTTP GET Response
- BLE.CloudRelay.ListInfos Curl Response
- BLE.CloudRelay.ListInfos Mos Response
{
"ts": 1732804839,
"offset": 0,
"count": 1,
"total": 1,
"devices": [
{
"5c:c7:c1:f0:db:60": {
"name": null,
"model": 0,
"sdata": {
"fcd2": "RAAVAWQ6AQ=="
},
"mdata": {},
"last_seen": 1732804835
}
}
]
}
{
"id": 1,
"src": "shellyplus1pm-441793ce3f08",
"params": {
"ts": 1732804839,
"offset": 0,
"count": 1,
"total": 1,
"devices": [
{
"5c:c7:c1:f0:db:60": {
"name": null,
"model": 0,
"sdata": {
"fcd2": "RAAVAWQ6AQ=="
},
"mdata": {},
"last_seen": 1732804835
}
}
]
}
}
{
"ts": 1732804839,
"offset": 0,
"count": 1,
"total": 1,
"devices": [
{
"5c:c7:c1:f0:db:60": {
"name": null,
"model": 0,
"sdata": {
"fcd2": "RAAVAWQ6AQ=="
},
"mdata": {},
"last_seen": 1732804835
}
}
]
}
BLE.StartBluTrvAssociations example
- BLE.StartBluTrvAssociations HTTP GET Request
- BLE.StartBluTrvAssociations Curl Request
- BLE.StartBluTrvAssociations Mos Request
http://192.168.33.1/rpc/BLE.StartBluTrvAssociations?blutrv_id=200&duration=120&rssi_thr=-80
curl -X POST -d '{"id":1,"method":"BLE.StartBluTrvAssociations","params":{"blutrv_id":200,"duration":120,"rssi_thr":-80}}' http://${SHELLY}/rpc
mos --port ${PORT} call BLE.StartBluTrvAssociations '{"blutrv_id":200,"duration":120,"rssi_thr":-80}'
Response
- BLE.StartBluTrvAssociations HTTP GET Response
- BLE.StartBluTrvAssociations Curl Response
- BLE.StartBluTrvAssociations Mos Response
null
{
"id": 1,
"src": "shellyblugwg3-3030f9ed6698",
"params": null
}
null