I am pretty new for openHAB, but maybe it can be done in these ways (unfortunately I don't have openHAB installed now, so it is just an idea, not tested).
1. Both short-click and long press reacting on button release and we manually counting how long it was pressed:
import java.util.Date
var long lastButtonPressTime
rule "short_long_press_v1"
when
Item MyButton changed
then
if ( MyButton.state == 1) {
lastButtonPressTime = new Date().time
} else {
if (new Date().time < lastButtonPressTime + 3000 ) {
// do short-click stuff
} else {
// do long-click stuff
}
}
end
2. Short-click react for button release but long-press react for timeout:
import org.openhab.model.script.actions.*
var Timer longPressTimer = null
rule "short_long_press_v2"
when
Item MyButton changed
then
if ( MyButton.state == 1) {
longPressTimer = createTimer(now.plusSeconds(3)) [| /* long-press stuff */]
} else {
if (globalLihghtOffTimer != null) {
var boolean cancelled = longPressTimer.cancel
globalLihghtOffTimer == null
if (cancelled) {
// do short-click stuff
}
}
}
end
P.S. Seems like GoogleGroups don't work good with Opera, so I don't know if my previous reply wasn't sent or this is just premoderation. I'm sending it in the second time, sorry if it will be double.
среда, 11 июня 2014 г., 23:59:15 UTC+3 пользователь
derc...@googlemail.com написал: