[SOLVED] How to divide numeric values from mqtt

Tags: #<Tag:0x00007f6171020b78> #<Tag:0x00007f6171020a38>

Hi All.
i have cam to a wall. i have info that comes from my Raspberry pi via node red sent with mqtt.
the values need to be divided for huamen reading. and som persentage calculations.

i am not sure where to start ? is there documents that can help me to do it ?
will it be rule base or transformation. ?
example of some calcs that needs to be done .

  1. (value1 / 1000000)/(value2/1000000)=(ans)/100 = %
  2. V1/1000000 = to item on site map

Thank you

Why don’t you change the payload in node-red BEFORE sending it to openHAB?

did not know i could :see_no_evil::face_with_hand_over_mouth::rofl:

will see if i can figure it out. did not know

If you want to change the number before it get’s set to the Item you would use a JS Transformation to do the math on the number.

If you want to change how it appears on your UIs, you can use a JS Transformation on the label.

As an alternative, you can use a Proxy Item and a Rule to do the math and set the result to the proxy Item.


But as Vincent indicates, it’s always preferable to fix this sort of thing at the source.

1 Like

i will have a look at how to do it at the source. as i only used node red . as a simple interface betwoon the db and my OpenHAB server. with basic send temp to mqtt and the pi’s gpio. now i want to do some more integrated stuff. will learn and break some stuff to get it up and running.

lol it was a lot easier to change it in node red as i thought .
i did the division and also the percentage calculations very easily.

Thanks for pointing me in the right direction.

Will add a small how to as soon as i get home . with my example