We are trying to create a device dynamically, starting with a base recipe and then adding attributes as needed for a final configuration. We use attribute tags for things such as units so need to be able to programmatically create an attribute that has attribute tags. The workflow node Device:update doesn’t seem to support this with the ‘individual fields’ option, so we are using the payload path option. Our payload is as shown below, and we use data.patch as our payload path to the Device:update node.
This works without error, but results in all existing attributes in the device being deleted. Is there somewhere this is specified in the documentation, and how can we add an attribute with tags without wiping out all other attributes already defined. We need this to be bulletproof, can’t have any possibility of attributes being deleted.
To use the Device: Update node, you will need to provide all of the attributes and attribute tags, along with the new ones you’d like to add, to the payload path.
Here’s a workflow example that is able to programmatically add attributes (and attribute tags) to a device without removing the already defined attributes.
The workflow is triggered by a Virtual Button which sends a JSON payload. Here’s what that payload looks like:
The workflow then uses the Device: Get node to retrieve the device information that is passed in as deviceIDToUpdate. It then uses the Mutate node to add a field to the payload that will act as a sort of staging area for the updates, and then uses the Loop Node to loop through the addAttributes field. Finally, it ends with a Device: Update node where the attributes are then updated for the device.
I’ve included the workflow zip below. Please let me know if you have any questions!
Go to your Organization’s overview page (go here and click on the name of your Organization)
Under the Applications section, click the “Import …” button on the top right
Select the .zip file
You can then test out the attribute tag functionality and copy over relevant components to your real application. Please give this a try and let us know how it goes!