Yandex Alice IoT Control in Mobile App
Smart home control via Yandex Alice — either Smart Home API (for devices in Yandex ecosystem), or Skills API (voice skill with own backend), or direct integration via Yandex IoT Core MQTT broker. For mobile app wanting to control devices through Alice, path almost always: OAuth 2.0 → Smart Home API → device control.
Smart Home API and Account Linking
OAuth authorization via https://oauth.yandex.ru/authorize with your app client_id. Scope: iot:view iot:control. After authorization app gets access token (lives 1 year) and refresh token.
Get user's device list:
GET https://api.iot.yandex.net/v1.0/user/info
Authorization: Bearer {access_token}
Response contains devices with capabilities and properties. Smart outlet returns:
{
"id": "device-id",
"name": "Smart outlet kitchen",
"type": "devices.types.socket",
"capabilities": [
{
"type": "devices.capabilities.on_off",
"state": {"instance": "on", "value": true}
}
]
}
Control — via Actions API:
func turnDevice(id: String, on: Bool) async throws {
let url = URL(string: "https://api.iot.yandex.net/v1.0/devices/actions")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let body: [String: Any] = [
"devices": [
[
"id": id,
"actions": [
[
"type": "devices.capabilities.on_off",
"state": ["instance": "on", "value": on]
]
]
]
]
]
request.httpBody = try JSONSerialization.data(withJSONObject: body)
let (_, response) = try await URLSession.shared.data(for: request)
// Check HTTP 207 Multi-Status — each device has its own status
}
Important API detail: Actions response — HTTP 207 with status array per device. Command can partially execute: one device turns on, another returns DEVICE_UNREACHABLE error. Parse each status mandatory.
Skills API: Voice Commands with Custom Logic
If devices not in Yandex ecosystem, need dialog (skill) in Yandex.Dialogs. Alice sends POST requests to developer webhook:
{
"request": {
"command": "turn on light in living room",
"nlu": {
"intents": {
"turn.on": {
"slots": {
"room": {"value": "living room"},
"device": {"value": "light"}
}
}
}
}
},
"session": {
"user": {"user_id": "yandex-user-id"}
}
}
Webhook responds within 5 seconds (hard timeout) with TTS text for Alice response and optionally buttons or map for screened devices.
For user account binding to skill — OAuth via skill settings form. After binding each webhook request contains access_token in session.user.access_token.
Yandex IoT Core: Direct MQTT Integration
For real-time instead of REST use Yandex IoT Core — managed MQTT broker. Devices publish to topics like $devices/{device_id}/events, mobile app subscribes and receives updates.
// Android, Paho MQTT
val client = MqttAsyncClient(
"ssl://mqtt.cloud.yandex.net:8883",
MqttClient.generateClientId(),
MemoryPersistence()
)
val options = MqttConnectOptions().apply {
userName = "unused" // For JWT authorization
password = generateJwt(serviceAccountId, privateKey).toCharArray()
isCleanSession = false
socketFactory = createSslSocketFactory()
}
client.connect(options).waitForCompletion()
client.subscribe("\$devices/+/events", 1) { topic, message ->
val deviceId = topic.split("/")[1]
val payload = String(message.payload)
handleDeviceEvent(deviceId, payload)
}
JWT for authorization generated with service account key via RS256 algorithm, 1-hour lifespan. Token refresh — separate coroutine with timer.
Special Notes for Russian Market
Smart Home API requires Yandex developer account with confirmed INN for skill publication and OAuth app registration with extended rights. For development testing regular account sufficient.
Integration timeline: Smart Home API into existing iOS or Android app: 1-2 weeks. Skills API with OAuth binding and webhook backend: 2-3 weeks. IoT Core MQTT integration with real devices: 3-4 weeks. Cost calculated individually.







