I’m trying to use the Choose function in my script but it says I haven’t set any trigger IDs even tho I have.
alias: Garage Mode Engage
sequence:
- type: turn_on
device_id: e61e2aa677b8246a1c4efe9e3400eb5f
entity_id: switch.garage
domain: switch
- type: turn_on
device_id: be501196d9d5cd39c898657b4cc2a44f
entity_id: light.bench_one
domain: light
- type: turn_on
device_id: 9e019bfab5bc0d6d8e9f3ee4901c24ab
entity_id: switch.bench_two
domain: switch
- type: turn_on
device_id: d4a1a899f191b03faf4968691b359140
entity_id: switch.plug01
domain: switch
- service: media_player.volume_set
continue_on_error: true
data:
volume_level: 0.6
target:
entity_id: media_player.deskdot
- service: media_player.play_media
continue_on_error: true
target:
entity_id: media_player.deskdot
data:
media_content_id: amzn_sfx_scifi_sheilds_up_01
media_content_type: sound
metadata: {}
- service: notify.alexa_media
continue_on_error: true
data_template:
message: Garage Mode Activated
data:
type: tts
target: media_player.deskdot
- service: script.activate_alexa_actionable_notification
data_template:
text: Should I open Spotify?
event_id: actionable_notification_deskdot_script1
alexa_device: media_player.deskdot
- wait_for_trigger:
- platform: event
event_type: alexa_actionable_notification
event_data:
event_id: actionable_notification_deskdot_script1
event_response_type: ResponseYes
id: '0001'
- platform: event
event_type: alexa_actionable_notification
event_data:
event_id: actionable_notification_deskdot_script1
event_response_type: ResponseNo
id: '0002'
timeout: '10'
- choose:
- conditions:
- condition: trigger
id: '0001'
sequence:
- service: shell_command.alexacontrol
data:
command: textcommand
device: DeskDot
message: open spotify
- conditions:
- condition: trigger
id: '0002'
sequence:
- stop: End of Script
default: []
123
(Taras)
May 30, 2022, 3:18am
2
You set them in the triggers for a wait_for_trigger
. That’s not the same as for an automation’s trigger
and that’s why it says you haven’t set any trigger IDs.
In addition, the resulting object from a triggered wait_for_trigger
would be a wait.trigger
and not a traditional trigger
object.
Try replacing the Trigger Conditions in your choose
statement with Template Conditions like this:
- choose:
- conditions: "{{ wait.trigger.id == '0001' }}"
sequence:
- service: shell_command.alexacontrol
data:
command: textcommand
device: DeskDot
message: open spotify
- conditions: "{{ wait.trigger.id == '0002' }}"
sequence:
- stop: End of Script
default: []
4 Likes
You are a gentleman and a scholar. That was the trick thank you buddy. I see the wait.trigger data now in the docs.
1 Like
Just wanted to update this with the way I managed to do it with mobile app notifications:
Process:
trigger script via an automation
Script runs and sends notification to my partners iPhone with 3 options for her to choose from (Yes please, No thanks, Tea Please)
When she responds by pushing a button in her notification, the response then tiggers the matching ‘event’ and assigned a trigger ID (I keep these all matching as it makes easier for me follow - i.e. YES_COFFEE is the action in the notification and trigger ID for the template)
The choose function then chooses the action to run based on the button that was pressed in the notification. the condition of the choose option is a value template that matches the trigger ID (YES_COFFEE)
alias: "Mobile App Notifications and Actions - Template "
sequence:
- action: notify.mobile_app_diana_s_iphone
data:
data:
actions:
- action: YES_COFFEE
title: Yes please
- action: NO_COFFEE
title: No thanks
- action: YES_TEA
title: Tea please
message: Do you want one?
title: Tom's making a coffee
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: YES_COFFEE
id: YES_COFFEE
context:
user_id:
- b220736f1daa405bbaf1759ec3eb58cc
- platform: event
event_type: mobile_app_notification_action
event_data:
action: NO_COFFEE
id: NO_COFFEE
context:
user_id:
- b220736f1daa405bbaf1759ec3eb58cc
- platform: event
event_type: mobile_app_notification_action
event_data:
action: YES_TEA
id: YES_TEA
context:
user_id:
- b220736f1daa405bbaf1759ec3eb58cc
timeout:
hours: 0
minutes: 15
seconds: 0
milliseconds: 0
continue_on_timeout: false
- choose:
- conditions:
- condition: template
value_template: "{{ wait.trigger.id == 'YES_COFFEE' }}"
sequence:
- action: notify.mobile_app_sm_s918b
metadata: {}
data:
title: Diana Replied
message: Coffee please
- conditions:
- condition: template
value_template: "{{ wait.trigger.id == 'NO_COFFEE' }}"
sequence:
- action: notify.mobile_app_sm_s918b
metadata: {}
data:
title: Diana Replied
message: "No thank you "
- conditions:
- condition: template
value_template: "{{ wait.trigger.id == 'YES_TEA' }}"
sequence:
- action: notify.mobile_app_sm_s918b
metadata: {}
data:
message: Tea please
title: "Diana Replied "
description: ""