### Device Instance Example Source: https://developers.google.com/assistant/sdk/reference/device-registration/model-and-instance-schemas.html An example of a concrete device instance configuration. Fields must start with a letter or number. ```json { "id": "my_led_1", "model_id": "my-devices-project-prototype-light-v1", "nickname": "My Assistant Light", "client_type": "SDK_LIBRARY" } ``` -------------------------------- ### Start Device Command Source: https://developers.google.com/assistant/sdk/reference/traits/startstop Use this command to start a device. Set 'start' to true in the params. ```json { "command": "action.devices.commands.StartStop", "params": { "start": true } } ``` -------------------------------- ### Install Google Assistant SDK Samples Source: https://developers.google.com/assistant/sdk/guides/library/python/embed/install-sample Installs the Google Assistant SDK with sample code support using pip. ```bash python -m pip install --upgrade google-assistant-sdk[samples]==0.5.1 ``` -------------------------------- ### Example Handlers for Brightness and Color Source: https://developers.google.com/assistant/sdk/guides/service/python/extend/add-trait-and-handler These examples demonstrate how to implement handlers for the BrightnessAbsolute and ColorAbsolute commands, including conditional logic based on the command parameters. ```python @device_handler.command('action.devices.commands.BrightnessAbsolute') def brightness_check(brightness): if brightness > 50: logging.info('brightness > 50') else: logging.info('brightness <= 50') @device_handler.command('action.devices.commands.ColorAbsolute') def color(color): if color.get('name') == "blue": logging.info('color is blue') else: logging.info('color is not blue') ``` -------------------------------- ### Configure GPIO and Handle OnOff Command Source: https://developers.google.com/assistant/sdk/guides/service/python/extend/handle-device-commands Configure the GPIO pin mode and setup, then implement the `OnOff` command handler. This example uses BCM numbering and controls GPIO pin 25. The `onoff` function toggles the pin state based on the command. ```python device_handler = device_helpers.DeviceRequestHandler(device_id) GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.OUT, initial=GPIO.LOW) @device_handler.command('action.devices.commands.OnOff') def onoff(on): if on: logging.info('Turning device on') GPIO.output(25, 1) else: logging.info('Turning device off') GPIO.output(25, 0) ``` -------------------------------- ### Example: Brightness Trait Handler Source: https://developers.google.com/assistant/sdk/guides/library/python/extend/add-trait-and-handler This example demonstrates how to handle the `BrightnessAbsolute` command, checking if the brightness level is above 50%. ```python if command == "action.devices.commands.BrightnessAbsolute": if params['brightness']: if params['brightness'] > 50: print('brightness > 50') else: print('brightness <= 50') ``` -------------------------------- ### Install SDK System Dependencies Source: https://developers.google.com/assistant/sdk/guides/library/python/embed/install-sample Installs essential system libraries required by the Google Assistant SDK package. Run this before installing the Python package. ```bash sudo apt-get install portaudio19-dev libffi-dev libssl-dev libmpg123-dev ``` -------------------------------- ### Device Model Schema Example Source: https://developers.google.com/assistant/sdk/reference/device-registration/model-and-instance-schemas.html This example demonstrates the structure of a device model, including project ID, model ID, manifest, device type, and supported traits. ```json { "project_id": "my-devices-project", "device_model_id": "my-devices-project-prototype-light-v1", "manifest": { "manufacturer": "Assistant SDK developer", "product_name": "Assistant SDK light", "device_description": "Assistant SDK light device" }, "device_type": "action.devices.types.LIGHT", "traits": ["action.devices.traits.OnOff"] } ``` -------------------------------- ### Install Google Assistant SDK with Samples Source: https://developers.google.com/assistant/sdk/guides/service/python/embed/install-sample Installs the latest version of the Google Assistant SDK package, including sample code, into the active Python virtual environment using pip. ```bash python -m pip install --upgrade google-assistant-sdk[samples] ``` -------------------------------- ### StartStop Command Source: https://developers.google.com/assistant/sdk/reference/traits/startstop This command is used to start or stop a device. It requires a boolean parameter 'start' to indicate the desired action. ```APIDOC ## action.devices.commands.StartStop ### Description Start or stop the device. ### Parameters #### Parameters - **start** (Boolean) - Required. True to start device operation, false to stop. - **zone** (String) - Indicates zone in which to start running. - **multipleZones** (Array) - Indicates two or more zones in which to start running. Will be set instead of `zone` parameter. - **_item** (String) - Name of a zone to start device in. ``` -------------------------------- ### Install Authorization Tool Source: https://developers.google.com/assistant/sdk/guides/library/python/embed/install-sample Installs or updates the necessary tool for generating OAuth 2.0 credentials for the Assistant SDK. ```bash python -m pip install --upgrade google-auth-oauthlib[tool] ``` -------------------------------- ### Install Google Assistant Library Source: https://developers.google.com/assistant/sdk/guides/library/python/embed/install-sample Installs the Google Assistant Library package using pip within the activated virtual environment. ```bash python -m pip install --upgrade google-assistant-library==1.0.1 ``` -------------------------------- ### StartStop Trait State: Running Example Source: https://developers.google.com/assistant/sdk/reference/traits/startstop Indicates that a device is running and not paused. ```json { "isRunning": true, "isPaused": false } ``` -------------------------------- ### action.devices.commands.StartStop Source: https://developers.google.com/assistant/sdk/reference/traits/startstop This command is used to start or stop a device. It accepts a 'start' parameter to indicate the desired state and an optional 'zone' or 'multipleZones' parameter to specify the location. ```APIDOC ## action.devices.commands.StartStop ### Description Starts or stops a device. ### Parameters #### Request Body - **command** (string) - Required - The command name, which is "action.devices.commands.StartStop". - **params** (object) - Required - Parameters for the command. - **start** (boolean) - Required - True to start the device, false to stop it. - **zone** (string) - Optional - The zone where the device is located. - **multipleZones** (array of strings) - Optional - A list of zones where the device is located. ### Request Example ```json { "command": "action.devices.commands.StartStop", "params": { "start": true } } ``` ### Request Example (with zone) ```json { "command": "action.devices.commands.StartStop", "params": { "start": true, "zone": "office" } } ``` ### Request Example (with multiple zones) ```json { "command": "action.devices.commands.StartStop", "params": { "start": true, "multipleZones": [ "kitchen", "dining room", "living room" ] } } ``` ``` -------------------------------- ### Start Device in Specific Zone Source: https://developers.google.com/assistant/sdk/reference/traits/startstop To start a device in a specific zone, include the 'zone' parameter with the zone name. ```json { "command": "action.devices.commands.StartStop", "params": { "start": true, "zone": "office" } } ``` -------------------------------- ### Run the Google Assistant SDK Sample Source: https://developers.google.com/assistant/sdk/guides/service/python/embed/run-sample Execute this command to start the sample and make queries. Replace placeholders with your Google Cloud project ID and device model name. The first run generates a device instance ID. ```bash googlesamples-assistant-pushtotalk --project-id my-dev-project --device-model-id my-model ``` -------------------------------- ### Install SDK System Dependencies Source: https://developers.google.com/assistant/sdk/guides/service/python/embed/install-sample Installs necessary system libraries required by the Google Assistant SDK package, such as portaudio, libffi, and OpenSSL development headers. ```bash sudo apt-get install portaudio19-dev libffi-dev libssl-dev ``` -------------------------------- ### Example: Color Trait Handler Source: https://developers.google.com/assistant/sdk/guides/library/python/extend/add-trait-and-handler This example shows how to handle the `ColorAbsolute` command, checking if the specified color is blue. ```python if command == "action.devices.commands.ColorAbsolute": if params['color']: if params['color'].get('name') == "blue": print('The color is blue.') else: print('The color is not blue.') ``` -------------------------------- ### Example: Review Intent with Structured Place Data Source: https://developers.google.com/assistant/sdk/reference/custom-actions/query-pattern-types This example demonstrates how to define an intent for writing reviews, specifying a `SchemaOrg_Place` parameter and configuring `deviceExecution` to return structured place data. ```json ... "intent": { "name": "com.example.intents.Review", "parameters": [ { "name": "place", "type": "SchemaOrg_Place" } ], "trigger": { "queryPatterns": [ "write review for $SchemaOrg_Place:place" ] } }, ... "deviceExecution": { "command": "com.example.commands.Review", "params": { "placeName": "$place.structured" } } ... ``` -------------------------------- ### Start Device in Multiple Zones Source: https://developers.google.com/assistant/sdk/reference/traits/startstop To start a device in multiple zones simultaneously, use the 'multipleZones' parameter with an array of zone names. ```json { "command": "action.devices.commands.StartStop", "params": { "start": true, "multipleZones": [ "kitchen", "dining room", "living room" ] } } ``` -------------------------------- ### Assistant.start Source: https://developers.google.com/assistant/sdk/reference/library/python Initiates the Assistant, enabling it to listen for the hotword and process audio input. This method also starts associated services like timers and alarms. It can only be called once. ```APIDOC ## Assistant.start ### Description Starts the Assistant, which includes listening for a hotword. Once `start()` is called, the Assistant will begin processing data from the ‘default’ ALSA audio source, listening for the hotword. This will also start other services provided by the Assistant, such as timers/alarms. This method can only be called once. Once called, the Assistant will continue to run until `__exit__` is called. ### Returns A queue of events that notify of changes to the Assistant state. ### Return type google.assistant.event.IterableEventQueue ``` -------------------------------- ### Start the Google Assistant Source: https://developers.google.com/assistant/sdk/reference/library/python Call the `start` method to begin processing audio, listening for the hotword, and initiating other Assistant services. This method can only be called once and the Assistant will run until `__exit__` is called. ```python assistant.start() ``` -------------------------------- ### StartStop Trait State: Running in Zones Example Source: https://developers.google.com/assistant/sdk/reference/traits/startstop Indicates that a device is running in specific zones and is not paused. ```json { "isRunning": true, "isPaused": false, "activeZones": [ "kitchen", "living room" ] } ``` -------------------------------- ### Run Device Code Source: https://developers.google.com/assistant/sdk/guides/service/python/extend/custom-actions Execute your Python device code to start the device handler and listen for commands. ```bash python pushtotalk.py ``` -------------------------------- ### Example Conversation Flow Source: https://developers.google.com/assistant/sdk/reference/library/python A conversation with the Assistant can involve one or more turns to achieve a desired final result. This example illustrates a simple query and response, followed by a more complex timer-setting interaction. ```text "What time is it?" -> "The time is 6:24 PM" OR "Set a timer" -> "Okay, for how long?" -> "5 minutes" -> "Sure, 5 minutes, starting now!" ``` -------------------------------- ### Authorize Application and Get Code Source: https://developers.google.com/assistant/sdk/reference/device-registration/register-device-manual Paste the provided URL into a browser to authorize the application and obtain an authorization code. ```bash Please visit this URL to authorize this application: https://... ``` ```bash Enter the authorization code: ``` -------------------------------- ### Example SSH Connection and Password Source: https://developers.google.com/assistant/sdk/guides/service/python/embed/setup-headless This example demonstrates a typical SSH connection to a Raspberry Pi with the IP address 192.168.1.101, showing the prompt for the default 'raspberry' password. ```bash $ ssh pi@192.168.1.101 password: raspberry ``` -------------------------------- ### Obtain Access Token with OAuthlib Tool Source: https://developers.google.com/assistant/sdk/reference/device-registration/register-device-manual Use the `google-oauthlib-tool` to get an access token for registering devices. You need your client secrets file. ```bash google-oauthlib-tool --scope https://www.googleapis.com/auth/assistant-sdk-prototype \ --headless --client-secrets /path/to/client_secret_client-id.json ``` -------------------------------- ### StartStop Trait Attributes Example Source: https://developers.google.com/assistant/sdk/reference/traits/startstop Defines attributes for a device that supports pausing and operating in multiple zones. ```json { "pausable": true, "availableZones": [ "kitchen", "living room", "office", "bedroom" ] } ``` -------------------------------- ### Get a Device Instance Source: https://developers.google.com/assistant/sdk/reference/device-registration/register-device-manual Retrieves the details of a specific device instance using its project ID and device ID. ```APIDOC ## GET /v1alpha2/projects/{project_id}/devices/{id} ### Description Retrieves a specific device instance. ### Method GET ### Endpoint https://embeddedassistant.googleapis.com/v1alpha2/projects//devices/ ### Parameters #### Path Parameters - **project_id** (string) - Required - The project ID associated with the device model. - **id** (string) - Required - The unique identifier of the device. #### Headers - **Authorization** (string) - Required - Bearer token for authentication (e.g., `Bearer $ACCESSTOKEN`). - **Content-Type** (string) - Required - `application/json` ### Response #### Success Response (200) - **(JSON)** - The JSON representation of the device instance. ``` -------------------------------- ### Get Device Information Source: https://developers.google.com/assistant/sdk/reference/device-registration/device-tool Use this command to retrieve all fields for a specific device model or instance. You must provide either the --model or --device flag. ```bash googlesamples-assistant-devicetool get --help ``` -------------------------------- ### Clone the Google Assistant SDK Python samples Source: https://developers.google.com/assistant/sdk/guides/library/python/extend/handle-device-commands Get the source code for the Google Assistant SDK Python samples to begin your project. This repository contains the hotword sample. ```bash git clone https://github.com/googlesamples/assistant-sdk-python ``` -------------------------------- ### Converse Request and Response Sequence Example Source: https://developers.google.com/assistant/sdk/reference/rpc/google.assistant.embedded.v1alpha1 Illustrates a typical sequence of gRPC messages for a single conversational turn, including initial configuration, audio input, end-of-utterance events, and audio output. ```text ConverseRequest.config ConverseRequest.audio_in ConverseRequest.audio_in ConverseRequest.audio_in ConverseRequest.audio_in ConverseResponse.event_type.END_OF_UTTERANCE ConverseResponse.result.microphone_mode.DIALOG_FOLLOW_ON ConverseResponse.audio_out ConverseResponse.audio_out ConverseResponse.audio_out ``` -------------------------------- ### Sample EXECUTE Request for ColorTemperature Source: https://developers.google.com/assistant/sdk/reference/traits/colortemperature An example of an EXECUTE request to adjust a device's color temperature to soft white (2700 Kelvin). ```APIDOC ## Sample EXECUTE Request ### Description This sample demonstrates how to send an EXECUTE request to change a device's color to "soft white" using a specific temperature. ### Request Example ```json { "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "inputs": [ { "intent": "action.devices.EXECUTE", "payload": { "commands": [ { "devices": [ { "id": "123", "customData": { "fooValue": 74, "barValue": true, "bazValue": "sheepdip" } } ], "execution": [ { "command": "action.devices.commands.ColorAbsolute", "params": { "color": { "name": "soft white", "temperature": 2700 } } } ] } ] } } ] } ``` ``` -------------------------------- ### Initialize GPIO Pins Source: https://developers.google.com/assistant/sdk/guides/library/python/extend/handle-device-commands Set the GPIO mode and initialize a specific output pin to a low logic state before processing events. This example uses BCM numbering for GPIO pins. ```python with Assistant(credentials, device_model_id) as assistant: events = assistant.start() device_id = assistant.device_id print('device_model_id:', device_model_id) print('device_id:', device_id + '\n') GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.OUT, initial=GPIO.LOW) ... ``` -------------------------------- ### Get a Device Instance using cURL Source: https://developers.google.com/assistant/sdk/reference/device-registration/register-device-manual Use this command to retrieve a specific device instance by its ID. Replace `project_id` and `id` with your actual project ID and device ID, and ensure `ACCESSTOKEN` is set. ```bash curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/id ``` -------------------------------- ### Modify Device Action Handler in Python Source: https://developers.google.com/assistant/sdk/guides/library/python/extend/custom-actions Add a handler for your custom device action in the `hotword.py` file. This example demonstrates how to handle a 'BlinkLight' command with a specified number of blinks. Uncomment GPIO instructions if using a Raspberry Pi with an external LED. ```python import time # Add this to the imports near the top of the file ... if event.type == EventType.ON_DEVICE_ACTION: for command, params in event.actions: print('Do command', command, 'with params', str(params)) # Add the following lines after the existing line above: if command == "com.example.commands.BlinkLight": number = int( params['number'] ) for i in range(int(number)): print('Device is blinking.') # GPIO.output(25, 1) time.sleep(1) # GPIO.output(25, 0) time.sleep(1) ``` -------------------------------- ### Navigate to Sample Directory Source: https://developers.google.com/assistant/sdk/guides/service/python/extend/handle-device-commands Change the current directory to the gRPC samples for the Assistant SDK. ```bash cd assistant-sdk-python/google-assistant-sdk/grpc ``` -------------------------------- ### Assistant Event Stream Examples Source: https://developers.google.com/assistant/sdk/reference/library/python Once started, the Assistant generates a stream of events to indicate its current state. These events provide information about conversation turns, speech recognition, responses, and more. ```python ON_CONVERSATION_TURN_STARTED ON_END_OF_UTTERANCE ON_RECOGNIZING_SPEECH_FINISHED: {'text': 'what time is it'} ON_RESPONDING_STARTED: {'is_error_response': False} ON_RESPONDING_FINISHED ON_CONVERSATION_TURN_FINISHED: {'with_follow_on_turn': False} ``` -------------------------------- ### Registration Tool Options Source: https://developers.google.com/assistant/sdk/reference/device-registration/device-tool This output details the command-line options available for the device registration tool, including project ID, client secrets, and credentials. ```bash Usage: googlesamples-assistant-devicetool [OPTIONS] COMMAND [ARGS]... Options: --project-id TEXT Enter the Google Developer Project ID that you want to use with the registration tool. If you don't use this flag, the tool will use the project listed in the client_secret_.json file you specify with the --client-secrets flag. --client-secrets TEXT Enter the path and filename for the client_secret_.json file you downloaded from your developer project. This file is used to infer the Google Developer Project ID if it was not provided with the --project-id flag. If the --project-id flag and this flag are not used, the tool will look for this file in the current directory (by searching for a file named after the client_id stored in the credentials file). --verbose Shows detailed JSON response --api-endpoint TEXT Hostname for the Google Assistant API. Do not use this flag unless explicitly instructed. [default: embeddedassistant.googleapis.com] --credentials TEXT File location of the generated credentials file. The google-oauthlib-tool generates this file after authorizing the user with the client_secret_.json file. This credentials file authorizes access to the Google Assistant API. You can use this flag if the credentials were generated in a location that is different than the default. [default: /home/pi/.config/google-oauthlib- tool/credentials.json] --help Show this message and exit. Commands: delete Delete given device model or instance. get Gets all of the information (fields) for a... list Lists all of the device models and/or... register Registers a device model and instance. register-device Registers a device instance under an existing... register-model Registers a device model. ``` -------------------------------- ### Run the hotword sample Source: https://developers.google.com/assistant/sdk/guides/library/python/extend/handle-device-commands Execute the hotword sample to test device command handling. Ensure your device model ID is correctly specified. ```bash googlesamples-assistant-hotword --device-model-id my-model ``` -------------------------------- ### Run Push-to-Talk Sample Source: https://developers.google.com/assistant/sdk/guides/service/python/extend/handle-device-commands Execute the sample to test Google Assistant command responses. This command initiates the push-to-talk sample. ```bash googlesamples-assistant-pushtotalk ``` -------------------------------- ### Navigate to gRPC Samples Directory Source: https://developers.google.com/assistant/sdk/guides/service/python/extend/handle-device-commands Change directory to the gRPC samples within the cloned SDK repository to locate the `pushtotalk.py` file. ```bash cd assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc ``` -------------------------------- ### Install python3-venv on older Ubuntu Source: https://developers.google.com/assistant/sdk/guides/library/troubleshooting Use a fully-qualified version to install the Python 3 virtual environment meta package on older Ubuntu versions. ```bash sudo apt-get install python3-dev python3.4-venv ``` -------------------------------- ### Console Output for 'Turn on' Query Source: https://developers.google.com/assistant/sdk/guides/service/python/extend/handle-device-commands Observe this console output when the 'Turn on' query is processed by the sample. It indicates the flow from audio recording to device execution. ```text INFO:root:Recording audio request. INFO:root:End of audio request detected INFO:root:Transcript of user request: "turn on". INFO:root:Playing assistant response. INFO:root:Turning device on INFO:root:Waiting for device executions to complete. INFO:root:Finished playing assistant response. ``` -------------------------------- ### Sample Output with Device Instance ID Source: https://developers.google.com/assistant/sdk/guides/service/python/embed/run-sample This output shows the connection and registration process when running the sample for the first time. The device instance ID is generated and displayed during registration. ```log INFO:root:Connecting to embeddedassistant.googleapis.com WARNING:root:Device config not found: [Errno 2] No such file or directory: '/home/pi/.config/googlesamples-assistant/device_config.json' INFO:root:Registering device INFO:root:Device registered: 0eea18ae-d17e-11e7-ac7a-b827ebb8010f # Device instance ID Press Enter to send a new request... ``` -------------------------------- ### Display Registration Tool Help Source: https://developers.google.com/assistant/sdk/reference/device-registration/device-tool Use this command to display the main help message for the device registration tool, showing available options and commands. ```bash googlesamples-assistant-devicetool --help ``` -------------------------------- ### Thermostat Device Attributes Example Source: https://developers.google.com/assistant/sdk/reference/traits/temperaturesetting Example of attributes for a thermostat device supporting discrete heating and cooling modes. Specifies available modes and the temperature unit. ```json { "availableThermostatModes": [ "off", "heat", "cool", "on" ], "thermostatTemperatureUnit": "F" } ``` -------------------------------- ### Install RPi.GPIO package Source: https://developers.google.com/assistant/sdk/guides/library/python/extend/handle-device-commands Install the RPi.GPIO package using pip. This package provides software access to the General Purpose Input/Output (GPIO) pins on a Raspberry Pi. ```bash pip install RPi.GPIO ``` -------------------------------- ### Command-Only Thermostat Device Attributes Example Source: https://developers.google.com/assistant/sdk/reference/traits/temperaturesetting Example of attributes for a command-only thermostat device. It includes available modes, temperature unit, and flags for command-only and query-only settings. ```json { "availableThermostatModes": [ "off", "heat", "cool", "on" ], "thermostatTemperatureUnit": "C", "commandOnlyTemperatureSetting": true, "queryOnlyTemperatureSetting": false } ``` -------------------------------- ### Configure ALSA Settings Source: https://developers.google.com/assistant/sdk/guides/library/python/embed/audio Create or update the `.asoundrc` file in your home directory with specific hardware details for your microphone and speaker. Replace `X` and `Y` with the card and device numbers identified previously. ```bash pcm.!default { type hw card X device Y } ctl.!default { type hw card X } ``` -------------------------------- ### Manually Start a Conversation Source: https://developers.google.com/assistant/sdk/reference/library/python Use `start_conversation` to manually initiate a new conversation with the Assistant, beginning speech recording and sending it to Google. This method has no effect if the Assistant is not started or is muted. ```python assistant.start_conversation() ``` -------------------------------- ### Run Google Assistant Sample Source: https://developers.google.com/assistant/sdk/guides/library/python/embed/run-sample Execute this command to run the Google Assistant sample. Replace placeholders with your project ID, model name, and optional nickname or query. The sample generates and saves a device instance ID on first run. ```bash googlesamples-assistant-hotword --project-id my-dev-project --device-model-id my-model [--nickname device-nickname] [--query text-query] ``` -------------------------------- ### Register a Device Instance using cURL Source: https://developers.google.com/assistant/sdk/reference/device-registration/register-device-manual Use this command to register a new device instance by sending a POST request with the device configuration in JSON format. Ensure the `project_id` and `ACCESSTOKEN` are correctly substituted. ```bash curl -s -X POST -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" -d @test_device.json \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/ ``` -------------------------------- ### Get Device Information Source: https://developers.google.com/assistant/sdk/reference/device-registration/device-tool Retrieves all information for a specified device model or instance. ```APIDOC ## Get Device Information ### Description Gets all of the information (fields) for a given device model or instance. ### Method GET (conceptual, this is a CLI command) ### Endpoint N/A (CLI command) ### Parameters #### Command Line Arguments - **ID** (string) - Required - The identifier for the device model or instance. - **--model** (string) - Required - Enter the identifier for an existing device model. - **--device** (string) - Required - Enter the identifier for an existing device instance. ### Request Example ```bash googlesamples-assistant-devicetool get --model "your-model-id" --device "your-device-id" ``` ### Response #### Success Response Returns detailed information about the specified device model or instance. ``` -------------------------------- ### StartStop Trait State: Paused Example Source: https://developers.google.com/assistant/sdk/reference/traits/startstop Indicates that a device is not running and is explicitly paused. ```json { "isRunning": false, "isPaused": true } ``` -------------------------------- ### List Device Instances using cURL Source: https://developers.google.com/assistant/sdk/reference/device-registration/register-device-manual Use this command to list all device instances associated with a project. Substitute `project_id` with your project ID and ensure `ACCESSTOKEN` is set. ```bash curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/ ``` -------------------------------- ### Stop Device Command Source: https://developers.google.com/assistant/sdk/reference/traits/startstop Use this command to stop a device. Set 'start' to false in the params. ```json { "command": "action.devices.commands.StartStop", "params": { "start": false } } ``` -------------------------------- ### Navigate to Assistant SDK Directory Source: https://developers.google.com/assistant/sdk/guides/library/python/extend/add-trait-and-handler Before modifying the `hotword.py` file, navigate to the correct directory in your project. ```bash cd assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/library ``` -------------------------------- ### Register Device Source: https://developers.google.com/assistant/sdk/reference/device-registration/device-tool Use this command to register a new device model and instance. Ensure that device model and instance fields adhere to the specified naming conventions and character restrictions. You must provide required flags such as --model, --type, --manufacturer, --product-name, --device, and --client-type. ```bash googlesamples-assistant-devicetool register --help ``` -------------------------------- ### Sample Output and Device Instance ID Source: https://developers.google.com/assistant/sdk/guides/library/python/embed/run-sample This output shows the device model ID and the generated device instance ID upon successful registration. The device instance ID is saved for future use with the same model ID. ```text device_model_id: my-model device_id: 1C3E1558B0023E49F71CA0D241DA03CF # Device instance ID Registering...Done. ON_MUTED_CHANGED: {'is_muted': False} ON_START_FINISHED ... ``` -------------------------------- ### Open pushtotalk.py with nano Source: https://developers.google.com/assistant/sdk/guides/service/python/extend/handle-device-commands Use the nano text editor to open the `pushtotalk.py` file for modification. ```bash nano pushtotalk.py ``` -------------------------------- ### Get a Device Model Source: https://developers.google.com/assistant/sdk/reference/device-registration/register-device-manual Retrieve the details of a specific device model using its project ID and device model ID. ```APIDOC ## Get a Device Model ### Description Retrieves the details of a specific device model using its project ID and device model ID. ### Method GET ### Endpoint https://embeddedassistant.googleapis.com/v1alpha2/projects//deviceModels/ ### Parameters #### Path Parameters - **project_id** (string) - Required - The ID of the project associated with the device model. - **device_model_id** (string) - Required - The ID of the device model to retrieve. ### Headers - **Authorization**: Bearer - Required - The access token for authentication. - **Content-Type**: application/json - Required ### Request Example ```bash curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/device_model_id ``` ### Response #### Success Response (200) Returns the JSON representation of the specified device model. ``` -------------------------------- ### Assistant.device_id Source: https://developers.google.com/assistant/sdk/reference/library/python Returns the device ID generated by the Assistant after it has been started. This ID identifies your device to the server for services like Google Device Actions. ```APIDOC ## Assistant.device_id ### Description Returns the device ID generated by the Assistant. This value identifies your device to the server when using services such as Google Device Actions. This property is only filled AFTER `start()` has been called. ### Returns The device id once `start()` has been called, empty string otherwise. ### Return type str ``` -------------------------------- ### Register Device Instance Source: https://developers.google.com/assistant/sdk/reference/device-registration/device-tool Use this command to register a new device instance or update an existing one. Ensure the device ID is unique within your project and adheres to the specified format. The device instance will be associated with a specified device model. ```bash googlesamples-assistant-devicetool register-device --help ``` ```bash googlesamples-assistant-devicetool register-device --device "my-device-id" --model "my-model-id" --nickname "My Device" --client-type "SERVICE" ``` -------------------------------- ### Get Device Model using cURL Source: https://developers.google.com/assistant/sdk/reference/device-registration/register-device-manual Use this command to retrieve a specific device model. Replace `project_id` and `device_model_id` with your respective IDs. ```bash curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/device_model_id ``` -------------------------------- ### List Device Models using cURL Source: https://developers.google.com/assistant/sdk/reference/device-registration/register-device-manual Use this command to list all device models associated with your project. Replace `project_id` with your project ID. ```bash curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/ ``` -------------------------------- ### Second Converse Request and Response Sequence Example Source: https://developers.google.com/assistant/sdk/reference/rpc/google.assistant.embedded.v1alpha1 Demonstrates a subsequent conversational turn, showing the message flow for a follow-up user input and assistant response. ```text ConverseRequest.config ConverseRequest.audio_in ConverseRequest.audio_in ConverseRequest.audio_in ConverseResponse.event_type.END_OF_UTTERANCE ConverseResponse.result.microphone_mode.CLOSE_MICROPHONE ConverseResponse.audio_out ConverseResponse.audio_out ConverseResponse.audio_out ConverseResponse.audio_out ``` -------------------------------- ### Configure Python 2.7 Virtual Environment Source: https://developers.google.com/assistant/sdk/guides/library/python/embed/install-sample Sets up a Python 2.7 virtual environment to isolate SDK dependencies. Ensure you are in the desired directory before running. ```bash sudo apt-get update sudo apt-get install python-dev python-virtualenv virtualenv env --no-site-packages env/bin/python -m pip install --upgrade pip setuptools wheel source env/bin/activate ``` -------------------------------- ### Query Device Docked State Source: https://developers.google.com/assistant/sdk/reference/traits/dock Use this example to query whether your device is currently connected to its docking station. This is a required boolean state for the Dock trait. ```json { "isDocked": true } ```