I am struggling a bit translating this into my HASS deployment. A little more background. I’m running hassio, raspberry pi 3+, and hass 0.94.4. I’m unsure of the other versions and differences in syntax or features.
Here is what I programmed and the system accepted it at a proper syntax.
here are the errors that I’m seeing.
extra keys not allowed @ data[‘entity_ID’]
2:04 PM core.py (ERROR)
Error executing script script.1561397164681. Invalid data for call_service at pos 1: extra keys not allowed @ data[‘entity_ID’]
I don’t know if the Automation Editor supports the use of templates. I don’t use that (and most people, to my knowledge, don’t.) I would recommend editing the YAML file directly.
Okay following your advise I programmed in YAML. Initially, I had a very difficult time getting it to run correctly. After tinkering around I realized I was actually generating some randomness (matching what I’m trying to accomplish) in the error file and narrowed down what I needed to adjust.
This is the final outcome that works for me. Randomizing a Service_Call when someone rings the Doorbell. Now I can alternate between spooky scenes when Halloween rolls around…
FYI, I ended up writing this into a new Script and not an Automation.
Hi, I have limited experience writing such templates, so not the most elegant solution:
I think this is what you wanted to do:
alias: Random Select Script
sequence:
- service: "{{ ['script.say_get_outta_here', 'script.say_what_you_do_you_do', 'script.say_sorry_this_room_is_occupied'] | random }}"
data: {}
mode: single
You can also define a variable and use choose to choose the script:
alias: Define Variable and Choose Random Message to Say
sequence:
- alias: Set a templated variable
variables:
selection_variable: "{{ range(0,3) | random | int }}"
- choose:
- conditions:
- condition: template
value_template: "{{ selection_variable == 0 }}"
sequence:
- service: notify.alexa_media
data:
target: media_player.living_room_echo
message: Get outta here!
data:
type: tts
- conditions:
- condition: template
value_template: "{{ selection_variable == 1 }}"
sequence:
- service: notify.alexa_media
data:
target: media_player.living_room_echo
message: Sorry this room is occupied!
data:
type: tts
- conditions:
- condition: template
value_template: "{{ selection_variable == 2 }}"
sequence:
- service: notify.alexa_media
data:
target: media_player.living_room_echo
message: What you do you do?
data:
type: tts
- service: notify.alexa_media
data:
target: media_player.living_room_echo
message: "{{ ['chicken', 'pot roast', 'cotton candy'] | random }}"
data:
type: tts
mode: single
You can also choose directly:
alias: Say Random Message
sequence:
- service: notify.alexa_media
data:
target: media_player.living_room_echo
message: >-
{{ ['Get outta here!', 'Sorry, this room is occupied', 'What you do you
do?'] | random }}
data:
type: tts
mode: single