Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a simple timer similar to the jruby lanuage #406

Open
ubeaut opened this issue Dec 16, 2024 · 0 comments
Open

Create a simple timer similar to the jruby lanuage #406

ubeaut opened this issue Dec 16, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@ubeaut
Copy link

ubeaut commented Dec 16, 2024

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');

};

@ubeaut ubeaut added the enhancement New feature or request label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant