Hello Folks,
I was hoping to get some help here. I have a homey script that returns a large json object and attempts to set a tag for it. The return value looks perfect. And indeed the tag appears under the API endpoint when I request flowTokens via http. However, the Advanced Flow doesnt even show it as an available tag. Anyone know what I might be doing incorrectly?
homeyscript:
## other functions
...
async function main() {
const zones = await Homey.zones.getZones();
const devices = await Homey.devices.getDevices();
const sensors = await getClimateValues(zones, devices);
const thermostats = await getThermostats(zones, devices);
const result = { thermostats, sensors };
console.log("generated json result tag")
tag('climate_value_all', result);
return result;
}
return await main();
http response from API:
Flow only shows a placeholder value called “My Number” under “HomeyScripts”
Hi Andy,
The tag is not getting any data, while you need to use await
AND a string value needs to have quotes around it, as opposite to num & bool values:
await tag('My String', 'abcdef');
await tag('My Number', 123);
await tag('My Boolean', true);
While you use a const as string value, you can force it by using
String(result)
Like this:
await tag('My String', String(result));
Thanks for the reply @Peter_Kawa ,
Is this how I should be casting my json object?
async function main() {
const zones = await Homey.zones.getZones();
const devices = await Homey.devices.getDevices();
const sensors = await getClimateValues(zones, devices);
const thermostats = await getThermostats(zones, devices);
const result = { thermostats, sensors };
console.log("generated json result tag")
await tag('climate_value_all', String(result));
await tag('climate_value_all_test', 'test_val');
return result;
}
return await main();
I just tried it and neither climate_value_all nor climate_value_all_test appear in the advanced flow. Any Ideas?
Ah wait, I didn’t notice they’re inside a function
Try without the await
no change without the awaits, im afraid.
interestingly they do appear when use “run code” and return as text. then it allows me to see the tags in another step, but not when I use the “run script”
In the case that the data was too large I also tried the following with no visible option to search for tag in the “number” logic evaluation
async function fetchall() {
const zones = await Homey.zones.getZones();
const devices = await Homey.devices.getDevices();
const sensors = await getClimateValues(zones, devices);
const thermostats = await getThermostats(zones, devices);
const data = { thermostats, sensors };
return data;
}
const all_climate = await fetchall();
const sleeping_zone_agg_f = all_climate.sensors.home.zones.inside.zones.upstairs.zones.sleeping.aggregate.avgTempF;
const living_thermostat_targetTempF = all_climate.thermostats.living_thermostat.targetTempF;
await tag('sensors.home.zones.inside.zones.upstairs.zones.sleeping.aggregate.avgTempF', sleeping_zone_agg_f);
await tag('thermostats.living_thermostat.targetTempF', living_thermostat_targetTempF);
return {sleeping_zone_agg_f, living_thermostat_targetTempF}