Actionable notification with two options

Hi, I’m trying to setup an automation to put my pc to sleep when there is no motion in the room but I’m stuck. I get the notification with the two options but when I pick one nothing happens and the trace shows that nothing was selected.

alias: Light Off Power Saver - Study
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.ultrasync_zone8state
    for:
      hours: 0
      minutes: 0
      seconds: 0
    from: Ready
    to: Not Ready
condition:
  - condition: state
    state: "on"
    entity_id: light.study_light
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.study_light
  - service: notify.mobile_app_adil_s_phone
    data:
      message: PC goin to sleep
      title: PC SLEEP
      data:
        notification_icon: mdi:sleep
        ttl: 0
        priority: high
        actions:
          - action: action_dontsleep
            title: Dont Sleep
            icon: mdi:sleep-off
          - action: action_gotosleep
            title: Sleep
            icon: mdi:sleep
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: action_dontsleep
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: action_gotosleep
    continue_on_timeout: false
    timeout:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == action_dontsleep }}"
        sequence:
          - service: automation.reload
            data: {}
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == action_gotosleep }}"
        sequence:
          - service: button.press
            data: {}
            target:
              entity_id: button.adils_pc_sleep
mode: restart

You need quotes around the action values in your templates since they are just strings, not variables like in the example in the companion app docs:

...
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == 'action_dontsleep' }}"
        sequence:
          - service: automation.reload
            data: {}
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == 'action_gotosleep' }}"
        sequence:
          - service: button.press
            data: {}
            target:
              entity_id: button.adils_pc_sleep
2 Likes

Thank you, spent hours trying to figure this out. Can’t believe it was that simple…