This example demonstrates how to handle device-level settings in SinricPro.
SinricPro supports two types of settings:
- Configuration for this specific device
- Registered via:
device.on_setting(callback) - Examples: Tilt angle, speed, direction, auto-close timeout
- Callback signature:
async def callback(setting_id: str, value: Any) -> bool - Settings are configured per-device in the SinricPro portal
- Configuration for the module (dev board) itself
- Registered via:
sinric_pro.on_set_setting(callback) - Examples: WiFi retry count, log level, heartbeat interval
- Callback signature:
async def callback(setting_id: str, value: Any) -> bool
from sinricpro import SinricProBlinds
blinds = SinricProBlinds("your-device-id")
# Register device-level setting callback
async def on_device_setting(setting_id: str, value: Any) -> bool:
if setting_id == "tilt":
set_blinds_tilt(value)
return True
elif setting_id == "speed":
set_motor_speed(value)
return True
return False
blinds.on_setting(on_device_setting)Device settings can have different value types:
| Setting | Type | Example Values |
|---|---|---|
tilt |
Integer | 0-100 |
direction |
String | "up", "down" |
speed |
String | "slow", "normal", "fast" |
auto_close |
Boolean | true, false |
close_timeout |
Integer | 60-3600 (seconds) |
- Replace
YOUR_DEVICE_ID_HEREwith your actual device ID - Set environment variables or replace credentials:
export SINRICPRO_APP_KEY="your-app-key" export SINRICPRO_APP_SECRET="your-app-secret"
- Run the example:
python device_settings_example.py
Device settings are configured in the SinricPro portal:
- Go to sinric.pro
- Navigate to your device
- Click on "Settings" tab
- Add or modify settings with their IDs and values
- Save changes - the SDK will receive the new values via the callback
- Validate Values: Always validate setting values before applying them
- Type Checking: Check the value type matches what you expect
- Range Validation: Ensure numeric values are within valid ranges
- Return False on Error: Return
Falseif a setting cannot be applied - Persist Settings: Consider saving settings to non-volatile storage