Wait for Trigger & Choose with Value Template…

Hi, been playing with the new Wait for Trigger and was wondering if I’ve missed something when combining it with choose:

Working set up:

  • Automation calling IOS actionable notification
  • Second automation with a trigger of the IOS response, choose in the actions based on the actionName in the response

To be set up:

  • Single automation calling IOS action notification
  • 'Wait for trigger ’ for the response back from IOS actionable notification
  • Choose action based on the trigger data from the waited for trigger

The configuration I’m trying to get running (possible responses from the actionable notification are TESTA and TESTB:

- id: '1596277325558'
  alias: xTest
  description: Test only.....
  trigger:
  - platform: device
    type: turned_off
    device_id: d20608626cd04a00844b9b01ddf05ca2
    entity_id: light.office_play
    domain: light
  condition: []
  action:
  - service: notify.mobile_app_mike_wood_iphonex
    data:
      message: This is a test
      data:
        push:
          category: TEST
  - wait_for_trigger:
    - platform: event
      event_type: ios.notification_action_fired
      event_data: {}
    timeout: 00:01:00
    continue_on_timeout: true
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ trigger.event.data.actionName == "TESTA" }}'
      sequence:
      - type: toggle
        device_id: d20608626cd04a00844b9b01ddf05ca2
        entity_id: light.office_play
        domain: light
    - conditions:
      - condition: template
        value_template: '{{ trigger.event.data.actionName == "TESTB" }}'
      sequence:
      - type: toggle
        device_id: 1921d1bc21774f9894700ce41360cd05
        entity_id: light.office_light
        domain: light
    default: []
  mode: restart

The working set up I have has one automation triggering the IOS actionable notification, and a second with the trigger being the IOS event, and the choose conditions as outlined in this one using the same value template format.

Probably error in chair, just wondered if this was possible and I’ve made a mistake or if the value_template in the choice is looking to the original trigger and not and the waited for one?

1 Like

I assume it takes the original trigger. Juat try it by sending the trigger data to your mobile and see if it is the trigger of the wait_for trigger or of the initial trigger.

Yes, (whilst learning more about trigger.xxx :slight_smile:) I believe that’s a correct conclusion - thanks for the prod at trying that!

I feel that this is a valid use case unless I’ve missed something obvious in the principles here?

I believe you can get the state object for the wait_for_trigger from wait.trigger

You may be able to extract what you need from there.

1 Like

Yes, sounds like a valid usecase to me as well. I don’t have time to test currently but try the suggestion from Brian.

1 Like

Boom!! Perfect thanks :grinning:

It was in the documentation but I’d failed to link the two things together so appreciate the help:

Here’s the working example

- id: '1596277325558'
  alias: xTest
  description: Test only.....
  trigger:
    - platform: device
      type: turned_off
      device_id: 1921d1bc21774f9894700ce41360cd05
      entity_id: light.office_light
      domain: light
  condition: []
  action:
    - service: notify.mobile_app_mike_wood_iphone
      data:
        message: This is a test
        data:
          actions:
            - action: TESTA
              title: Action A
            - action: TESTB
              title: Action B
    - wait_for_trigger:
        - platform: event
          event_type: ios.notification_action_fired
          event_data: {}
    - choose:
        - conditions:
            - condition: template
              value_template: '{{ wait.trigger.event.data.actionName == "TESTA" }}'
          sequence:
            - service: notify.mobile_app_mike_wood_iphone
              data:
                message: This is option A
        - conditions:
            - condition: template
              value_template: '{{ wait.trigger.event.data.actionName == "TESTB" }}'
          sequence:
            - service: notify.mobile_app_mike_wood_iphone
              data:
                message: This is option B
      default: []
  mode: restart

EDIT: Updated slightly to reflect the changes in IOS notification configuration

8 Likes