Hubitat app that turns off your devices after they have been on some time.
The app allows you to select switches you want to be turned off automatically. Each switch is tracked individually but they all share the auto-off time setting. If you need different auto-off times for different switches, just add another instance of this app.
I have a few lights in the house that always seem to be left on. Sometimes the bathroom lights are left on for a few hours and sometimes the basement lights are left on so long that I can feel the hot spots on the floor above.
I had RM rules to deal with this but since you can't reference the trigger device (yo @joe.roback), I ended up with a lot of copies of the same logic. That bothers an OCD hobgoblin.
This app is cleaner to maintain after a dealing with just few lights in the house. It also took me a few times to learn about 'Cancellable" actions in RM that are required if you use Delay to implement this. Anyway, this app makes it all very easy.
This looks great. I too have about a dozen different RM rules for turning closet lights off.
The only thing I would add would be a switch to disable the auto-off. I have a virtual switch for lighting automatons that when turned off the RM rules don't run due to a condition.
It's code so it could do that but to keep the implementation clean I request a single callback every minute from the hub and see if there is anything to be done. Making it seconds would require me to increase the callback frequency or to add more complexity in the code. You can open up an Issue over at the GitHub repository but to be honest I'm probably going to keep it super simple, low-frequency, and low hub resource use.
Won't work since the offList is only checked every minute.
Edit: I was going to give you a patch to increase the resolution to seconds using the cron-style scheduler but I'm seeing that it doesn't allow less than one minute between callbacks either. Hubitat wants apps to behave and not be too busy, so no luck, unless I refactored it to use runIn() that has seconds resolution. I thought about that but going to stay away from that rabbit hole for now.
Great work, it fixed my issues when I was trying to use the delay timer built into RM, specifically regarding my startup procedure and when the internet is in an unknown state.
As a result, the delay action was called with at an incorrect time code, since the internet was down at that time, and then when the time got updated, since the internet came up, it would jump past the time at which it would trigger the delayed action, causing that action to never get called.
The unpredictable time codes are still an issue with your app, but I am guessing your comparison is not just an "equal to" comparison, so if/when the time gets updated, the auto-off still triggers even if the jump is massive, which is fine for me since I am controlling a network device and once the internet is online, it no longer has to be.
Anyway, thank you, very simple setup and it works very well.
The implementation is pretty naive and simple since I wanted a rock solid app, not a clever one with potential issues. I'm actually storing the requested off-time in native microsecond resolution and checking if now() is greater than that time for any registered device that has turned on, every minute. Not optimized but good enough
FYI for anyone using the app:
One side effect is that the actual time before the device is turned off can be as long as 59.999999 seconds after the requested off delay since the list is only checked every minute.
Cool app, I was looking for something exactly like this as setting up a rule in RM for each device is tedious in the extreme, even if using the cloning feature!
Does this run a timer for each individual device or a global timer?
Btw, my only suggestion for improving this awesome app is to add an option for using a house mode or virtual switch to prevent timers from running. eg I have a virtual switch called WFH that disables my rule machine 1hr timer for my Study lights and switch to a 4 hour timer instead.
It would also be nice to have timers disabled while the house is in eg Away mode so I can run a random lights program at night that simulates us being home.
No, I wanted to keep this app as simple as possible (implementation-wise) so there is one timer per app instance. The app gets a callback every minute and checks if any lights have been on for longer than it should. I was considering doing a callback for each device but decided against it since the only downside of a single timer is that it may take 59 seconds longer for a device to turn off, but the code complexity would be much higher.
You can probably do that with virtual switches and the master switch in the Auto-Off app. Have two instances of Auto-Off, one with 1-hour and the other with 4-hour. Add all devices to both Apps. Make a virtual switch that is the inverse of another virtual switch, feed one virtual into the 1-hour instance, and the inverted into the 4-hour.
Z-Wave or Z-Wave Plus? It matters because Z-wave non-plus don't report state changes. Which is why you see so many recommendations to replace them. You could poll them on a limited basis but it causes a lot of noise on the z-wave network and is generally not recommended.