jcallaghan / home-assistant-config

My Home Assistant configuration & documentation.
https://www.jcallaghan.com/
MIT License
173 stars 8 forks source link

Zone triggered reminders πŸ—ΊπŸ“Œβœ… #215

Closed jcallaghan closed 3 years ago

jcallaghan commented 3 years ago

Reminders based on zone. Perhaps use helpers to determine if a reminder is needed or not. Even an input_text for each zone and when it contains text then send this as a notification when entering that zone.

Use-cases

https://twitter.com/michaeldvinci/status/1281302094994079744 Michael Vinci (@michaeldvinci) Honestly, Zone based notification automations have saved me more times than I can count. @home_assistant #hassio #homeassistant

image

jcallaghan commented 3 years ago

It’s working!!!

I've got a few examples of this working now. Using the helpers is great! I'm using a single automation with a with a template to determine the value it should show when the notification is sent.

image

action:

  - service: notify.mobile_app_james_iphone
    data_template:
      title: "{{ trigger.zone.attributes.friendly_name }} zone reminder"
      message: >-
        {% if trigger.zone.attributes.friendly_name == "Community Garden" %}
          The community garden gate code is {{ states('input_text.community_garden_gate_code') }}. Happy gardening.
        {% elif trigger.zone.attributes.friendly_name == "Gym" %}
          The gym code is {{ states('input_text.community_garden_gate_code') }}. Enjoy your workout!
        {% endif %}

image

jcallaghan commented 3 years ago

Explore if it is possible to reference multiple zones in a single trigger or have a trigger when entering any zone without having to specify them all one by one.

This currently works.

trigger:

  - platform: zone
    entity_id:
      - person.james
    zone: zone.community_garden
    event: enter

  - platform: zone
    entity_id:
      - person.james
    zone: zone.gym
    event: enter

Something like this would be great.

trigger:

  - platform: zone
    entity_id:
      - person.james
    zone: 
        - zone.community_garden
        - zone.gym
    event: enter

Or like this when entering any zone and then leverage {{ trigger.zone.attributes.friendly_name }} in the template.

trigger:

  - platform: zone
    entity_id:
      - person.james
    event: enter
jcallaghan commented 3 years ago

Ad-hoc reminders

One further idea I had for this was to use an input_select which would list all my zones and an input_text which would be used as a placeholder for a message. Then if a zone was selected from the list and a message was added it would be sent as a notification when entering the selected zone. This would allow for ad-hoc messages to be sent rather than having to hardcode this in the automation.

jcallaghan commented 3 years ago

Michael Vinci (@michaeldvinci) also suggested this using actionable alerts to mask the password from the notification screen.

https://twitter.com/michaeldvinci/status/1281564640812642306 Also, I was actually thinking of making them 'Actionable' Notifications so the code isn't displayed directly on the screen, and it takes user input to see it. Might be a better implementation in the eyes of security-forward folks.

michaeldvinci commented 3 years ago

I figured actionable notifications would require user input, thus masking the code until some action was taken. This way the plaintext view of the password is at least shielded partially until a user-driven event or action was taken, such as a long press on the notification, etc, etc

jcallaghan commented 3 years ago

@michaeldvinci it is a great idea. Personally, the stuff I will remind myself is not anything I would be worried about anyone else seeing however for those using this for something more sensitive this would work a treat.

Here we go.

ios:
  push:
    categories: 
      - name: Zone Reminder Yes No Prompt
        identifier: 'zone_reminder_yes_no_prompt'
        actions:

          - identifier: 'zone_reminder_yes_no_prompt_yes'
            title: 'Yes'
            authenticationRequired: false
            destructive: true
            behavior: 'default'
            activationMode: 'background'

          - identifier: 'zone_reminder_yes_no_prompt_no'
            title: 'No'
            authenticationRequired: false
            destructive: false
            activationMode: 'background'

Reboot and then refresh notifications in the app (app configuration > notifications > import push configuration from server).

We will need an input_text helper to store a message to reveal.

zone_reminder:
  name: "Zone Reminder"
  icon: mdi:note
  max: 255
  mode: password

Then in the first automation that triggers when entering a zone.

alias: System - Zone Reminders

trigger:

  - platform: zone
    entity_id:
      - person.james
    zone: zone.community_garden
    event: enter

  - platform: zone
    entity_id:
      - person.james
    zone: zone.gym
    event: enter

action:

    # As we won't be able to leverage trigger.zone.attributes.friendly_name etc in the second 
    # notification we store the message we want to reveal in a text field.
  - service: input_text.set_value
    data_template:
      entity_id: input_text.zone_reminder
      value: >-
        {% if trigger.zone.attributes.friendly_name == "Community Garden" %}
          The community garden gate code is {{ states('input_text.community_garden_gate_code') }}.
        {% elif trigger.zone.attributes.friendly_name == "Gym" %}
          The gym code is {{ states('input_text.community_garden_gate_code') }}. Enjoy your workout!
        {% endif %}

    # We send the first notification with a different message depending on the zone name.
    # In this message we don't reveal the reminder so use *** to indicate there is a reminder.
    # The push category we defined above in the ios config is sent with this notification.
  - service: notify.mobile_app_james_iphone
    data_template:
      title: "{{ trigger.zone.attributes.friendly_name }} zone reminder"
      message: >-
        {% if trigger.zone.attributes.friendly_name == "Community Garden" %}
          The community garden gate code is ****. Would you like to reveal the reminder?
        {% elif trigger.zone.attributes.friendly_name == "Gym" %}
          The gym code is ****. Would you like to reveal the reminder?
        {% endif %}
      data:
        push:
          category: 'zone_reminder_yes_no_prompt'

Then in the second automation do the big reveal.

alias: System - Zone Reminder Reveal

trigger:

    # The actionName must be in capitals.
  - platform: event
    event_type: ios.notification_action_fired
    event_data:
      actionName: ZONE_REMINDER_YES_NO_PROMPT_YES

action:

    # We send a further notification with the text we stored in the reminder text field.
  - service: notify.mobile_app_james_iphone
    data:
      message: "{{ states('input_text.zone_reminder') }}"

    # As we are done with the text we stored we clear the text field.
  - service: input_text.set_value
    data:
      entity_id: input_text.zone_reminder
      value: ""
jcallaghan commented 3 years ago

Here is a video of the actionable alert revealing the reminder - https://twitter.com/jamescallaghan/status/1281586295320584192

Twitter
James Callaghan #Microsoft on Twitter
β€œ@michaeldvinci @anton3sco @home_assistant Because....welll....why not? πŸ₯° https://t.co/ILIxIAgtl2”