How to compare sensor values with a number

Hello everyone, I'm new here. I'm struggling to write a function that compare a sensor value with a number then return 1 if the sensor value equal or grater than the number and return 0 if it smaller. I'm using Modbus RTU (RS485) to receive the sensor value and control the Raspberry pin. Sorry for my bad English, i'm not a english speaker.

Welcome to the forum @Randomguys

If you make it just do what you have said, then when the value is very close to the number you are comparing it with, then the noise on the measurement may make it hop up and down a bit around that value, so the gpio pin will flick up and down, which is probably not what you want. You will probably need to apply a bit of hysteresis, so you get a small dead band around the number. Have a look at node-red-contrib-hysteresis which may do what you want. Set one threshold just above your comparison value and one just below it.

Thanks for reply my question but i haven't write the function yet. Can you help me with that ?

You don't need a function. Use the node I linked to instead.