Increment/decrement property using core nodes

My cheerlights flow got itself trapped in a loop so I want to add a counter and get it to give up after 10 attempts

So I added a change node at start of flow to set flow.attempts to 10 and then added a switch later on in the loop to detect if attempts < 0

Then I went to add something to decrement flow.attempts and realised that I couldn't come up with anything to do that (without code)

I'm wondering if maybe the change node could have an increment option added to let us do this?

Or is there an easy method I've missed?

Well, not as simple as chosing an increment drop down but, not sooo difficult
chrome_kZKrTYVwqn

image

Simon, I sometimes think your aversion to function nodes is counter productive :wink: (see what I did there :laughing: )

I am the ultimate block-based programmer evangelist - someone has to fight the good fight :slight_smile:

Node-RED should (IMO) always (as it does in LOTS of cases) let us do simple operations without coding

And of course, even when I code, I 99% use Bart's Blockly node :slight_smile:

3 Likes

Actually I can envisage a simple node that does things like this... but of course the instant reaction is scope creep... I would want simple add, subtract, multiply, divide etc of the "payload" by a constant, (eg see Steve's buffer parser) or flow/global property... oh and then combinations like multiply and add etc (degC to degF etc). - oh then maybe AND, OR, XOR - etc etc... Not saying it can't be done (probably should be) - - but needs some design work first - and then indeed should it be part of the change node ? (see other recent discussions on change node) - or a new numeric only calculator node ?

1 Like

This is something I've been thinking about - having a core set of nodes for common operations on standard JavaScript types.

There is already the node-red-contrib-string as a node that provides common string functions - not saying that's quite the model I had in mind, but it is along those lines.

A Maths node could provide operations for numeric types.

An Array node could do simple push/pop/splice etc type operations.

I think it would be worth putting together a concept for it.

Nick

4 Likes

Super duper :slight_smile:

And maybe a conversions node? I could see that would be REALLY useful.

These nodes would also help take Node-RED into improving some areas that it is weak on compared to some other visual tools as well which would be nice. One day, it would be wonderful to be able to use Node-RED to do ETL tasks that people currently switch to Python for. :grinning:

I was wondering if the join node could have an add/minus/multiply/divide setting for numbers with a starting number?

I just wanted to subtract 1 from a number .......

:slight_smile:

Surely you can do that in the blockly node :rofl:

If someone does a node-red-contrib-just-subtract-one node, can they also assemble an end to end illustrated tutorial to get from the idea n -=1 to a published node?

It's an intimidating stage of the learning curve.

1 Like

Dave, can i borrow your crystal ball please?

image

1 Like

eg see -

... that's how it always starts... :slight_smile:

... or should that be a "Math" node ...

2 Likes

You know, I read and re-read Julians comment as a conversations node. I pondered and pondered and ...

I was scared to ask about what sorcery I was missing out on.

1 Like

It's Friday... I was too blinkered to think that far out of the box... if he had said that I would have missed it

That is a can of worms you just opened. I'm with knolleary on this.

The only difference is that math is preferred in the U.S. and Canada, and maths is preferred in the U.K., Australia, and most other English-speaking areas of the world.

me too... I was just have a Friday afternoon moment...

1 Like

I very nearly wrote Math(s) in my original reply... but my en_GB nature shone through.

2 Likes

There was a recent conversation on slack about adding a local context to the change node, perfect for things like keeping a counter that can be modified by any expression syntax... perhaps it's time to rethink that as it's a general purpose solution?

And I think we have now demonstrated that we are the wolves in the out-of-control trolley!

2 Likes