push:
  sound:
    name: default
    critical: 1
    volume: 1
actions:
  - action: StartRoomba
    title: "Yes"
  - action: "No"
    title: "No"
alias: Roomba when I am not home
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.residents_presence
    to: "off"
    from: "on"
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: state
    state: "off"
    entity_id: binary_sensor.residents_presence
  - condition: template
    value_template: |-
      {% set nw = now() %}
          {% set last = state_attr('automation.roomba_notification_when_out', 'last_triggered') %}
          {{ 00 <= nw.hour < 24 and
             (last is none or (nw - last).total_seconds() > 60 * 6) }}
    enabled: true
  - condition: state
    entity_id: vacuum.roomba
    state: docked
action:
  - service: notify.mobile_app_sm_a546b
    data:
      title: Start Roomba?
      message: ""
      data:
        push:
          sound:
            name: default
            critical: 1
            volume: 1
        actions:
          - action: StartRoomba
            title: "Yes"
          - action: "No"
            title: "No"
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: StartRoomba
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "No"
    continue_on_timeout: false
    timeout: "1:00"
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == \"StartRoomba\" }}"
        sequence:
          - device_id: da5fe7ff38406de9824f354ec319c130
            domain: vacuum
            entity_id: 89733010534ff859cfcedd920f9b6b35
            type: clean
mode: single