Homeyscript to return a JSON

I am trying a small homey script (see below) to return a JSON
It does not seem to work -or accept the output as the tag is never created.

Any idea how to do this?

let devices = await Homey.devices.getDevices();
// Return array of device capabilities
await tag("homey devices", devices);
return true;

I am not sure if you described the problem completely, as “tag” has something to do with flows and cards.
Anyway, search the forum and find for example Can running a script from a card create a tag?
It gives some clues.

Yes, its a homeyscript flow card that should generate a tag with the JSON, but for some reason it doesn’t…

That card is only avaiable in advanced flow, see link above.

Yes I know, and understand. What I don’t understand is why the script is not generating a tag with the JSON output in it

That tag is a tag that will be like any other device capability value tag.
If you want it returned as a string tag (advanced code flow card) then you’ll first have to first parse the JSON object to a string, and then return that string (instead of your “true”).
If you do want it as a tag like any other device capability value, you’ll also have to parse the JSON to a string first.
Tokens/tags just don’t accept a json object as value, either string, number or boolean.

1 Like