Delay in variable?

I have a super HomeyScript for that:

// FindLogicsVarsInFlowsTEST.js
//
// Script to find Homey Logics Variables in Flows, and orphaned Variables (by RonnyW)
// Adjusted somewhat, when called from a flow, it returns the output in a Variable (PD)
//
// Enable all "log" entries to output results to console
//log("=============================================================");
//log("Flow Search for Logics Variables");
//log("=============================================================");
//log(" ");
const flows = await Homey.flow.getFlows();
const logicVars = await Homey.logic.getVariables();
let flowMatches;
let varUsed;
let position = [];
let results2Var; // To be able to build a string to output the results to 
                 //  a variable [OrphanedLogicsVars], for usage in flows
results2Var = ("** *** Flow Search for Logics Variables *** **\n\n");                 

for (var iLogicVar in logicVars){
  // log("=============================================================");
  // log(" ");
  // log("Logics Variable: "+logicVars[iLogicVar].name);
  results2Var = results2Var + "\n|| *VARIABLE*: ["+logicVars[iLogicVar].name + "]\n";
  //log('ID: '+logicVars[iLogicVar].id);
  //log("=============================================================");
  let logicVar = logicVars[iLogicVar].name;
  let logicVarId = logicVars[iLogicVar].id;
  varUsed = false;

  for (var iFlow in flows){
    flowMatches = false;
    position = [];
    // Search for variable name in Triggers
    if (flows[iFlow].trigger.uri == "homey:manager:logic"){
      for (var iArgs in flows[iFlow].trigger.args){
        if (    flows[iFlow].trigger.args[iArgs].name == logicVar
             || flows[iFlow].trigger.args[iArgs].id == logicVarId){
          position.push("Trigger card (IF)");
          flowMatches = true;
        }
      }
    }
    // Search for variable name in Condition cards
    for(var iCond in flows[iFlow].conditions){
      if ( flows[iFlow].conditions[iCond] &&
          flows[iFlow].conditions[iCond].uri == "homey:manager:logic"){
        //log(flows[iFlow].conditions[iCond].args);
        for (var iArgs in flows[iFlow].conditions[iCond].args){
          if (    flows[iFlow].conditions[iCond].args[iArgs].name == logicVar
                || flows[iFlow].conditions[iCond].args[iArgs].id == logicVarId ){
            position.push("Condition (AND) - direct reference");
            flowMatches = true;
          }
        }
      }
      for (var iArgs in flows[iFlow].conditions[iCond].args){
        if ( flows[iFlow].conditions[iCond].args[iArgs] &&
            JSON.stringify( flows[iFlow].conditions[iCond].args[iArgs] ).indexOf( logicVarId ) > 0 &&
            JSON.stringify( flows[iFlow].conditions[iCond].args[iArgs] ).indexOf( "homey:manager:logic" ) > 0 ){
          position.push("Condition (AND) - indirect reference (Tag)");
          flowMatches = true;
        }
      }
    }
    // Search for variable name in Action cards
    for(var iAct in flows[iFlow].actions){
      if ( flows[iFlow].actions[iAct] &&
          flows[iFlow].actions[iAct].uri == "homey:manager:logic"){

        for (var iArgs in flows[iFlow].actions[iAct].args){
          if (    flows[iFlow].actions[iAct].args[iArgs].name == logicVar
                || flows[iFlow].actions[iAct].args[iArgs].id == logicVarId ){
            position.push("Action (THEN) - direct reference");
            flowMatches = true;
          }
        }
      }
      for (var iArgs in flows[iFlow].actions[iAct].args){
        if ( flows[iFlow].actions[iAct].args[iArgs] &&
            JSON.stringify( flows[iFlow].actions[iAct].args[iArgs] ).indexOf( logicVarId ) > 0 &&
            JSON.stringify( flows[iFlow].actions[iAct].args[iArgs] ).indexOf( "homey:manager:logic" ) > 0 ){
          position.push("Action (THEN) - indirect reference (Tag)");
          flowMatches = true;
        }
      }
    }

  // Results of Flows found:
    if (flowMatches == true){
      varUsed = true;
      // log("-------------------------------------------------------------");
      results2Var = results2Var + " - ";
      // log("  Flow: "+flows[iFlow].name);
      results2Var = results2Var + "**Flowname:** " + "(" + flows[iFlow].name + ") \n";
//    //   log(flows[iFlow].name);
//    //   results2Var = results2Var +flows[iFlow].name);
      // log("     Position:");
      results2Var = results2Var +"   -Position: / \n";
      for (iPos in position){
        // log("         - "+position[iPos]);
        results2Var = results2Var + "       -" +position[iPos] + " / \n";
      }
    }
  }
  if (!varUsed){
    // log(" ");
    // log("* NOT FOUND in a flow *");
    results2Var = results2Var +"*** NOT FOUND IN FLOWS *** \n\n";
    // log(" ");
  } 
}
// Output (test to view the result data in 'results2Var')
 console.log(results2Var)
// Output to a StringVariable [OrphanedLogicsVars]
await tag( "OrphanedLogicsVars", results2Var );

return(true);


Output snippet:

*VARIABLE*: [AB.StartChargingTime_Num]
 - **Flowname:** (T1-2 Rem.ChargingTime) 
   -Position: / 
       -Action (THEN) - direct reference / 
 - **Flowname:** (T2-2 Departure.Time Change) 
   -Position: / 
       -Action (THEN) - direct reference / 
 - **Flowname:** (C2-3 StartCharging Time.Num2Normal) 
   -Position: / 
       -Trigger card (IF) / 
       -Condition (AND) - indirect reference (Tag) / 
 - **Flowname:** (C2-3 Start Laden Tijd.Num2Normal (Kopie)) 
   -Position: / 
       -Trigger card (IF) / 
       -Condition (AND) - indirect reference (Tag) / 
       -Action (THEN) - indirect reference (Tag) / 
       -Action (THEN) - indirect reference (Tag) / 
 - **Flowname:** (T1-2 Rest.LaadtijdChange (Kopie)) 
   -Position: / 
       -Action (THEN) - direct reference / 
       -Action (THEN) - indirect reference (Tag) / 
       -Action (THEN) - indirect reference (Tag) / 
 - **Flowname:** (T2-2 Vertrektijd.Gewijzigd (Kopie)) 
   -Position: / 
       -Action (THEN) - direct reference / 
       -Action (THEN) - indirect reference (Tag) / 
       -Action (THEN) - indirect reference (Tag) / 

|| *VARIABLE*: [Chronograph_ms_test]
 - **Flowname:** (1-2 Chronograph Test) 
   -Position: / 
       -Action (THEN) - indirect reference (Tag) / 

|| *VARIABLE*: [PrijsNu_Afgerond]
 - **Flowname:** (De prijs wordt 1 vd laagste in de 2u. vóór 18u. PBTH) 
   -Position: / 
       -Action (THEN) - direct reference / 
       -Action (THEN) - indirect reference (Tag) / 
 - **Flowname:** (De gem. prijs komende 2u. wordt het laagst in de komende 8u. PBTH) 
   -Position: / 
       -Action (THEN) - direct reference / 
       -Action (THEN) - indirect reference (Tag) / 

|| *VARIABLE*: [ABC.TimeNumeric2Time]
*** NOT FOUND IN FLOWS *** 

1 Like