Best way to build a rule based on a distance

You may need to add either a filter on the Arduino side to prevent sending the rogue values or a filter on the OH side to ignore the rogue values.

On the OH side you would create a rule which processes the incoming MQTT values. If the value is beyond the possible (e.g. larger or smaller than the last value by a lot) drop it. Otherwise pass it on to a proxy item. In your case I think the proxy item is your switch.

As to your received update, are you triggering this rule based on a Group Item? If not, one message from MQTT should only result in one update to that Item. But because of the way Groups aggregate their state one change to an Item in a Group results in multiple updates to the Group.

If you are not triggering off of a Group Item, then something else weird is going wrong. But you can filter out a lot of the noise by using changed as your trigger instead of received update. That will only trigger the rule if the Number actually changes causing repeated updates from the same state change to be ignored.

If you do not want to update your proxy item until the Number Item has been stable for a period of time you can use a Timer to implement a Latch.

var Timer timer = null

rule "Desk state changed"
when
    Item MyNumberItem received update
then
    if(timer == null){
      timer = createTimer(now.plusMinutes(2), [|
          // calculate whether the switch should be ON or OFF based on the current state of MyNumberItem
        MySwitchItem.sendCommand( new_state )
        timer = null
      ]
    }
end

In the above rule the first time a change occurs a timer is created that goes off in two minutes. All triggers of the rule that occur while the timer is waiting to go off are ignored. When the timer does go off it sets MySwitchItem to the appropriate value based on what MyNumberItem is at that time. The timer gets reset to null and the cycle repeats on the next update.

Personally, I don’t think this is the right way to go. There is something else going on that smells fishy but with the limited information provided it is the best I can do.