Thingsplex programming code - beginners rules of thumb/best practice/lessons learned

I suspect a lot of people on this forum are programming for the first time. But no matter if you’re experienced with logic sequences or not, every programming language has its own features and pitfalls.

To assist new TP-coders from making the same mistakes as everyone else, please post your hardest lessons learned and solutions here.

If a lot of contributions pop in maybe it’s possible to create a summary of them and stick them to the top of this thread.

5 Likes

Here are some tips related to importing code, timeouts/errors and use of Receive nodes:

  • Remember to “define” (ie. Add) variables when you import a code, otherwise the flow will stop at any if-nodes or otherwise fail to run (unless the same variable is set previously by the same flow; next tip is implemented; or futurehome improves the import tool to do this automatically).
  • To avoid head-scratching for anyone importing your code, you could implement if-statements as follows: Set variable = false as condition and draw a line from the yellow circle instead of from the green circle (flow will continue by default - even when if the variable is not set).
  • The timeout (orange) and error (red) handlers are there for a reason, especially in Action nodes, and especially useful for battery-powered devices. You can for example choose to receive a push notification whenever a timeout or error occurs and use that information to troubleshoot.
  • The Receive (wait for event) node will not do anything to initiate sending of anything - it should normally be used directly downstream of an action node (for example evt.lvl.report). Should never be used without a defined timeout and timeout logic. See also next tip.
  • Each flow (everything you see on one screen in the UI) can have multiple triggers and sub-flows.
  • Setting up separate triggers such as evt.lvl.set and evt.binary.set to store info in variables doesn’t “cost” anything in terms of z-wave network capacity, and is preferred over using the Receive (Wait for event) node, unless it is used to confirm an action initiated by the same flow. For maximum reliability it should be allowed to run in parallell with main flow, so sometimes you need to split into separate flows and use global variables.
4 Likes