Arriving and leveeing scene automation

hello my dears
i need your help to create a an automation
when the first person arrive at the house the home scene switch on
when the last person leaves the house the away scene switches on.
can you help, please?
thanks.

group:
  everyone:
    entities:
      - person.1
      - person.2
      - person.3

automation:
  alias: All home or away
  trigger:
    platform: state
    entity_id: group.everyone
  action:
    service: homeassistant.turn_on
    data:
      entity_id: "scene.{{ 'home' if trigger.to_state.state == 'home' else 'away' }}"
1 Like