You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How about a simple javascript timer where you just type in the command and the device and the amount of time and the action?
example openhabTimer(device, ON, OFF, 10m)
Here is jruby example:
Switch.command(ON, for: 5.minutes)
Switch.on for: 5.minutes
Dimmer.on for: 5.minutes, on_expire: 50
Dimmer.on(for: 5.minutes) { |event| Dimmer.off if Light.on? }
Currently to do a javascript timer it takes about 13 lines of code!
This is how I am doing it now:
cachename=ctx.ruleUID
console.log("cachename : " + cachename)
//turn the light off after X minutes
var zmtimer=10
if (cache.private.exists('cachename') === false || cache.private.get('cachename').hasTerminated()) {
items.getItem("zigbee_switch_4_gang_switch_2").sendCommand("ON")
console.log('The script ran top level command ON');
cache.private.put('cachename', actions.ScriptExecution.createTimer('cachename', time.ZonedDateTime.now().plusMinutes(zmtimer), function () {
items.getItem("zigbee_switch_4_gang_switch_2").sendCommand("OFF")
console.log('The script ran 2nd level command OFF');
How about a simple javascript timer where you just type in the command and the device and the amount of time and the action?
example openhabTimer(device, ON, OFF, 10m)
Here is jruby example:
Switch.command(ON, for: 5.minutes)
Switch.on for: 5.minutes
Dimmer.on for: 5.minutes, on_expire: 50
Dimmer.on(for: 5.minutes) { |event| Dimmer.off if Light.on? }
Currently to do a javascript timer it takes about 13 lines of code!
This is how I am doing it now:
cachename=ctx.ruleUID
console.log("cachename : " + cachename)
//turn the light off after X minutes
var zmtimer=10
if (cache.private.exists('cachename') === false || cache.private.get('cachename').hasTerminated()) {
items.getItem("zigbee_switch_4_gang_switch_2").sendCommand("ON")
console.log('The script ran top level command ON');
cache.private.put('cachename', actions.ScriptExecution.createTimer('cachename', time.ZonedDateTime.now().plusMinutes(zmtimer), function () {
items.getItem("zigbee_switch_4_gang_switch_2").sendCommand("OFF")
console.log('The script ran 2nd level command OFF');
}));
} else {
cache.private.get('cachename').reschedule(time.ZonedDateTime.now().plusMinutes(zmtimer));
items.getItem("zigbee_switch_4_gang_switch_2").sendCommand("ON")
console.log('The script rescheduled the command ON');
};
The text was updated successfully, but these errors were encountered: