After wasting many days debugging, I finally found the reasons I get wrong info to display: tag unavailable in flow
This is how the flow looks normally
When I run the flow, some of the tags suddenly (and randomly) become unavailable for a split second, precisely when the flow updates them. As a result, I don’t get the updated information from the flow run because I’m printing the contents of those tags.
Does anyone have any idea what might be causing this?
It happens quite often (more than 70% of the time), but not always. I’ve rebooted the system several times, but the problem persists. I have put in delays/await, still not help.
It happens quite often (>70%), but now always. I have rebooted the system several times.
Where’s the tag coming from?
The tags are from my own HomeyScript. Here is an example how they are generated.
I have several flows calling the same script so I write the results on different tags depending on which flow is calling. In this example, each flow supplies different StopNr and RowNumber
const tagName1 = `${StopNr} Row ${RowNumber} Left`;
const tagName2 = `${StopNr} Row ${RowNumber} Right`;
await tag(tagName1, null);
await tag(tagName2, null);
await tag(tagName1, line);
await tag(tagName2, `${WholeMin} Min`);
How often do you call the script? Or are you calling the script as part of the flow that also has the cards where the tags go “unavailable”?
I call the script as part of an advanced flow. What it does is fetching live bus schedule using bus stop ID as input arguments when I push a button. The script returns tags containing the next expected arrival time for that bus stop, then I put the arrival time in a dashboard using Widget Forge. There is a refresh cycle of 1 minute. There are 2 flows that call the script concurrently. I think the problem has to do with concurrency, either with the calling of the script, updating the tags or even Widget Forge. Anyway, I am modifying my script to avoid this concurrency.
Anyway, it definitely is a bug with Homey here, since it is so random, just momentarily and should not happen at all.
I can imagine that running the script concurrently could cause these issues. In an ideal world, tag updates are performed atomically, but I doubt that they are.
Confirm that it is a problem of concurrency. The script has async function as well as a number of await calls to external webserver. After I have optimized the script to avoid overlapping and put some seconds waiting between each time the script is invoked, the problem disappears. I also dropped the usage of tags which I suspect contributed to the problem.