I am sending this input block’s data from a User Experience Dashboard via a virtual button to a workflow:
Full device info is shared in the dashboard in context:
However when I try to submit the data it shows that the data does not end up as valid JSON:
It seems {{ctx.deviceId.id}} and {{ctx.deviceId.name}} are valid JSON as they evaluate correctly everywhere else on the dashboard.
See that {{ctx.deviceId.name}} evaluates to 42003
Setting:
In User Experience:
Hi Leo,
You are seeing this error as {{ctx.deviceId.tags}} is an object, and the intended use for .tags is to return just one tag, or a stringified object. The documentation states:
{{ctx.VARIABLE_NAME.tags}}
is a reference to the tags associated with the device; you may wish to iterate over all tags or get the value of a specific tag with a string template such as {{ctx.VARIABLE_NAME.tags.TAG_KEY.[INDEX]}}
, where INDEX
is usually 0
since tag values are returned as an array.
If you would like to get the tags as an object, I would recommend doing so in the workflow. You can do this by using the deviceId you are sending in a Device: Get Node and checking the box to get return tags as an object.
Thanks!
Julia
Data comes in as the device name:

Then use the get device node to find the id and tags:

Works great, thanks!
I did however find one thing perplexing:
It works if I send the device name as such:
But also shows a JSON error if i send the device id as such:
Hi Leo,
The id has to be formatted as a string to pass the JSON validator:
{ "sensor" : "{{ctx.deviceId.id}}" }
Thanks!
Julia
I need to pay more attention to variable types apparently. 
Thanks again, Julia.
2 Likes