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

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.

@MFornander awesome simple app. I've been using a combination of RM and driver capabilities to accomplish the same function. I'd much prefer to use this app to consolidate preferences. Is there a recommended or least resource expensive way to do this? I would think a driver based "auto off" function would be best when possible, wondering if there's a best way?

Any chance of adding specific time to the OFF options?

I love this app for lights that people always tend to leave on. But one thing that has continuously frustrated me with HE is that Simple Automation doesn't allow you to pair "On at Sunset" with "Off at Specific Time."

Not that having an ON rule and OFF rule is much of a burden, but it just seems like something so basic.

For my holiday lights (I'm revisiting this again because Halloween is coming up), I want to turn them on at Sunset (+/-), but have them turn off at 11pm. So I currently have one rule for "On at Sunset" and a separate rule for "Off at 11pm."

Hardly killing me, but just grinds my gears.

Thanks!

RM4 is a large app, and generally purpose built apps are much smaller and execute faster. Also rules take very little resources so a bunch of simple rules are generally better than large complex rules.

1 Like