Files
home-assistant/packages/presence/presence.yaml

228 lines
6.5 KiB
YAML

# Presence Detection Package
# -----------------------------------------------------------------------------
# Person Setup (handled by UI)
person:
# -----------------------------------------------------------------------------
# Person/Device Tracker Customization
homeassistant:
customize:
person.jpk:
entity_picture: https://gravatar.com/avatar/e78e623948f3675cf1c51544f9bec928
sensor.jp_presence_status:
entity_picture: https://gravatar.com/avatar/e78e623948f3675cf1c51544f9bec928
# -----------------------------------------------------------------------------
# Extended Presence States
input_select:
jp_presence_state:
name: J.P.
options:
- Home
- Just Arrived
- Just Left
- Away
- Extended Away
jen_presence_state:
name: Jen
options:
- Home
- Just Arrived
- Just Left
- Away
- Extended Away
house_presence_state:
name: House Occupancy
options:
- Home
- Just Arrived
- Just Left
- Away
- Extended Away
# -----------------------------------------------------------------------------
# Extended Presence Sensors
template:
- binary_sensor:
- default_entity_id: binary_sensor.jp_presence
device_class: presence
name: J.P.
state: '{{ is_state("person.jpk", "home") }}'
- default_entity_id: binary_sensor.jen_presence
device_class: presence
name: Jen
state: '{{ is_state("person.jen", "home") }}'
- default_entity_id: binary_sensor.house_presence
device_class: presence
name: House
state: '{{ is_state("person.jpk", "home") or is_state("person.jen", "home") }}'
- sensor:
- default_entity_id: sensor.jp_presence_status
name: J.P. Presence Status
state: '{{ states.input_select.jp_presence_state.state }}'
- default_entity_id: sensor.jen_presence_status
name: Jen Presence Status
state: '{{ states.input_select.jen_presence_state.state }}'
- default_entity_id: sensor.house_presence_status
name: House Presence Status
state: '{{ states.input_select.house_presence_state.state }}'
# -----------------------------------------------------------------------------
# Automations for Presence Detection
automation:
# Handle Just Arrived/Just Left State Transitions
- alias: Mark Person as Just Arrived
trigger:
- platform: state
entity_id: person.jpk
to: 'home'
- platform: state
entity_id: person.jen
to: 'home'
- platform: state
entity_id: binary_sensor.house_presence
to: 'on'
mode: queued
action:
- service: input_select.select_option
data_template:
entity_id: >
{% if trigger.entity_id == 'person.jpk' %}
input_select.jp_presence_state
{% elif trigger.entity_id == 'person.jen' %}
input_select.jen_presence_state
{% elif trigger.entity_id == 'binary_sensor.house_presence' %}
input_select.house_presence_state
{% else %}
{% endif %}
option: >
{% if trigger.entity_id == 'person.jpk' %}
{% if states.input_select.jp_presence_state == 'Just Left' %}
Home
{% else %}
Just Arrived
{% endif %}
{% elif trigger.entity_id == 'person.jen' %}
{% if states.input_select.jen_presence_state == 'Just Left' %}
Home
{% else %}
Just Arrived
{% endif %}
{% elif trigger.entity_id == 'binary_sensor.house_presence' %}
{% if states.input_select.house_presence_state == 'Just Left' %}
Home
{% else %}
Just Arrived
{% endif %}
{% else %}
{% endif %}
- alias: Mark Person as Just Left
trigger:
- platform: state
entity_id: person.jpk
from: 'home'
- platform: state
entity_id: person.jen
from: 'home'
- platform: state
entity_id: binary_sensor.house_presence
from: 'on'
mode: queued
action:
- service: input_select.select_option
data_template:
entity_id: >
{% if trigger.entity_id == 'person.jpk' %}
input_select.jp_presence_state
{% elif trigger.entity_id == 'person.jen' %}
input_select.jen_presence_state
{% elif trigger.entity_id == 'binary_sensor.house_presence' %}
input_select.house_presence_state
{% else %}
{% endif %}
option: 'Just Left'
# Handle Timed State Changes to Home/Away/Extended Away
- alias: Mark Person as Home
trigger:
- platform: state
entity_id: input_select.jp_presence_state
to: 'Just Arrived'
for:
minutes: 5
- platform: state
entity_id: input_select.jen_presence_state
to: 'Just Arrived'
for:
minutes: 5
- platform: state
entity_id: input_select.house_presence_state
to: 'Just Arrived'
for:
minutes: 5
mode: queued
action:
- service: input_select.select_option
data_template:
entity_id: '{{ trigger.entity_id }}'
option: 'Home'
- alias: Mark Person as Away
trigger:
- platform: state
entity_id: input_select.jp_presence_state
to: 'Just Left'
for:
minutes: 5
- platform: state
entity_id: input_select.jen_presence_state
to: 'Just Left'
for:
minutes: 5
- platform: state
entity_id: input_select.house_presence_state
to: 'Just Left'
for:
minutes: 5
mode: queued
action:
- service: input_select.select_option
data_template:
entity_id: '{{ trigger.entity_id }}'
option: 'Away'
- alias: Mark Person as Extended Away
trigger:
- platform: state
entity_id: input_select.jp_presence_state
to: 'Away'
for:
hours: 24
- platform: state
entity_id: input_select.jen_presence_state
to: 'Away'
for:
hours: 24
- platform: state
entity_id: input_select.house_presence_state
to: 'Away'
for:
hours: 24
mode: queued
action:
- service: input_select.select_option
data_template:
entity_id: '{{ trigger.entity_id }}'
option: 'Extended Away'