Another post targeted at beginning users (like me)…
Wouldn’t it be great to have a rule to make Alexa to give us a random thought for the day out of our own list of quotations?
If you already have the capability to launch a daily briefing using OH, read on. Otherwise, you first should start with the Amazon Echo Control Binding documentation.
First we need to install a debian linux application. On the command line of your openhab/openhabian installation, enter:
sudo apt install randomize-lines
Go to the /etc/openhab2/scripts folder and create a sample file called quotes.txt
Add several lines of random text like:
This is the first line
This is the second line
This is the third line
This is the fourth line
You can test the randomize program by entering this on the command line:
rl -c 1 /etc/openhab2/scripts/quotes.txt
Create another file in the scripts folder called randomline.sh and enter the following:
#!/bin/bash
rl -c 1 /etc/openhab2/scripts/quotes.txt
Save, and change the file permissions so randomline.sh is an executable file:
sudo chmod +x /etc/openhab2/randomline.sh
Your Echo device should have a speak item for it. Writing a rule to have Alexa speak a random line will require you to identify the speak item for your device. For illustration, we will assume it is called EchoPlus_Speak and we will further assume the quote will be spoken when the kitchen computer (computer_kitchen) is turned on:
rule "Alexa Quote"
when
Item computer_kitchen changed from OFF to ON
then
var Random_Line = executeCommandLine("/etc/openhab2/scripts/randomline.sh", 1000)
EchoPlus_Speak.sendCommand("thought for the day...." + Random_Line)
end
That’s it!
Note that Alexa seems to speak without interruption, even when there are commas and periods for punctuation. The trick is to add periods, because the Alexa routine pauses for a fraction of a second for each period found. So when you populate the quotes.txt file, instead of:
Seek first to understand, then to be understood
write the quote out as:
Seek first to understand.. then to be understood