Turning off device that has been on more than a specified time

I have devices that are automated to be turned on and off based on sensors such as motion, humidity etc but some family members just turn them on manually and forget to turn them off. Or the time period built into these automations does not survive a restart.

Is there a way to create automations that turn off these devices after a certain time period of being on as sensed by HA regardless of how they were turned on?

Thanks

Any automation won’t survive a restart, you could have an action that fires when HA starts to toggle the lights if they are on so they stay on X minutes more before auto off.

Otherwise, the automation you just need to put a Delay in your automation between turn on and turn off, I usually also set the automation to restart if retriggered so it doesn’t go out while someone is still in the room.

I did no know that there are actions that can be taken on HA (re)start. What is the trigger for HA starting?

Also, I am familiar with using delays in automations for when the automation is turning the device on. If it was turned on manually, is the trigger the device turning on which then starts a delay measurement?

Thanks

On should be on, so it detects on and it gets fired. As for manual turn on, you have to see if your device reports that since not all differentiate between turned on at the paddle versus turned on via HA.

The restart is just how you configure your automation, by default it’s single but you can set it via the elipsis menu in the upper right.

image

You can use timers since they can be set up to survive restart and even store the time they were supposed to finish.

1 Like
  trigger:
  - event: start
    platform: homeassistant

Thanks, everyone. I now have several things to try.

I now have a timer set up to start when a device is powered on and to be cancelled when the device is powered off. I’ve tested that it is working.

I don’t seem to be able to use it to shut down the device on the timer.finished event though. Is it supported as a trigger in the automation GUI?

Yes, by selecting “Manual Event” as your trigger type and filling in the appropriate information.

I wasn’t using entity_is: before the timer :frowning:

Works now!

Thanks