Shelly Sensor Add-On
SensorAddon is a Service (similar to Webhook and Schedule), which manages the exposure of add-on peripherals. It uses SensorAddon as RPC namespace and provides the following methods:
SensorAddon.AddPeripheral
to add peripheralSensorAddon.RemovePeripheral
to remove peripheralSensorAddon.UpdatePeripheral
to update peripheral settingsSensorAddon.GetPeripherals
to list all peripheralsSensorAddon.OneWireScan
to scan one wire bus
SensorAddon allows the client to link add-on peripherals to Component instances, which in effect means that access to said peripherals is available through the standard Component interfaces: <Component>.GetStatus()
, <Component>.GetConfig()
, <Component>.SetConfig()
.
Ids of Components linked to add-on peripherals start from 100 and are limited to 199. Ids range [0..99]
is reserved for Components linked to "internal" peripherals.
Below is a list of supported add-on peripherals and the Component
types they can be linked to:
Peripheral type | Component type |
---|---|
ds18b20 | temperature |
dht22 | temperature, humidity |
digital_in | input |
analog_in | input |
voltmeter | voltmeter |
Changes in peripheral<->component links made with SensorAddon.AddPeripheral
, SensorAddon.RemovePeripheral
, SensorAddon.UpdatePeripheral
bond the firmware to spawn/destroy Component instances and therefore require reboot to apply.
Devices that support Shelly Sensor Addon
Addon configuration
Addon board can be enabled or disabled by setting device.addon_type
parameter in Sys config. To enable Shelly Sensor Addon, addon_type
must be set to "sensor"
. When Addon is enabled, device must be restarted and all related API will be accessible. To disable Shelly Sensor Addon, parameter device.addon_type
must be set to null
.
Methods
SensorAddon.AddPeripheral
SensorAddon.AddPeripheral
links an add-on peripheral to a Component
instance.
Request
Parameters:
Property | Type | Description |
---|---|---|
| string | Peripheral type |
| object | Attributes that the method takes |
Find more about the attrs properties in AddPeripheral attributes section
Response
List of JSON objects, where the object key designates the Component
key (in format <type>:<id>
, e.g. temperature:100
) to which the peripheral is linked.
Examples: SensorAddon.AddPeripheral Examples
SensorAddon.GetPeripherals
SensorAddon.GetPeripherals
returns the configured links between add-on peripherals and Components
.
Request
This method takes no parameters.
Response
List of JSON objects, one for each supported peripheral, where the object key designates the peripheral type ([ds18b20, dht22, digital_in, analog_in]
). The object body contains a nested list of JSON objects, where the object key designates the Component
keys (in format <type>:<id>
, e.g. temperature:100
) to which the peripheral is linked. The object body may contain additional attributes depending on the peripheral type.
Examples: SensorAddon.GetPeripherals Examples
SensorAddon.RemovePeripheral
Request
Property | Type | Description |
---|---|---|
| string | Linked |
Response
The result from this method is null
on success otherwise will return error information.
Examples: SensorAddon.RemovePeripheral Examples
SensorAddon.UpdatePeripheral
SensorAddon.UpdatePeripheral
serves to reconfigure peripheral-component links or reassign peripheral-specific properties.
Currently only ds18b20
peripheral has updateable attributes.
Request
Property | Type | Description |
---|---|---|
| string | Linked |
| object | Attributes that the method takes |
Find more about the attrs properties in UpdatePeripheral attributes section
Response
The result from this method is null
on success otherwise will return error information.
Examples: SensorAddon.UpdatePeripheral Examples
SensorAddon.OneWireScan
SensorAddon.OneWireScan
returns a list of discovered OneWire
devices.
This method returns an error if a dht22
peripheral is currently in use, as dht22
occupies the same GPIOs used for OneWire.
For now the only supported OneWire peripheral type is ds18b20
.
Request
This method takes no parameters.
Response
Attributes in the result:
Property | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| array of objects | List of all discovered devices on the bus
|
Examples: SensorAddon.OneWireScan Examples
AddPeripheral Attributes
Some peripherals require additional configuration attributes like one wire device address. For every SensorAddon peripheral, component cid
can be predefined or will be taken first available.
Property | Type | Description |
---|---|---|
| number | Id of component. (optional) |
| string | Address of DS18B20 sensor. (required for DS18B20 sensor) |
UpdatePeripheral Attributes
Property | Type | Description |
---|---|---|
| string | Address of DS18B20 sensor. (required for DS18B20 sensor) |
Examples
Enable / Disable SensorAddon examples
Enable SensorAddon
- Sys.SetConfig HTTP GET Request
- Sys.SetConfig Curl Request
- Sys.SetConfig Mos Request
http://192.168.33.1/rpc/Sys.SetConfig?config={"device":{"addon_type":"sensor"}}
curl -X POST -d '{"id":1,"method":"Sys.SetConfig","params":{"config":{"device":{"addon_type":"sensor"}}}}' http://${SHELLY}/rpc
mos --port ${PORT} call Sys.SetConfig '{"config":{"device":{"addon_type":"sensor"}}}'
Disable SensorAddon
- Sys.SetConfig HTTP GET Request
- Sys.SetConfig Curl Request
- Sys.SetConfig Mos Request
http://192.168.33.1/rpc/Sys.SetConfig?config={"device":{"addon_type":null}}
curl -X POST -d '{"id":1,"method":"Sys.SetConfig","params":{"config":{"device":{"addon_type":null}}}}' http://${SHELLY}/rpc
mos --port ${PORT} call Sys.SetConfig '{"config":{"device":{"addon_type":null}}}'
SensorAddon.AddPeripheral examples
Add Digital Input
- SensorAddon.AddPeripheral HTTP GET Request
- SensorAddon.AddPeripheral Curl Request
- SensorAddon.AddPeripheral Mos Request
http://192.168.33.1/rpc/SensorAddon.AddPeripheral?type="digital_in"&attrs={"cid":100}
curl -X POST -d '{"id":1,"method":"SensorAddon.AddPeripheral","params":{"type":"digital_in","attrs":{"cid":100}}}' http://${SHELLY}/rpc
mos --port ${PORT} call SensorAddon.AddPeripheral '{"type":"digital_in","attrs":{"cid":100}}'
Response
- SensorAddon.AddPeripheral HTTP GET Response
- SensorAddon.AddPeripheral Curl Response
- SensorAddon.AddPeripheral Mos Response
{
"input:100": {}
}
{
"id": 1,
"params": {
"input:100": {}
}
}
{
"input:100": {}
}
Add Analog Input
- SensorAddon.AddPeripheral HTTP GET Request
- SensorAddon.AddPeripheral Curl Request
- SensorAddon.AddPeripheral Mos Request
http://192.168.33.1/rpc/SensorAddon.AddPeripheral?type="analog_in"
curl -X POST -d '{"id":1,"method":"SensorAddon.AddPeripheral","params":{"type":"analog_in"}}' http://${SHELLY}/rpc
mos --port ${PORT} call SensorAddon.AddPeripheral '{"type":"analog_in"}'
Response
- SensorAddon.AddPeripheral HTTP GET Response
- SensorAddon.AddPeripheral Curl Response
- SensorAddon.AddPeripheral Mos Response
{
"input:100": {}
}
{
"id": 1,
"params": {
"input:100": {}
}
}
{
"input:100": {}
}
Add DS18B20 sensor
- SensorAddon.AddPeripheral HTTP GET Request
- SensorAddon.AddPeripheral Curl Request
- SensorAddon.AddPeripheral Mos Request
http://192.168.33.1/rpc/SensorAddon.AddPeripheral?type="ds18b20"&attrs={"cid":101,"addr":"11:22:33:44:55:66:77:88"}
curl -X POST -d '{"id":1,"method":"SensorAddon.AddPeripheral","params":{"type":"ds18b20","attrs":{"cid":101,"addr":"11:22:33:44:55:66:77:88"}}}' http://${SHELLY}/rpc
mos --port ${PORT} call SensorAddon.AddPeripheral '{"type":"ds18b20","attrs":{"cid":101,"addr":"11:22:33:44:55:66:77:88"}}'
Response
- SensorAddon.AddPeripheral HTTP GET Response
- SensorAddon.AddPeripheral Curl Response
- SensorAddon.AddPeripheral Mos Response
{
"temperature:101": {}
}
{
"id": 1,
"params": {
"temperature:101": {}
}
}
{
"temperature:101": {}
}
Add DHT22 sensor
- SensorAddon.AddPeripheral HTTP GET Request
- SensorAddon.AddPeripheral Curl Request
- SensorAddon.AddPeripheral Mos Request
http://192.168.33.1/rpc/SensorAddon.AddPeripheral?type="dht22"
curl -X POST -d '{"id":1,"method":"SensorAddon.AddPeripheral","params":{"type":"dht22"}}' http://${SHELLY}/rpc
mos --port ${PORT} call SensorAddon.AddPeripheral '{"type":"dht22"}'
Response
- SensorAddon.AddPeripheral HTTP GET Response
- SensorAddon.AddPeripheral Curl Response
- SensorAddon.AddPeripheral Mos Response
{
"humidity:100": {},
"temperature:100": {}
}
{
"id": 1,
"params": {
"humidity:100": {},
"temperature:100": {}
}
}
{
"humidity:100": {},
"temperature:100": {}
}
SensorAddon.RemovePeripheral example
- SensorAddon.RemovePeripheral HTTP GET Request
- SensorAddon.RemovePeripheral Curl Request
- SensorAddon.RemovePeripheral Mos Request
http://192.168.33.1/rpc/SensorAddon.RemovePeripheral?component="input:100"
curl -X POST -d '{"id":1,"method":"SensorAddon.RemovePeripheral","params":{"component":"input:100"}}' http://${SHELLY}/rpc
mos --port ${PORT} call SensorAddon.RemovePeripheral '{"component":"input:100"}'
Response
- SensorAddon.RemovePeripheral HTTP GET Response
- SensorAddon.RemovePeripheral Curl Response
- SensorAddon.RemovePeripheral Mos Response
null
{
"id": 1,
"params": null
}
null
SensorAddon.UpdatePeripheral example
- SensorAddon.UpdatePeripheral HTTP GET Request
- SensorAddon.UpdatePeripheral Curl Request
- SensorAddon.UpdatePeripheral Mos Request
http://192.168.33.1/rpc/SensorAddon.UpdatePeripheral?component="temperature:100"&attrs={"addr":"40:255:100:6:199:204:149:177"}
curl -X POST -d '{"id":1,"method":"SensorAddon.UpdatePeripheral","params":{"component":"temperature:100","attrs":{"addr":"40:255:100:6:199:204:149:177"}}}' http://${SHELLY}/rpc
mos --port ${PORT} call SensorAddon.UpdatePeripheral '{"component":"temperature:100","attrs":{"addr":"40:255:100:6:199:204:149:177"}}'
Response
- SensorAddon.UpdatePeripheral HTTP GET Response
- SensorAddon.UpdatePeripheral Curl Response
- SensorAddon.UpdatePeripheral Mos Response
null
{
"id": 1,
"params": null
}
null
SensorAddon.GetPeripherals example
- SensorAddon.GetPeripherals HTTP GET Request
- SensorAddon.GetPeripherals Curl Request
- SensorAddon.GetPeripherals Mos Request
http://192.168.33.1/rpc/SensorAddon.GetPeripherals
curl -X POST -d '{"id":1,"method":"SensorAddon.GetPeripherals"}' http://${SHELLY}/rpc
mos --port ${PORT} call SensorAddon.GetPeripherals
Response
- SensorAddon.GetPeripherals HTTP GET Response
- SensorAddon.GetPeripherals Curl Response
- SensorAddon.GetPeripherals Mos Response
{
"digital_in": {
"input:100": {}
},
"ds18b20": {
"temperature:100": {
"addr": "40:255:100:6:199:204:149:177"
}
},
"dht22": {},
"analog_in": {
"input:101": {}
}
}
{
"id": 1,
"params": {
"digital_in": {
"input:100": {}
},
"ds18b20": {
"temperature:100": {
"addr": "40:255:100:6:199:204:149:177"
}
},
"dht22": {},
"analog_in": {
"input:101": {}
}
}
}
{
"digital_in": {
"input:100": {}
},
"ds18b20": {
"temperature:100": {
"addr": "40:255:100:6:199:204:149:177"
}
},
"dht22": {},
"analog_in": {
"input:101": {}
}
}
SensorAddon.OneWireScan example
- SensorAddon.OneWireScan HTTP GET Request
- SensorAddon.OneWireScan Curl Request
- SensorAddon.OneWireScan Mos Request
http://192.168.33.1/rpc/SensorAddon.OneWireScan
curl -X POST -d '{"id":1,"method":"SensorAddon.OneWireScan"}' http://${SHELLY}/rpc
mos --port ${PORT} call SensorAddon.OneWireScan
Response
- SensorAddon.OneWireScan HTTP GET Response
- SensorAddon.OneWireScan Curl Response
- SensorAddon.OneWireScan Mos Response
{
"devices": [
{
"type": "ds18b20",
"addr": "40:255:100:6:199:204:149:177",
"component": null
},
{
"type": "ds18b20",
"addr": "40:255:100:6:199:204:149:178",
"component": "temperature:100"
}
]
}
{
"id": 1,
"params": {
"devices": [
{
"type": "ds18b20",
"addr": "40:255:100:6:199:204:149:177",
"component": null
},
{
"type": "ds18b20",
"addr": "40:255:100:6:199:204:149:178",
"component": "temperature:100"
}
]
}
}
{
"devices": [
{
"type": "ds18b20",
"addr": "40:255:100:6:199:204:149:177",
"component": null
},
{
"type": "ds18b20",
"addr": "40:255:100:6:199:204:149:178",
"component": "temperature:100"
}
]
}