From 7413b900f489aea78e9cc82af04c5eb9c1123379 Mon Sep 17 00:00:00 2001 From: Scott Reston Date: Sat, 22 Apr 2017 08:08:16 -0400 Subject: [PATCH] Added example to work around broken random filter (#2465) Random filter in Jinja isn't currently working with lists. https://github.com/home-assistant/home-assistant/issues/5678 --- source/_components/alexa.markdown | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/_components/alexa.markdown b/source/_components/alexa.markdown index c0526d856a8..fd96399a702 100644 --- a/source/_components/alexa.markdown +++ b/source/_components/alexa.markdown @@ -306,6 +306,34 @@ text: !include alexa_confirm.yaml Alexa will now respond with a random phrase each time. You can use the include for as many different intents as you like so you only need to create the list once. +

+As of April 2017, the random filter has been somewhat broken. You'll get a random response the first time this runs, but subsequent commands will reply with the same randomly-chosen phrase. On reboot, Home Assistant will pick a new random choice, but you're stuck with that choice till you reboot. To get around that, use the following code in alexa_confirm.yaml: +

+ +```text +{% raw %} > + {% set responses = [ + "OK", + "Sure", + "If you insist", + "Done", + "No worries", + "I can do that", + "Leave it to me", + "Consider it done", + "As you wish", + "By your command", + "Affirmative", + "Yes oh revered one", + "I will", + "As you decree, so shall it be", + "No Problem" + ] %} + {% set rindex = (range(0, (responses | length - 1) )|random) -%} + {{responses[rindex]}} + {% endraw %} +``` + ## {% linkable_title Flash Briefing Skills %}