I currently use a workflow to receive Device:State messages that are filtered by an attribute named “request”. This looks for incoming messages with a “request” in the payload and depending on the type of request, it triggers a “Device: Update” block to update an individual DeviceTag or responds to the request with a “Device: Command” block to send data back to the Device. This works quite well but I would like to expand the functionality a bit. I would like the device itself to be able to update it’s own DeviceTags. I can already do this with individual tags but I want to expand to be able to support a wider range of incoming DeviceTags. I am currently trying to do this with the following incoming state message.
As seen in the image, I receive a “request”:“device_update_tags_req” with a “tag” object that includes all of the keys that I’d like to update. I’m not able to decode this in a way that’s usable and I really don’t understand the jsonEncode or stringify functions. I tried the jsonEncode blocks and it gets encoded as:
I have two questions:
- How can I parse this [object Object] into a usable JSON object?
- How can I generically update tags using a “Device: Update” block? Something like this where it pulls all the key names from the decoded json object and uses that key name as a template variable: