Nodered - Doing basic calculations with values coming from Openhab Items

Hello,

I am trying to do a basic calculation with values coming from an openhab item. I have an temperature sensor (temp) and I would like to set a variable in my flow that with an increased value.

e.g. tempupperlimit = temp + 5

What is the best option to do this? I tried change nodes and function nodes but I am having issues with both. This is one attempt but both options do not work:

[{"id":"1d780b0c.c182c5","type":"change","z":"a410c438.eb0a28","name":"kellertempupper","rules":[{"t":"set","p":"payload","pt":"msg","to":"kellertemp+5","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":160,"wires":[[]]},{"id":"d821711a.502e2","type":"openhab2-in","z":"a410c438.eb0a28","name":"KellerTemp","controller":"a266d42c.a10f68","itemname":"KellerTemp2","x":100,"y":200,"wires":[["b7108d7f.d9a77"],[]]},{"id":"226e70ff.66cc9","type":"change","z":"a410c438.eb0a28","name":"kellertemplower","rules":[{"t":"set","p":"kellertemplower","pt":"flow","to":"kellertemp - 2","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":220,"wires":[[]]},{"id":"b7108d7f.d9a77","type":"change","z":"a410c438.eb0a28","name":"","rules":[{"t":"set","p":"kellertemp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":200,"wires":[["226e70ff.66cc9","1d780b0c.c182c5"]]},{"id":"a266d42c.a10f68","type":"openhab2-controller","z":"","name":"Openhab","protocol":"http","host":"localhost","port":"8080","path":"","username":"openhabian","password":"xxxxxx"}]

image
image

With a function node:

[{"id":"25a35b64.4ba534","type":"openhab2-in","z":"a410c438.eb0a28","name":"KellerTemp","controller":"a266d42c.a10f68","itemname":"KellerTemp2","x":80,"y":620,"wires":[["b0fbe46b.b856d8"],[]]},{"id":"b0fbe46b.b856d8","type":"change","z":"a410c438.eb0a28","name":"","rules":[{"t":"set","p":"kellertemp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":620,"wires":[["6089a96e.b5beb8"]]},{"id":"677902ef.75fb7c","type":"debug","z":"a410c438.eb0a28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":680,"y":620,"wires":[]},{"id":"6089a96e.b5beb8","type":"function","z":"a410c438.eb0a28","name":"","func":"var temp = { payload: msg.payload };\ntemp = temp + 5\nreturn temp;","outputs":1,"noerr":0,"x":470,"y":620,"wires":[["677902ef.75fb7c"]]},{"id":"a266d42c.a10f68","type":"openhab2-controller","z":"","name":"Openhab","protocol":"http","host":"localhost","port":"8080","path":"","username":"openhabian","password":"xxxxxx"}]

image

var temp = { payload: msg.payload };
temp = temp + 5
return temp;

I get the error:
Function tried to send a message of type string

Am I completely on the wrong track for my purpose?

BR,
Martin

Another attempt:

var temp = { payload: msg.payload };
temp = Number(temp);
temp = temp + 5;
return temp;

Here is the solution:
image

image

1 Like
return msg.payload + 5;

Should suffice in a function node
or maybe:

msg.payload = msg.payload + 5;
return;