#-------------------------------------------
# Realtime Debugging Related Packages
# @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# More information found here #780, #168
# https://github.com/CCOSTAN/Home-AssistantConfig/issues/780
# https://github.com/CCOSTAN/Home-AssistantConfig/issues/168
#-------------------------------------------

notify:
#  - platform: ios #Not Needed anymore - 10/04/2020
  - name: ios_family
    platform: group
    services:
      - service: mobile_app_stacey_iphone11
      - service: mobile_app_carlo_xsmax
  - name: ios_parents
    platform: group
    services:
      - service: mobile_app_stacey_iphone11
      - service: mobile_app_carlo_xsmax

mobile_app:

ios:
  push:
    categories:
      - name: Medicine
        identifier: 'tablet'
        actions:
          - identifier: 'TABLET_TAKEN'
            title: 'Tablet Taken'
            activationMode: 'background'
            authenticationRequired: no
            destructive: yes

          - identifier: 'NOT_HOME'
            title: 'I am not Home'
            activationMode: 'background'
            authenticationRequired: no
            destructive: no

## - Reminders to take my medicine
input_boolean:
  medicine:
    name: Medicine Reminder
    initial: off
    icon: mdi:tablet

automation:
  - alias: Medicine Reminder
    id: 78c47087-8242-470c-97d1-3dc5747ed576
    initial_state: true
    trigger:
      - platform: time_pattern
        minutes: '/45'
      - platform: time
        at: '21:30:00'
      - platform: state
        entity_id: person.carlo
        to: 'home'

    condition:
      - condition: time
        after: '21:30:00'
      - condition: state
        entity_id: person.carlo
        state: 'home'
      - condition: state
        entity_id: input_boolean.medicine
        state: 'off'

    action:
      - service: script.notify_engine
        data:
          title: 'Medicine Alert!'
          value1: 'Please take your Medicine!'
          ios_category: "tablet"
          who: "carlo"
          apns_id: 'Medicine'

  - alias: Remind Me Later
    id: 79b49c85-f832-47d7-b02d-bff099ef6fbc
    trigger:
      platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: NOT_HOME
    action:
      - service: script.notify_engine
        data:
          title: 'Medicine Reminder'
          value1: 'Ok. I will remind you when you get home.'
          who: 'carlo'
          apns_id: 'Medicine'
      - wait_template: >-
          {{ states.person.carlo.state == 'home' }}
      - service: script.notify_engine
        data:
          title: 'Medicine Reminder'
          value1: 'Now that your home, please take your medicine!'
          who: 'carlo'
          apns_id: 'Medicine'

  - alias: Tablet Already taken
    id: 1f295bb8-8925-4b22-8f75-9fe079b295a8
    trigger:
      platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: TABLET_TAKEN
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.medicine





## Reminders to take my Medicine! - End.