Page 1 of 1

How to DEBUG your RULES

Posted: 31 Mar 2019, 19:03
by dampa
Here is my method for debugging RULEs while I'm developing and I hope it helps some people out.

First thing is to add a 'Generic - Dummy Device', name it 'data' and name one of the variables 'debug'. For our example, let's assume you select device 12 and named the first variable 'debug' .

Now in your rules just add anywhere you want
TaskValueSet,11,1,n.m // debug
I suggest if you have more than one 'on xxxxx do' use 1.m for the first on/do, 2.m for the second etc. In addition change m for each debug spot. As the rules fire, the variable will change telling you where you are. It's really helpful when your rules do what you told them to do, not want them to do. :D

Or in other words, things just don't work and you don't know why. This will at least tell you the last part of the rule that worked.

Here is an example from a ruleset I use
==============
on dataReq do
TaskValueSet,12,1,1.1 // debug <<<<<<<<<<<<<<<<<

TaskValueSet,12,1,%eventvalue1% // set rxGroupID from received message
TaskValueSet,12,2,%eventvalue2% // set rxNodeID from received message
TaskValueSet,12,3,%eventvalue3% // set requesterID from received message

// is this a 'all' group or a requset for my group
if [rx#rxGroupID] = [my#groupID] or [rx#rxGroupID] = 0
TaskValueSet,12,1,1.2 // debug <<<<<<<<<<<<<<<<<
event checkNode // yes go check node requested
endif
endon

on checkNode do
TaskValueSet,12,1,2.1 // debug <<<<<<<<<<<<<<<<<
// is this a 'all' nodes or a request for my node
if [rx#rxNodeID] = [my#nodeID] or [rx#rxNodeID] = 0
TaskValueSet,12,1,2.2 // debug <<<<<<<<<<<<<<<<<
event sendData // yes go send the data
endif
endon
==============

Re: How to DEBUG your RULES

Posted: 04 Apr 2019, 13:46
by dynamicdave
What a clever idea.
It will be extremely useful in developing some of my Rule-Sets.
Thanks for sharing.

Re: How to DEBUG your RULES

Posted: 06 Apr 2019, 21:44
by lairnewtons
What a great idea?!
I luve it! Very useful!
Thank for sharing :D