LUA -random text

Does someone have an example of LUA for sending TTS to Sonos or DLNA speaker?
I am using PLEG.
For example: when I open a door (with door sensor), I want the speaker to say “Hi”, next time someone enters the door, the speaker should say “something else”, etc.

Are you sure you need LUA ?
The device probably has a say action you can access from the advanced actions editor.

Sent from my SAMSUNG-SM-G935A using Tapatalk

Sorry, I meant: I want to have different/random TTS greating every time :slight_smile:

That’s a fun question actually. How many different greetings are you thinking?
I would use a random number generator and create a “text” variable which would be different for each output of the number generator.
For example if you have 10 of them"

local rand = math.random(10)
local text = ""
if rand = 1 then
text = "blah blah 1"
else if rand = 2 then
text = "blah blah 2"
... until 10

then run the TTS command to speak out the “text” string

Check out this post in the “Dynamic TTS” thread,12408.msg159478.html#msg159478

[quote=“parkerc, post:5, topic:196463”]Check out this post in the “Dynamic TTS” thread,12408.msg159478.html#msg159478[/quote]

Yes indeed. I have to say that the programming implementation there for selecting different texts is somewhat cleaner than that described here.