Debugging YAML for event condition

I’m trying to use actionable notifications on Android. I’ve created an automation with a wait for trigger that waits for me tapping the notification button. That works, and you can see how the action was detected and so the automation should continue.

But it doesn’t. The next action, where the conditions are written in YAML and not using the UI (I got this from some blog post) doesn’t work and I can’t see why. I cannot see a syntax error, and the condition seems well written to me.

Can someone help me debug this? Many thanks!

Replying myself as a kind user helped on Discord to figure this out.

Here’s how the entire automation looks like. The final action which was giving the problem was changed in several ways.

For once it was adding quotes to the variable being used, but we also changed the syntax so it was picked up by the UI as it’s much easier for me to use that way.

alias: Good night
description: ""
trigger:
  - platform: tag
    tag_id: 8add40bd-368b-4b23-ae63-bdb990269ab5
condition: []
action:
  - service: notify.mobile_app_xiaomi_12_lite_ax
    data:
      message: "What do you want to do? "
      data:
        actions:
          - action: bed_light
            title: Bed light
          - action: living_lights
            title: Living lights
  - alias: Wait for a response
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: bed_light
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: living_lights
    continue_on_timeout: false
    timeout:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
  - alias: Perform the action
    choose:
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == \"bed_light\" }}"
        sequence:
          - service: light.toggle
            data: {}
            target:
              entity_id: light.bed_led
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == \"living_lights\" }}"
        sequence:
          - service: light.toggle
            data: {}
            target:
              entity_id: light.living_room_lights
mode: single

If you are interested, you can eliminate the entire choose statement if you tweak the values in the Event Triggers.

  • bed_led instead of bed_light
  • living_room_lights instead of living_lights
alias: Good night
description: ""
trigger:
  - platform: tag
    tag_id: 8add40bd-368b-4b23-ae63-bdb990269ab5
condition: []
action:
  - service: notify.mobile_app_xiaomi_12_lite_ax
    data:
      message: "What do you want to do? "
      data:
        actions:
          - action: bed_led
            title: Bed light
          - action: living_room_lights
            title: Living lights
  - alias: Wait for a response
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: bed_led
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: living_room_lights
    continue_on_timeout: false
    timeout:
      seconds: 20
  - alias: Perform the action
    service: light.toggle
    target:
      entity_id: 'light.{{ wait.trigger.event.data.action }}'
mode: single