From 0a4b965613601045d83c21cee8956152f1592f2f Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 29 Jun 2018 15:15:14 -0400 Subject: [PATCH] Notify me when someone else enters or leaves the house --- packages/notifications.yaml | 4 +++ packages/occupancy.yaml | 62 +++++++++++++++++++++++++++++++------ secrets.example.yaml | 1 + 3 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 packages/notifications.yaml diff --git a/packages/notifications.yaml b/packages/notifications.yaml new file mode 100644 index 0000000..2a99a1c --- /dev/null +++ b/packages/notifications.yaml @@ -0,0 +1,4 @@ +notify: + - name: correl + platform: pushbullet + api_key: !secret pushbullet_api_key diff --git a/packages/occupancy.yaml b/packages/occupancy.yaml index fa55c8e..b02f0e4 100644 --- a/packages/occupancy.yaml +++ b/packages/occupancy.yaml @@ -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 diff --git a/secrets.example.yaml b/secrets.example.yaml index ec7c25d..51cae95 100644 --- a/secrets.example.yaml +++ b/secrets.example.yaml @@ -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