Turn on lights using door sensor only if group has been home < xx minutes

I have a simple automation to turn on two light switches in our kitchen when we open our sliding door. This works well, but I would like it to only run when a group (my wife and I are in a group, group.family) goes from not_home to home within the past 5 minutes. I think this would prevent them from turning on when we’re already home and might not want them to turn on again. I have tried to play with triggers using our group as well as going from not_home to home with the option time, but I can’t get it to work, or if it is even possible

Any help would be greatly appreciated.

John

I have a similar automation and your post made me think about how to do this. Haven’t tried it yet, but have you tried using the door sensor as the trigger and the group presence as a condition?

I have not. I have the door sensor as a trigger as well as the group. I just looked into the condition, but with using “state” and the group as the entity id, it doesn’t give the option for the “from (optional)” and “to (optional)”, which I think would be needed to know that one of us just recently got home.

If this were a single entity and not a group, I would use the the state value - ‘home’. You can try it with a group, but I’m not sure what the value is going to be if one person is home and the other is not. Would have to test that one. If it doesn’t work just use the entities of the two phones in an ‘OR’ condition

condition: state
entity_id: group.zone_presence
state: home
for:
  hours: 0
  minutes: 3
  seconds: 0

Scratch that. This actually measures more than 3 minutes, not 3 minutes or less.

You should be able to create a template condition that checks group.family is ‘home’ AND group.family last changed is less than 5 minutes from now().

I looked into this a bot last night and it’s over my head. I’ll keep reading through it. Thanks for pointing me in the right direction.