I have this rule to automatically turn off a switch after turn on. I’m looking for a way to set up a slider to dynamically set the minutes to turn off for every on. I want the slider to be between 30 and 180 minutes.
Any ideas?
my rule:
var Timer timer = null
rule "Timer Demo"
when
Item The_blue_Led received command
then
if (receivedCommand == ON) {
if (timer === null) {
// first ON command, so create a timer to turn the light off again
timer = createTimer(now.plusMinutes(30)) [|
sendCommand(The_blue_Led, OFF)
]
} else {
// subsequent ON command, so reschedule the existing timer
timer.reschedule(now.plusSeconds(30))
}
} else if (receivedCommand == OFF) {
// remove any previously scheduled timer
if (timer !== null) {
timer.cancel
timer = null
}
}
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
2
Hi
That sounds simple enough.
You just need a number Item to store the valve and allow you to change it in a UI.
(Don’t forget to use some kind of persistent to restore the value after a reboot)
Then poll that item during the rule.
New Item might be called “LED_Duration”
var Timer timer = null
rule "Timer Demo"
when
Item The_blue_Led received command
then
var duration = (LED_Duration.state as Number).intValue // so the value is available to all timers
if (receivedCommand == ON) {
if (timer === null) {
// first ON command, so create a timer to turn the light off again
timer = createTimer(now.plusMinutes(duration)) [|
sendCommand(The_blue_Led, OFF)
]
} else {
// subsequent ON command, so reschedule the existing timer
timer.reschedule(now.plusSeconds(duration))
}
} else if (receivedCommand == OFF) {
// remove any previously scheduled timer
if (timer !== null) {
timer.cancel
timer = null
}
}
end
Thank you very much. it’s working.
The slider only sets between 0-100 where i need 30 to 120. I added 30 to the var duration and I get 30 to 130 which is close enough. all I need now is to figure out how to display the calculated number…