hufftheweevil / node-red-contrib-persistent-fsm

A Node Red node that wraps around Javascript State Machine
Other
4 stars 7 forks source link

State Machine - How to Compare Numbers? #11

Closed wilwizard1979 closed 1 year ago

wilwizard1979 commented 1 year ago

Hello, I´m trying to learn and do some tests with the State Machine Node, but I´m having problems to use number comparisons. The = works fine, but the > #number seems to require a certain syntax that I´m not sure.

Below the very simple flow I´m testing: image

And the configuration inside:

image

The >400 doesn´t work and it seems the Node waits for a string ">400" but not an actual number that is over 400.

The trigger State Node is configured to Number. What am I doing wrong?

hufftheweevil commented 1 year ago

Traditionally, FSMs don't usually accept triggers/cases that are conditionals like that. I don't have any plans to modify this node to accept stuff like that. However, an easy solution is to add a node(s) before the state machine that checks the value and changes it to ">400" if it is indeed over 400. This could be done many ways, but probably the easiest would be with a function node with the following:

if (msg.payload > 400) msg.payload = ">400" // or check whatever property you're using for the trigger
return msg
hufftheweevil commented 1 year ago

Closing for now, but please feel free to ask more questions if you have any