Update Presence Automations
This commit is contained in:
@@ -53,4 +53,238 @@ device_tracker:
|
|||||||
jen_iphone_bt_entry: monitor/entry/jen_iphone/device_tracker
|
jen_iphone_bt_entry: monitor/entry/jen_iphone/device_tracker
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Automations for Presence Detection
|
# 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
|
||||||
|
binary_sensor:
|
||||||
|
|
||||||
|
# Home / Not-Home Sensors
|
||||||
|
- platform: template
|
||||||
|
sensors:
|
||||||
|
jp_presence:
|
||||||
|
friendly_name: J.P.
|
||||||
|
device_class: presence
|
||||||
|
value_template: "{{ is_state('person.jpk', 'home') }}"
|
||||||
|
|
||||||
|
jen_presence:
|
||||||
|
friendly_name: Jen
|
||||||
|
device_class: presence
|
||||||
|
value_template: "{{ is_state('person.jen', 'home') }}"
|
||||||
|
|
||||||
|
house_presence:
|
||||||
|
friendly_name: House
|
||||||
|
device_class: presence
|
||||||
|
value_template: >-
|
||||||
|
{{ is_state('person.jpk', 'home')
|
||||||
|
or is_state('person.jen', 'home') }}
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
|
||||||
|
# Extended Presence Status
|
||||||
|
- platform: template
|
||||||
|
sensors:
|
||||||
|
jp_presence_status:
|
||||||
|
value_template: '{{ states.input_select.jp_presence_state.state }}'
|
||||||
|
friendly_name_template: 'J.P. Presence Status'
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
sensors:
|
||||||
|
jen_presence_status:
|
||||||
|
value_template: '{{ states.input_select.jen_presence_state.state }}'
|
||||||
|
friendly_name_template: 'Jen Presence Status'
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
sensors:
|
||||||
|
house_presence_status:
|
||||||
|
value_template: '{{ states.input_select.house_presence_state.state }}'
|
||||||
|
friendly_name_template: 'House Presence Status'
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Automations for Presence Detection
|
||||||
|
automation:
|
||||||
|
|
||||||
|
# Run Bluetooth Arrival Scan at Home Assistant startup
|
||||||
|
- alias: Startup Arrival Scan
|
||||||
|
trigger:
|
||||||
|
- platform: homeassistant
|
||||||
|
event: start
|
||||||
|
mode: queued
|
||||||
|
action:
|
||||||
|
- service: mqtt.publish
|
||||||
|
data:
|
||||||
|
topic: monitor/scan/arrive
|
||||||
|
payload: scan
|
||||||
|
|
||||||
|
# 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'
|
||||||
|
|||||||
Reference in New Issue
Block a user