az iot hub digital-twin

Note

This reference is part of the azure-iot extension for Azure CLI and requires version 2.0.70 or higher. The extension will automatically install the first time you run an az iot hub digital-twin command. Learn more about extensions.

Manipulate and interact with the digital twin of an IoT Hub device.

Commands

az iot hub digital-twin invoke-command

Invoke a root or component level command of a digital twin device.

az iot hub digital-twin show

Show the digital twin of an IoT Hub device.

az iot hub digital-twin update

Update the read-write properties of a digital twin device via JSON patch specification.

az iot hub digital-twin invoke-command

Invoke a root or component level command of a digital twin device.

az iot hub digital-twin invoke-command --cn
                                       --device-id
                                       [--component-path]
                                       [--connect-timeout]
                                       [--hub-name]
                                       [--login]
                                       [--payload]
                                       [--resource-group]
                                       [--response-timeout]

Examples

Invoke root level command "reboot" which takes a payload that includes the "delay" property.

az iot hub digital-twin invoke-command --command-name reboot -n {iothub_name} -d {device_id} --payload '{"delay":5}'

Invoke command "getMaxMinReport" on component "thermostat1" that takes no input.

az iot hub digital-twin invoke-command --cn getMaxMinReport -n {iothub_name} -d {device_id} --component-path thermostat1

Required Parameters

--cn --command-name

Digital twin command name.

--device-id -d

Target Device.

Optional Parameters

--component-path

Digital twin component path. For example: thermostat1.

--connect-timeout --cto

Maximum interval of time, in seconds, that IoT Hub will attempt to connect to the device.

--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--payload

JSON payload input for command. Provide file path or inline JSON.

default value: {}
--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--response-timeout --rto

Maximum interval of time, in seconds, that the digital twin command will wait for the result.

az iot hub digital-twin show

Show the digital twin of an IoT Hub device.

az iot hub digital-twin show --device-id
                             [--hub-name]
                             [--login]
                             [--resource-group]

Examples

Show the target device digital twin.

az iot hub digital-twin show -n {iothub_name} -d {device_id}

Required Parameters

--device-id -d

Target Device.

Optional Parameters

--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

az iot hub digital-twin update

Update the read-write properties of a digital twin device via JSON patch specification.

Currently operations are limited to add, replace and remove.

az iot hub digital-twin update --device-id
                               --json-patch
                               [--etag]
                               [--hub-name]
                               [--login]
                               [--resource-group]

Examples

Update a digital twin via JSON patch specification.

az iot hub digital-twin update --hub-name {iothub_name} --device-id {device_id} --json-patch '{"op":"add", "path":"/thermostat1/targetTemperature", "value": 54}'

Update a digital twin via JSON patch specification.

az iot hub digital-twin update -n {iothub_name} -d {device_id} --json-patch '[
  {"op":"remove", "path":"/thermostat1/targetTemperature"},
  {"op":"add", "path":"/thermostat2/targetTemperature", "value": 22}
]'

Update a digital twin property via JSON patch specification defined in a file.

az iot hub digital-twin update -n {iothub_name} -d {device_id} --json-patch ./my/patch/document.json

Required Parameters

--device-id -d

Target Device.

--json-patch --patch

An update specification described by JSON-patch. Operations are limited to add, replace and remove. Provide file path or inline JSON.

Optional Parameters

--etag -e

Etag or entity tag corresponding to the last state of the resource. If no etag is provided the value '*' is used.

--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.