#-------------------------------------------
#  Realtime Debugging Related Packages
# @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
#-------------------------------------------
# homeassistant:
#   customize_glob:
#     "sensor.carlo_6*":
#
#     "sensor.staceys_iphone_*":

notify:
  - platform: ios
  - name: ios_family
    platform: group
    services:
      - service: ios_staceys_iphone
      - service: ios_carlo_6s
  - name: ios_parents
    platform: group
    services:
      - service: ios_staceys_iphone
      - service: ios_carlo_6s

group:
  Phones:
    entities:
      - sensor.carlo_6s_battery_level
      - sensor.carlo_6s_battery_state
      - sensor.staceys_iphone_battery_level
      - sensor.staceys_iphone_battery_state

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: Tablet Already taken
    trigger:
      platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: TABLET_TAKEN
    action:
      - service: notify.ios_carlo_6s
        data:
          message: "Great job!"
      - service: input_boolean.turn_on
        entity_id: input_boolean.medicine

  - alias: Remind Me Later
    trigger:
      platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: NOT_HOME
    action:
      - service: notify.ios_carlo_6s
        data:
          message: "Ok. I will remind you when you get home."
      - wait_template: >-
          {{ states.device_tracker.carlo.state == 'home' }}
      - service: notify.ios_carlo_6s
        data:
          message: "Now that your home, please take your medicine!"

  - alias: Medicine Reminder
    initial_state: true
    trigger:
      - platform: time
        minutes: '45'
        seconds: '00'
      - platform: time
        at: '21:30:00'
      - platform: state
        entity_id: device_tracker.carlo
        to: 'home'

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

    action:
      - service: notify.ios_carlo_6s
        data:
          title: "Medicine Alert!"
          message: "Please take your Medicine!"
          data:
            push:
              category: "tablet"
            action_data:
              entity_id: light.test
              my_custom_data: foo_bar

## Reminders to take my Medicine! - End.
