Presence detection + Saving State Automation

alias: Office Occupancy
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.office_occupancy
    from: 'on'
    to: 'off'
    for:
      minutes: 5
  - platform: state
    entity_id: binary_sensor.office_occupancy
    from: 'off'
    to: 'on'
condition: []
action:
  - if: "{{ trigger.to_state.state == 'off' }}"
    then:
      - service: scene.create
        data:
          scene_id: automated_office_state_lights
          snapshot_entities:
            - light.office_main_lights
            - light.office_floor_lamp
            - light.office_table_lamp
      - service: light.turn_off
        target:
          entity_id:
            - light.office_main_lights
            - light.office_floor_lamp
            - light.office_table_lamp
    else:
      - service: scene.turn_on
        target:
          entity_id: >
            scene.{{ 'automated_office_state_lights' if states.scene.automated_office_state_lights.state is defined else 'office_working' }}
mode: single

EDIT

Correction. Fixes list of snapshot_entities