Delay in variable?

I have this flow where I set a variable, and to test it I’m doing something like “output current variable state, do actions, change variable, output state again”. The problem is that the first output gives the wrong value - which means the planned if test won’t work.

Anyone know if there’s something I should do to get the correct’s value?

In standard flows, delay the cards which should be fired after the ‘set variable’ actions. Action cards are not fired sequentially.

In Adv. flows, cards should fire the next card only when they’re finished, like one would expect. So here is no additional delay needed:

1 Like

Thanks, @Peter_Kawa . Do you know how long this is?

Here’s my test flow, which fails. I’m sorry, but for some reason it didn’t let me upload the image.

What happens here is that I manually set my variable, and based on the change in the variable I start the flow. Entering the flow, the variable still isn’t set correctly, but the call is still made. That’s pretty strange…or did I just have a mind fart? :thinking::face_with_raised_eyebrow::exploding_head:

EDIT You created a loop. When you let the var be set to ‘No’,
the same var is changed back, and it then triggers the flow again.

No, I accidentally created a loop, i used the ON instead of OFF in the "set ‘var’ to NO card.

This is an example how you can use it:

Just out of curiosity - are you sure there’s a loop? There are two similarly named vars - one AllOn and one AllOff. When AllOn is set to yes, the AllOff is set to no and vice versa. The start block is just to test by setting one of them to yes and make sure the other one is set to no.

Please correct me if I’m wrong. I really appreciate the help :slight_smile:

Thanks for that :slight_smile:

It kind of makes me wonder why there’s a event for changed variables, if the variables take time to set. The only reason I can see for an event like that is to react, but then you have to test the value first. If there’s a delay, then the event shouldn’t have been raised until the variable had been set?

Or am I missing something? I my head, I need to do the following:

  1. Listen for the event that my variable changed
  2. Test it and react according to the value
  3. Execute my actions

This translates to:

  1. Listen for the CompoundAll[On|Off]Active
  2. Find if it’s set to “yes”, then
  3. Set all the other variables to “no”

I’d love to hear your (or anyone elses) opinion about this.

Oww, my bad. Your vars looked to similar :laughing:
I accidentally created a loop myself, i used the ON instead of OFF in the "set ‘var’ to NO card.

Can you share the flow? I ditched the example flow already
Howto share your flows (brand new feature!): click here

TEF:FLOWS:H4sIAAAAAAACA72Wy2orRxCGX8UMZ6mCvlTftDtkHbIIZGOEqL75DJE1J9LYHOPo3VMtj0TsyGQSZC/EaNRNVX9//V2l5+6xWz53qJCUKxlEShqw5gzRWgWVpA1ORF8qtn3bbtml4f778LDNXzebX7Zf09g/lm7RjbwSh2FTaNsdFp2QqQQbDWiXEDAIAoomACYSxR

Like this?

Yes, thanks! But it is only a part of the code. Please use ctrl+a ctrl+c to copy, and use the </> button above, before pasting it in your post.

Screenshot from 2022-10-03 19-04-20

[TEF:FLOWS:H4sIAAAAAAACA9VW227bRhD9FYPIowbY+0VvQZ6LAk3aF0MQZm8OUZpUKcqJ4erfO6SlWEFlhS7iAn4QRGAHM+ecOTO7D9Ud9jWGJm8/db/lTYMxV8uHSgmFwuYELEYJqqQEwRgBBbnxlgWXixrjWryl+Cp2t5tu16b3TfNr+z4O9V2uFtVwvxkPQ9c1Gdtqv6gYj9mboEHaqEB5hoBBe1ARWbaIUnDxTNpSns1LiTHdYRtzKk33ZVstrx+qOlGINd4lLwUI5h0oqwsElTgkbozGolkwjhIeyv3SpbrcfzgU/eMoDAXkdvyijEO/y4sqYp+2I06LOQTrAkQviU+OJBNjgUilYJXMsjA+xnVf2tz/3tdU5HN3m++Xt9jiTe6XTXdTRyowoT22Yh0/Y3tD5YhXfzMVOh6N31PsrAYtLvVnlO2g5NDXN4SG4r9WS7ao7qsld/Tf7YbNbvi4izFvR1UrI4iokBG0dBGUUhoCKgfoLEuMmcBCrlaU2CtnpVIkfMIAiqcMzioOMQuT5Pjj6nWEmWWxxUWHXVZGmnPKRGWxZKHAZFWoWDYQfJIgtdKea+kt55MyPAljUkTSwxC+GDJgZA5K5OQhjip6PV+Z/NcOm/VxEr7Bjl2b6qHu2kfg1hya+gT9Exl5xI0mMR5YBEe6UKMMB+eKhWhU9hKRe+ur1ZPe63ep7zZD92du363PY/t7ljdHkckcXkhNxUNBCqRBctQ+cNEj4ym5EOJraSHVv7Qo2hAeT6Yt1EjFPAFL3AKT0WZBilhVXqrFLDtOG2xOI14+Mds8nEjyqlOzoLTNqGTBZpufZgjjk/p82ivfW/FkimhpFMxOQlQ6gZJegSs0TyZbpZwsNFximqJZrXo1tX7C8n2RWCdePRGL5+Sy1AGKEbRjrZG0jJOHZBxPvHgh0uMytoHR/UdwvTW0tY1I4FThUHS02uoQZJisdYCwHbAfDgjEIwAtzgFAI9AYMioialBOkGm4LHS7JkZnMlnhJgCzAt+Gt8cHwPluyUOzNGMUQNSSLONqK5xRc4KloswA88VYHX000r8Ng/6YsREj41lvg0uM226oSx1xLLA9Mo99xiGvT89OiA/560BBHweKuerK1SgE6XA1MVleXV//1+tptaoucz6/v2Zd7uNEzFp0b14sro8PDzU6ZNYb6X8kXcpzrOesjB9a5PzWnvXmmR6Kc9b721frm0fkuTtmtd/vV/t/AJsu4XymDgAA]

@Peter_Kawa Sorry about the last one. For some reason, copying the field in the app doesn’t copy everything - and I’d never seen the output before and didn’t know what to look for. Hopefully this will work.

I really appreciate the help!

1 Like

Don’t understand the problem. I build your flows on my own and it works as it should:

Or am I missing something? :thinking:

That’s really strange…Mine comes in as “yes”, I change it, when I write the variable again it’s still “yes”…Maybe I need to contact support, then? The whole behavior is contra to everything I know from development, and I just created this little snippet to test it out.

Excuse me, but I don’t quite get it.
If I change “CV_Off” from No to Yes, then “CV_On” is automatically changed from Yes to No. And of course vice versa. And this doesn’t work for you?
Are there any other flows with these two variables?

Hmmm…that shouldn’t be an issue. I know I have flows setting these variables, but as far as I know there are no flows intercepting the change. I did try to change the variables (I had to reboot the Homey to access them, which was strange), and that seemed to work - so I’m not ruling anything out.

Do you know a way to see which flows uses variables, like you can look at a device and see which flows they are in?

Don’t know, sorry. This might be a request for @martijnpoppen Flow Checker app?

1 Like

Actually, you dont need to copy the TEF yourself.
After you press Create TEF, the TEF is automaticly placed in your clipboard, so you just need ctrl+v to paste it somewhere :wink:

image
Translation: TEF allready in clipboard.

1 Like

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

Flow import worked, I adjusted it with added ms timestamps.
It seems to work well.
@Tiwas How did you test?
When I switched the start button I saved the flow every time. Then I ran the flow by rightclick on it’s name and hit ‘start’.

ON 2 - var AllOn: true (--- var AllOff: false)  @ 04T15:51:13.950Z

ON 1 - var AllOn: true @ 04T15:51:13.828Z

ON 1 - var AllOn: false @ 04T15:51:02.367Z

OFF 2 - var AllOff: true  (--- var AllOn: false)  @ 04T15:51:02.354Z

OFF 1 var AllOff: true @ 04T15:51:02.255Z

OFF 1 var AllOff: false @ 04T15:50:52.300Z

ON 2 - var AllOn: true (--- var AllOff: false)  @ 04T15:50:52.291Z

ON 1 - var AllOn: true @ 04T15:50:52.199Z

ON 1 - var AllOn: false @ 04T15:50:34.232Z

OFF 2 - var AllOff: true  (--- var AllOn: false)  @ 04T15:50:34.224Z

OFF 1 var AllOff: true @ 04T15:50:34.123Z

Flow:

[TEF:FLOWS:H4sIAAAAAAACA+1Y227bRhD9FYIIEBv1Onu/MCjQwqjbPjQGkrQvsSDs1SFKka5IpXZd/3uHFOVEitIyjZKnPOiyy+XMnDNnZ5a8y9/kxV0udIrCOomkJhJxEy3ShDjEhcIMR2eMVP26Oi9yW1Xzi2f5Sd7BwDVNFW2d35/kiXBpBY2Ic6kQ9yograJCOnphibAiYbll4/x818j9ML7LfbM4td1r+IZPvG39srzuNvf+1E+9WE/1d9i8eHWXl3AluOS4jAFFJzzi1AhkhEgoKeuJUYlBJOCyNzKfz39pQpluz5rFdbOqw292WVpXxRYWxLzolqt4kvvep7LROaUd8oZxxKMPyGHskHXBKc4iS5j0627yAp/kt3lBNPw24GQIvljY2l7FZVE1V6UH632kb0Zvc//a1lcxjER0y/IKlsKoBVB50lYFqgySlFCgNUXkjKNIMsMNkzpY6fLZwMDdg8n+fxnA2KScAht2Ed9m9b5n1HCtGOcU0WBhPQkRMskJ8pHKwPoP4VuImTwQ4qBt4M4xZAOBDBIN/zQTgFiFaHRkHNsPI56kwG3EoMEBMglUyuCBIiUhyd5FZD3WKIFwGCeWeyNGyITIMc//jTr+sbLVfKPvNWTf1KHsyqYfN12P2sqAicMe6SHPRBKkdVLISx4Nsxa0ax5Qzx+FZXPdNb/H+tF8v/O/J6W+hw0JNpTBZtEuWcQTqFwTD+n2xmISgnbO78KGHBwGdhISvBuQWaLAOTYQRiAKYeZVpABe8fRRsCflfygZUwgfYQs9OdsPGm9jt4Pe+hH6IHMdPIAH19Jo8M8UxJggZJcEI4ZGTmk8uMxPwFK1gqlkqzb2NExKwA4NE7I/mYagkmNEeuQD11Cvg0BaUgGEEO6FEhgreuj69j4LymGKDXQNoyAULinQyRNBSXgFQUA1chsxjBxIitdw2s4uuwc0sF9Y6vdSIhhx5RS0CCwRNpBa4Y2Hsp3PBvVRKyVozloLYDW1yBKWEBjAcI0FRfXokPLR42HE93n01PfKnshJBGzjEvwz4vpEgWxgSQqNnzKPBNOgD84Fchb0arXCAWPpsIsjLPXvtaJuujKV3vZRtyM8v4y2i/N3L+3dK5Ma1GavdPGmt3DxLCMZyoCY7PuquqiL7NWr/9suZrPsO7h9HVRRTDmaFEUL7b2+ms2GogtnimQjdHTPRYA9bjgIhScko+JcsySh7G3kwUZ9EH5IIne4oQfk5giht8ZS+pC1KVttNjvOtrie0i12uPZc2RShqAOpCfxECekJDDHBhSGCGUXIjmYZP7hmJ50udjV7fg6iPRSTWzxOOVzu8EhigHnhUJIUcq4kg70fDAqghkCSoTTEXc0yemgi91D0rnY/maRt9X7iVtgR75Qev1soppyOxmOJ2X8Wt9fXxf6HyDXxy1V91oT4PHarZd2+GLzvP6lNKVqb/PimV0P+5EnWlYsIh4PFdbYoq6pso89+fXl2WV/WcPHH2GWvV8BtFiD7WVmn5rKuYPLFbfszDLJvM/unLbtseNI9bW/bLi5Or2LXXzw6fpoNVn646ZYQa1Y13lZZs8z+WlWrwfFl3adymH8JQzA3Gj7t/f3Uez5tq9LHo/fnyzrEm4t09Dh7fPwNOX66ttWb3mPqI6wMIZ8Ncm8zOwZ9mT+P7arqLvOss1f9kuWQkLexw53j1CaEQSGTDo47CtmpbwdTyKQS8VUhX1ohU14krBXC8d6XGAcTyKRe/FUgX1ggk96trQXC9N73egcTyKQHjK8C+aICub+f3f8DyHjQUxwXAAA=]

I suddenly got the urge to hug you :wink:

Anyway - it showed what I believed to be true: those two variables are only in use in two places, they are set in scripts. No other events for handling them if they change.

One question, though - does the script look in advanced flows as well?

1 Like

I saved it, then clicked the blue button to set one of the vars to ‘yes’. Right clicking it shouldn’t do anything other than that, should it?