Hi,
I’ve hit 100 tags for a particular device application. (Storing various thresholds and labelling fields).
Storing these in a small array could reduce my tag count by 75% if this works, however I can’t seem to get my syntax correct.
If I store a tag called:
D2_TEST
With a value of:
{“key”: “foo”, “value”: “bar”}
Can I reference this address in a Gauge label for example?
I can read in a single char:
{{ ctx.deviceId-0.tags.D2_TEST.[0].[0] }}
However I can’t seem to address:
{{ ctx.deviceId-0.tags.D2_TEST.key }} for example
Hopefully it’s a minor formatting error!
The issue is that, though your value resembles an object, it is still being treated as a string. I wrestled with this for a while but I cannot figure out a way using our Handlebars rendering engine to cast that value to an object, which would allow you to then look up the properties within it. I’m going to file a feature request for a new Handlebars helper that would allow for this use case (casting a stringified object to an actual object).
As a side note, would moving any of these device tags to attribute tags solve your use case? Those values are also available on the device context object just like device tags are.
Most of them would be better stored as attribute tags for sure. Many are attribute specific.
However they do need to be updated by the user, using a input control form on a dashboard. When I started playing with the workflow I realised I couldn’t use the Device Update node to set these Attribute Tags.
I found a forum post referencing the API, but apparently needing to update ‘all’ tags in one hit, every time, which I thought best to avoid. Proceeded to use Device Tags, and found a limit of 100 tags.
If I’m mistaken above on the attribute tags, that would be a great result! Any ideas would be appreciated.
You’re right about the Device: Update Node not allowing the setting of attribute tags, and also about the Device: Patch API endpoint requiring the passing of the entire attributes array when adding, removing, or editing any attribute.
One workaround I’ve used in the past is to use the Devices: Patch API endpoint (also known as the “Bulk Device Update endpoint”) to update a single attribute tag, as that endpoint does support such an operation. So you’d build your device query to only target a single device, and then using the “Attribute Tag: Set” operation to change the value of all (one) devices matching the query.
That endpoint is pretty confusing, so I’ve attached a starter workflow you can use. You’ll probably need to change the variable names to match what you’re passing from your Input Controls Block but other than that, this should allow users to safely set individual device attribute tag values.
set-attribute-tag-develop.flow (3.3 KB)
1 Like
Thanks Dylan,
That sounds like a good solution, I’ll give it a try.
Hi @Dylan_Schuster,
This is working well for a single attribute tag update.
Could this schema be used to update a batch of say 3 or 4 tags in one go?
Many thanks,
Absolutely; you can just add additional instruction objects to the updateOperations
array. For example, copy, the highlighted operation in this screenshot and make the necessary adjustments to target a different attribute / attribute tag.
Note that if you want to target different devices per operation, that is something that will require a separate API call.
1 Like
Following up on this thread. The feature request that @Dylan_Schuster referenced above has been released.
{{jsonDecode val}}
treats val
as a JSON string and parses it, thereby casting that value to an actual object. While the workflow solution that Dylan shared above is still valid, use of this helper simplifies this process.
1 Like
Hi @Sebastian_Turner,
Could this solution work for a device Tag, which is then used as configuration parameters on an Edge Workflow.
Tag Name - DeviceConfig1
Tag Value - {“param1”:“12345”}
for example?
Yes, that would work, with the following considerations:
- There’s a 255 character limit for the tag value.
- The tag value would fail if not in valid JSON format, so validation testing is recommended.
Would it be possible to ask for an example?
I did try this but I think my syntax was incorrect.
Would the JSON Decode Node work?
Yes, the JSON: Decode Node would work for this. I’ve attached a sample application demonstrating this. Did you try this already and run into a problem?
export-6409f9a1bb7fefb54cb22a22-1678375578716-forums4634.zip (2.5 KB)