Notify me when someone else enters or leaves the house
This commit is contained in:
parent
1ca5c8d232
commit
0a4b965613
3 changed files with 58 additions and 9 deletions
4
packages/notifications.yaml
Normal file
4
packages/notifications.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
notify:
|
||||
- name: correl
|
||||
platform: pushbullet
|
||||
api_key: !secret pushbullet_api_key
|
|
@ -50,17 +50,46 @@ automation:
|
|||
- service: script.sonos_tts
|
||||
data_template:
|
||||
message: >-
|
||||
Welcome home,
|
||||
{{ states
|
||||
| selectattr("entity_id", "in",
|
||||
states.group.phones.attributes.entity_id)
|
||||
| selectattr('state', 'eq', 'home')
|
||||
| map(attribute='attributes.friendly_name')
|
||||
| join(' and ')}}!
|
||||
{% set occupants
|
||||
= states.sensor.occupants.state.split(', ')
|
||||
| select
|
||||
| reject('equalto', 'Somebody')
|
||||
| join(', ')
|
||||
%}
|
||||
Welcome home
|
||||
{{ occupants }}!
|
||||
trigger:
|
||||
- entity_id: binary_sensor.occupied
|
||||
platform: state
|
||||
to: 'on'
|
||||
to: 'on'
|
||||
- alias: Notify me when someone arrives at home
|
||||
action:
|
||||
- service: notify.correl
|
||||
data_template:
|
||||
title: Occupancy
|
||||
message: >-
|
||||
{% set occupants = states.sensor.occupants.state.split(', ')
|
||||
%}
|
||||
{% if occupants | length == 0 %}
|
||||
Nobody is home
|
||||
{% elif occupants | length == 1 %}
|
||||
{{ occupants[0] }} is home
|
||||
{% else %}
|
||||
{{ occupants[:-2].join(', ') }}
|
||||
{{ occupants[-2].join(' and ') }}
|
||||
are home
|
||||
{% endif %}
|
||||
trigger:
|
||||
- platform: state
|
||||
entity_id: sensor.occupants
|
||||
condition:
|
||||
- condition: template
|
||||
value_template: >-
|
||||
{% set from = trigger.from_state.state.split(', ') | select %}
|
||||
{% set to = trigger.to_state.state.split(', ') | select %}
|
||||
{{ from|reject('equalto', 'Correl') | sort
|
||||
!= to|reject('equalto', 'Correl') | sort
|
||||
}}
|
||||
|
||||
input_boolean:
|
||||
occupied:
|
||||
|
@ -84,7 +113,22 @@ binary_sensor:
|
|||
{{ is_state('group.all_lights', 'on')
|
||||
or is_state('media_player.den', 'playing')
|
||||
}}
|
||||
|
||||
sensor:
|
||||
- platform: template
|
||||
sensors:
|
||||
occupants:
|
||||
friendly_name: List of occupants
|
||||
value_template: >-
|
||||
{% if is_state('binary_sensor.occupied', 'on') %}
|
||||
{{ states
|
||||
| selectattr("entity_id", "in",
|
||||
states.group.phones.attributes.entity_id)
|
||||
| selectattr('state', 'eq', 'home')
|
||||
| map(attribute='attributes.friendly_name')
|
||||
| join(', ')
|
||||
| default('Somebody', true)
|
||||
}}
|
||||
{% endif %}
|
||||
group:
|
||||
Occupancy:
|
||||
view: yes
|
||||
|
|
|
@ -9,3 +9,4 @@ http_password: secret
|
|||
aws_access_key_id: secret
|
||||
aws_secret_access_key: secret
|
||||
darksky_api_key: secret
|
||||
pushbullet_api_key: secret
|
||||
|
|
Loading…
Reference in a new issue