Turn on lights only if recently home?

Hi all,

I’m trying to turn on my inside lights when I open the door when I come home. How I want to do this is to create a binary sensor that turns on when I arrive home (via OwnTracks presence detection that’s already setup) and then turns off after 15 minutes. Without this condition my lights will turn on any time I open the door, even if I’m exiting.

Any ideas how I can do this?

change the device tracker part in the below template to suit. This goes in the condition part of your automation.

condition:
  - condition: template
    value_template: '{{as_timestamp(now()) - as_timestamp(states.group.all_tracked_devices.last_changed) < 60 }}'
1 Like

…so simple and here I was looking into input booleans and creating automations to turn it on and off. I didn’t know I could check the timestamps. Thank you!

no worries. To be honest I can’t take the credit as I had another forum member help me sort it out in the first place!

Actually I have found having an input_text which stores the ‘lights out’ time to be very useful.

I have lights which come on when it is dark and then go off normally at various predefined times.
I turn off certain lights when everyone goes out.
I turn on certain lights for 15 minutes if it is dark and the house becomes occupied.
I have a Dash button that will turn certain lights on again for one hour if they have gone off and for some reason we are up later than normal.
That same Dash button will turn those lights off again if an hour was too long.
I also have lights coming on and off at random times when we are on holiday.

I found it easier and more flexible to have all of these based off an input_text for each light containing whatever is the current ‘off’ time.

I’m not suggesting my way is best, just another way of looking at it and one that suits me.

1 Like

I like that idea too, it is definitely more flexible. For more complex automations I’ll certainly look toward using an input_text or some other input component. Thank you for sharing!