[RELEASE] Auto Off - Automatically turn off devices after set amount of time on

Auto Off

Hubitat app that turns off your devices after they have been on some time.

Details

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.

Use Case

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.

Import App Link

https://raw.githubusercontent.com/MFornander/Hubitat/master/apps/AutoOff/AutoOff.groovy

Screenshot

Versions

  • 1.0.0 (2020-05-21) - Initial release
  • 1.1.0 (2020-05-23) - Add invert (auto on), and master switch options
5 Likes

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.

Is there way to set this up for seconds instead of minutes?

Sounds reasonable. Open up an "Issue" over at the GitHub repository and I'll see what I can do:
https://github.com/MFornander/Hubitat/issues

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.

state.offList[evt.device.id] = now() + autoTime * 60 * 1000

could try removing the * 60 so it doesn't convert the time to minutes. Not sure what kind of issues may result from that though.

there does appear to be checks for a newer/older version to the github repo though, so that might throw some wrenches into things as well.

Great code OP. Definitely better than going through each device individually or setting up rules for each device individually

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.

Version 1.1: Add invert (auto on), and master switch options

Ping @jason and @mark.oswell

1 Like

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 :slight_smile:

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.

Glad it worked!

2 Likes

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.

Similar setup with Home-Away.

1 Like

Any possibility of making the rules we create children of the app? No particular reason at the moment other than it triggers my OCD for some reason.

image

1 Like

Hi @lewis.heidrick and apologies to the OP for going of topic, but which site do you use for the emoji's you are using.
Thanks.

Emojipedia

Just click the copy button.

1 Like

Thanks again. :+1:

1 Like

I would like this too, it’ll just tidy up the app list.

1 Like

I’m having issues where it doesn’t turn off if I manually turn the switch on. Any thoughts?

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.

Plus. There’s an option for master switch and I’m wondering what that is for. I haven’t really read the code yet.