Skip to content

Instantly share code, notes, and snippets.

@dmakovec
Created January 10, 2023 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmakovec/7dce99af1164f406d5d2a5a44c3be75c to your computer and use it in GitHub Desktop.
Save dmakovec/7dce99af1164f406d5d2a5a44c3be75c to your computer and use it in GitHub Desktop.
Example HA automation with action buttons
alias: "Pill reminder (interactive)"
description: ""
trigger:
  - platform: time_pattern
    minutes: /15
    alias: Every 15 mins
condition:
  - condition: state
    entity_id: input_boolean.not_had_pill_today
    state: "on"
action:
  - alias: Set up variables
    variables:
      action_yes: YES_PILL
      action_no: NO_PILL
  - alias: Ask question
    service: notify.mobile_app_pixel_7
    data:
      message: Had it today?
      title: Pill
      data:
        tag: pill
        actions:
          - action: "{{ action_yes }}"
            title: "Yes"
          - action: "{{ action_no }}"
            title: "No"
  - alias: Wait for response
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_yes }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_no }}"
    timeout:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - if:
      - condition: template
        value_template: "{{ wait.trigger.event.data.action == action_yes }}"
        alias: Answer "Yes" received
    then:
      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.not_had_pill_today
        data: {}
    else:
      - service: notify.mobile_app_pixel_7
        data:
          message: clear_notification
          data:
            tag: pill
    alias: Check the answer
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment