Best Practice Development

The SHOW SOURCE Button

image

Problem of the day was that I regularly check to see if a device should be turned on or off , based on relative (%) , absolute (Kr) or comfort (Wife) cost of doing so.

The default “Home Mode Tracker” is a built in example that store A text , home,sleep,away … in a global fh.home.mode variable … So, no problem , new flow , “Home Action Tracker” , same trigger , but now select SHORTCUT , instead of Home mode

image

Then after trigger completes , dump result in a global variable , and see what happens…

image

The Variable is set to 1, for my first custom ShortCut , 2 for the next , 3 for next … etc etc…

So far so god, just add a bunch of IF’s ? heek = 1 heek = 2 … Ohhhhhh NO !

When saving I started gettin error messages , hitting the LOG button I found “cant convert to 64 float” and other strange messages .

After a long time I startet reading the code … "SHOW SOURCE" . The error found was same if I used seperate IF’s or I used a Transform Map.

The transform looks like this :

But the code for the same was like this

    "ValueMapping": [
          {
            "LValue": {
              "Value": 1,
              "ValueType": "string"
            },
            "RValue": {
              "Value": "A01",
              "ValueType": "string"
            }
          },
          {
            "LValue": {
              "Value": 2,
              "ValueType": "string"
            },
            "RValue": {
              "Value": "A02",
              "ValueType": "string"
            }
          },
          

Do YOU Spot the ERROR ? The conditions never triggered. Neither if used in IF or MAP.

If you compare the LValue to the RValue you see it . Both are defined as string , but since Thingsplex thinks that 1 is an integer it drops the “” .

Editing code to this , and it all works .

    "ValueMapping": [
          {
            "LValue": {
              "Value": "1",
              "ValueType": "string"
            },
            "RValue": {
              "Value": "A01",
              "ValueType": "string"
            }
          },
          {
            "LValue": {
              "Value": "2",
              "ValueType": "string"
            },
            "RValue": {
              "Value": "A02",
              "ValueType": "string"
            }
          },
          

So … For IF and MAP … check that constants, are converted to code correctly , Strings need quotation marks.

And then , in the back … somebody raises his voice and says … STUPID … use Integer and integer on both sides …

 "LValue": {
              "Value": "1",
              "ValueType": "int"
            },
            "RValue": {
              "Value": 1,
              "ValueType": "int"
            }

:sweat_smile:

So … clearly a case of Copy 1,2, edit 2,1 error .

Creating left and right side BOTH as xxx01 and yyy02 as ALFA numerical made “” inserted corectly . Then edit yyy02 to 02 to 2 did not remove the “” .

1 Like