能否从Fulfillment Service中获取已配置的Google Smart Home房间/位置信息?
Great question! I’ve built several Google Smart Home integrations, so I can confirm this is totally possible—here’s how it works:
You’ll get room context in
action.devices.EXECUTErequests
When a user issues a room-targeted command like "Turn off all devices in my office", Google includes the room/location details directly in the EXECUTE request payload. Look for thecontextobject, which contains alocationfield with the user-configured room name.Here’s a simplified example of what that payload might look like:
{ "requestId": "abc123", "inputs": [ { "intent": "action.devices.EXECUTE", "payload": { "commands": [ { "devices": [{"id": "my-office-lamp-01"}], "execution": [{"command": "action.devices.commands.OnOff", "params": {"on": false}}] } ] }, "context": { "location": { "name": "Office", "roomHint": "Office" } } } ] }The
roomHintfield is your go-to here—it’s the exact room name the user set up in their Google Home app.SYNC requests don’t include user-assigned rooms (but you can pre-set defaults)
Theaction.devices.SYNCintent is only for listing your available devices to Google. While you can add aroomHintattribute to your device objects in the SYNC response to suggest a default room, users can override this in the app. To get the actual room the user chose, always rely on the EXECUTE request context.A few quick tips
- Room names are user-defined, so they might be inconsistent (e.g., "Office", "Home Office", "Work Nook")—build flexible string matching into your fulfillment logic if you need to map rooms to internal systems.
- If you want to persist room associations for devices, cache the
roomHintvalue from EXECUTE requests linked to each device ID.
内容的提问来源于stack exchange,提问作者Andrew Eers

