Author Topic: Help with a script for timed announcements (bedtime countdown )  (Read 183 times)

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2364
  • Karma: +33/-45
  • Life Moves Pretty Fast....
    • Node Central
Hi All

I'm looking for some advice..

Is this the best way to script a delayed set of (AWS Polly) TTS announcements?
The Polly function is included in the Lua start up, and the print entries are used for Luatest.

Currently after the first Polly TTS  request plays, the remaining ones play out of order and do not seem to honour their assigned delays (in seconds) ?

Code: [Select]
local vol = 30

Print ('Commencing kids bedtime countdown routine... This is your 10 minute bedtime countdown notification')
Polly ('Commencing kids bedtime countdown routine... This is your 10 minute bedtime countdown notification', vol )
 
luup.call_delay( 'call_polly', 300)  -- 5 minute, 300 seconds delay
   
function call_polly()
  Polly('kids. There are now 5 minutes before bedtime. So make those 300 seconds count!', vol)
  Print('kids. There are now 5 minutes before bedtime. So make those 300 seconds count!')
  end     

luup.call_delay( 'call_polly1', 120)  -- 2 minute, 120 seconds delay

function call_polly1()
   Polly('kids. There are now 3 minutes before bedtime. So not long left to go!', vol)
   Print('kids. There are now 3 minutes before bedtime. So not long left to go!')
   end

luup.call_delay( 'call_polly2', 120)  -- 2 minute, 120 seconds delay

function call_polly2()
   Polly('kids. There is only 1 minute to go now. So start to get ready!', vol)
   Print('kids. There is only 1 minute to go now. So start to get ready!!')
   end

luup.call_delay( 'call_polly3', 120)  -- 2 minute, 120 seconds delay

function call_polly3()
   Polly('kids. Thats it, it time for bed, the last one upstairs is a rotten egg!', vol)
   Print('kids. Thats it, it time for bed, the last one upstairs is a rotten egg!')
   end
« Last Edit: August 02, 2017, 03:04:38 pm by parkerc »

Offline akbooer

  • Master Member
  • *******
  • Posts: 5234
  • Karma: +226/-67
  • "Less is more"
Re: Help with a script for timed announcements (bedtime countdown )
« Reply #1 on: August 02, 2017, 01:59:36 pm »
All the luup.call_delay() functions are executed immediately after one-another.  So there are two approaches:
  • adjust the delays to be time from NOW, or,
  • move the luup.call_delay() calls to each of the delayed functions.
Hope that's clear.  Ask again if not.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P.
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2364
  • Karma: +33/-45
  • Life Moves Pretty Fast....
    • Node Central
Re: Help with a script for timed announcements (bedtime countdown )
« Reply #2 on: August 02, 2017, 03:02:41 pm »
Thanks @akbooer :)

So for option 1) each delay would therefore be this?

Code: [Select]
luup.call_delay( 'call_polly', 300)  -- Schedules polly notification 5 minutes after the initial notification
luup.call_delay( 'call_polly', 420)  -- Schedules Polly1 notification 7 minutes after the initial notification
luup.call_delay( 'call_polly', 540)  -- Schedules polly2 notification 9 minutes after the initial notification
luup.call_delay( 'call_polly', 600)  -- Schedules the final notification - 10 minutes after the initial notification

For Option 2) - Ok, so I would move the luup.call_delay part into each of the 4 functions (polly 1' Polly 2 etc.) and then call all them at once at the end. For that to work! I assume I still need to set the intervals based on when the script is run (like above)? 

« Last Edit: August 02, 2017, 03:05:29 pm by parkerc »

Offline akbooer

  • Master Member
  • *******
  • Posts: 5234
  • Karma: +226/-67
  • "Less is more"
Re: Help with a script for timed announcements (bedtime countdown )
« Reply #3 on: August 02, 2017, 03:38:45 pm »
  • yes, that's right (except the calls need to be to polly1, polly2, etc...)
  • no, the delays are from when the calls are made so it will be 120, 120, and 60. (polly 1 calls polly2, etc.)

You can make this much neater by passing a parameter to a single function, rather than duplicating the functions, but that's another level of refinement.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P.
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.