Blueprint | People Arrive or Leave

This is what I created.
This automation blueprint triggers actions when one or more selected people enter or leave a specific zone, such as home, work, or school. You can fine-tune when it runs using flexible time filters:

*Anytime
*Daytime (06:00–18:00)
Nighttime (18:00–06:00)
Specific Time Range
(e.g., 08:00–12:00)

Inputs:

  • Person(s)
  • Zone
  • Event Type: Enter or Leave
  • Time Filter: When the automation should trigger
  • Actions to perform
blueprint:
  name: Person Enter/Leave Zone with Time Filter
  description: >
    Trigger actions when selected people enter or leave a selected zone, with support for time filters (anytime, daytime, nighttime, specific).
  domain: automation
  input:
    persons:
      name: Select Person(s)
      selector:
        entity:
          domain: person
          multiple: true

    zone:
      name: Zone
      selector:
        entity:
          domain: zone

    event_type:
      name: Event Type
      description: Trigger when the person enters or leaves the zone
      selector:
        select:
          options:
            - Enter
            - Leave

    time_filter:
      name: Time Filter
      description: When should the automation be active?
      selector:
        select:
          options:
            - Anytime
            - Daytime (06:00-18:00)
            - Nighttime (18:00-06:00)
            - Specific Time

    specific_time_start:
      name: Specific Time Start
      default: "00:00:00"
      selector:
        time: {}

    specific_time_end:
      name: Specific Time End
      default: "23:59:59"
      selector:
        time: {}

    actions:
      name: Actions
      description: What to do when the trigger happens
      selector:
        action: {}

mode: single

variables:
  zone_entity: !input zone
  trigger_event: !input event_type
  selected_time_filter: !input time_filter
  specific_start: !input specific_time_start
  specific_end: !input specific_time_end

trigger:
  - platform: state
    entity_id: !input persons

condition:
  - condition: template
    value_template: >
      {% set to_state = trigger.to_state.state %}
      {% set from_state = trigger.from_state.state %}
      {% set zone_name = state_attr(zone_entity, 'friendly_name') %}
      {% if trigger_event == 'Enter' %}
        {{ from_state != zone_name and to_state == zone_name }}
      {% else %}
        {{ from_state == zone_name and to_state != zone_name }}
      {% endif %}

  - condition: or
    conditions:
      - condition: template
        value_template: "{{ selected_time_filter == 'Anytime' }}"

      - condition: and
        conditions:
          - condition: template
            value_template: "{{ selected_time_filter == 'Daytime (06:00-18:00)' }}"
          - condition: time
            after: "06:00:00"
            before: "18:00:00"

      - condition: or
        conditions:
          - condition: template
            value_template: "{{ selected_time_filter == 'Nighttime (18:00-06:00)' }}"
          - condition: time
            after: "18:00:00"
          - condition: time
            before: "06:00:00"

      - condition: and
        conditions:
          - condition: template
            value_template: "{{ selected_time_filter == 'Specific Time' }}"
          - condition: template
            value_template: >
              {% set now_time = now().strftime('%H:%M:%S') %}
              {{ specific_start <= now_time <= specific_end }}

action: !input actions

1 Like

Hello shivam-yadav,
Welcome to the Home Assistant Forum!

Thanks for contributing to the community with a new Blueprint.

I have a suggestion for you. Many people who are not familiar with directory structures will have problems installing this without the Home Assistant MY tools.
Adding a MY link for this Blueprint to your top post would help them a lot.

Here is the link to make that.
Create a link – My Home Assistant

1 Like