Another way is to use the Expire binding, this will eliminate the need to use a timer and lambda in your rule. What you have above will work fine but be aware if you have several rules that use lambda’s there’s a chance it may have problems when two or more try to run at the same time.
Also see this example for anti flapping in a rule https://community.openhab.org/t/rule-optimization-window-open-reminder/39451/12?u=h102
If your asking how to use this logic in your rule.
when sensor_x update
then
createTimer(now.plusSeconds(1)) [ | proxy_sensor_x.sendUpdate ]
You need to define the variable Timer, the rule will look similar to this:
var Timer sensorTimer
rule "your_rule"
when
Item sensor_x changed
then
if(senosr_x == ON){
sensorTimer = createTimer(now.plusSeconds(1), [ |
proxy_sensor_x.postUpdate(ON)
])
}
end
Just for more idea’s here’s an example for a motion detector.
If your sensor triggers ON/OFF (0 and 1 in the example) several times you can use a counter in the rule similar to this:
var timerCount = 0
rule "timer"
when
Item Esp_Easy_Motion changed from 0 to 1
then
if(Esp_Easy_Motion.state != NULL) {
timerCount +=1
timer.postUpdate(timerCount)
}
end
rule "timer count"
when
Item timer changed
then
if(timerCount >= 3 && Couch_Light.state != ON){
Couch_Light.sendCommand(ON)
timerCount =0
timer.postUpdate(timerCount)
}
else if(timerCount >= 3 && Couch_Light.state != OFF){
Couch_Light.sendCommand(OFF)
timerCount =0
timer.postUpdate(timerCount)
}
end
Just adjust the counter number to suit your needs.