I have about 10 of these rules (turn off light after being on for a period) in Rules Engine. Is there any way to collapse them to one rule? Basically if any of these 10 devices is on for longer then x minutes then turn that specific light off
No, but this is a very simple app in Groovy. You can select as many lights as you want, and each will turn off however many seconds after turning on. See below:
definition(
name: "Lights Off After on",
namespace: "hubitat",
author: "Bruce Ravenel",
description: "Simple turn off after on lighting automation",
category: "Convenience",
iconUrl: "",
iconX2Url: ""
)
preferences {
section {
input "lights", "capability.switch", title: "Select lights to turn on then off", multiple: true, required: true
input "secs", "number", title: "Select number of seconds before off", defaultValue: 1, description: "1"
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
initialize()
}
def initialize() {
subscribe(lights, "switch.on", onHandler)
}
def onHandler(evt) {
runIn(secs, lightsOff, [data: [devName: evt.displayName], overwrite: false])
}
def lightsOff(data) {
lights.each {if(it.displayName == data.devName) it.off()}
}
@reachjeffs It's great to have samples from the Groovy Masters Can have a lot of fun with this "App template" -- he's shown the minimum, which is always a great place to start.
Can the timer (runIn) be canceled if the switch is manually turned off? To prevent the case where a switch is manually turned off and back on before the original timer expires? Maybe delete any existing timers for that switch before registering a new one. Does runIn return some type of handle which could be used to delete the timer?
Trigger just says "when this event happens, do something"
Triggered rule gives you some further options. "When this event happens, if some condition is met, do one thing, otherwise do another".
Take a garage door opening, for example. I want to get a notification when this happens.
If I just use a trigger, I can only say "When garage door opens, speak a message on my Google Home".
But a Google Home notification is no good when I'm not home. So if I convert this to a triggered rule, I can add different actions depending on whether I'm home or not:
"When garage door opens, if I'm home then speak a message on my Google Home, otherwise send a Pushover notification to my phone"
You can call unschedule(nameOfFunction) to cancel an existing schedule for that particular function.
So, for Bruce's example, you could cancel the runIn() by calling 'unschedule(lightsOff)'. If you call unschedule() without passing any arguments, it will cancel all schedules for that App or Driver.
For a completely different way to solve this problem, you can use a device that includes an automatic shutoff timer.
In my case, I use a Z-Wave smart plug to control a hot water recirculation pump. I always want the pump to shut off after 3 minutes. The plug has the option to set an automatic shutdown time. I programmed the plug to automatically turn off after three minutes anytime it's turned on.
This places the turn off logic in the device. This is perhaps not transparent to someone reading your rules later... "Where in these rules do you turn the device off?"...
What do you mean, "it's not working"? It doesn't shut the plug off? You don't show the restrictions part of the rule. What is displayed in the black bar at the top next to the rules name?
This should work...I'm not understanding why it wouldn't. Does BingBong update it's on/off state correctly when it's toggled? Is it turned on digitally, or physically?
Thanks. I was wondering that too ... when I go to the device page itself and tell it to go ON... and then refresh the page... it still says it is off. that is probably bad huh?
I still am having trouble understanding the Triggered Rule thing though and wondering if that is what I should be using... "Convert to triggered rule"