Current State Node, add 1 to the entity value using jsonata?

I can use a Current State Node in Node Red to get the value of an entity. I would like to instead get the value of the entity plus 1. Is that possible?

I tried to set the msg.count output property to jsonata “payload + 1”, but it does not like that, because payload has not actually been set yet. Is there a way to refer the the state value of the chosen entity in Jsonata so I can add 1 and return that to the next node?

Thanks

Looks like this is the answer:

$number($entity().state) + 1

Next time it might help to tell us what you are talking about (Node Red?) or at least pick the correct forum category.

Just in case it is useful for anyone else searching for this in the future, it is also possible to put multiple outputs in a single “Current state node”, and they can all be read in the following nodes. You just include the name of the sensor(s) that you want to put in the output, or example:

$number($entities("sensor.my_counter").state)

You can even add multiple sensors together in an output:

$number($entities("sensor.my_counter_one").state) + $number($entities("sensor.my_counter_two").state)

Remember that the output has to be set to Jsonata.

Also, apologies, I forgot to select the Node Red topic. I was deep in the weeds and forgot to give that context.

1 Like