We have moved at community.getvera.com

Author Topic: LUA -random text  (Read 1361 times)

Offline paros

  • Full Member
  • ***
  • Posts: 205
  • Karma: +6/-1
LUA -random text
« on: June 10, 2017, 02:49:42 pm »
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.

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: LUA -random text
« Reply #1 on: June 10, 2017, 03:42:25 pm »
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


Offline paros

  • Full Member
  • ***
  • Posts: 205
  • Karma: +6/-1
Re: LUA -random text
« Reply #2 on: June 10, 2017, 04:21:26 pm »
Sorry, I meant: I want to have different/random TTS greating every time :)

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: LUA -random text
« Reply #3 on: June 11, 2017, 08:16:36 pm »
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"

Code: [Select]
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
end


then run the TTS command to speak out the "text" string
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: LUA -random text
« Reply #4 on: August 30, 2017, 02:03:27 pm »

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: LUA -random text
« Reply #5 on: August 30, 2017, 03:12:22 pm »
Check out this post in the "Dynamic TTS" thread

http://forum.micasaverde.com/index.php/topic,12408.msg159478.html#msg159478

Yes indeed.  I have to say that the programming implementation there for selecting different texts is somewhat cleaner than that described here.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.