Page 1 of 1

LUA script: Turn Plug ON and play alarm sound with OmxPlayer

Posted: Monday 04 May 2020 15:19
by gemminiss
Hello all!

I want to make a LUA time script that turns-On a Zwave smartplug for 20secons, and plays one alarm sound twice

But it does not work as expected.

If I leave the smartplug = 'On' and exceute the scritp, it plays well the sound twice every minute
Only leaving the (commandArray['Powerplug'] = "On FOR 20 SECONDS', it works well, plug ON 20secons every minute

And If I put all together, the plug turns ON (but more than 20 seconds) but it does not play any sound. However I can see in the log, that the output of the .mp3 (bitrate, etc) has been printed.

for information: I use the assert+read+close, to be sure the execution of the io.popen is finished before playing the second sound.

Does anyone knows whats happening? another way around?

Code: Select all

commandArray = {}

commandArray['Powerplug'] = "On FOR 20 SECONDS"

local file = assert(io.popen('omxplayer --vol -1500 /home/pi/MyHDD/AlarmSounds/GarageOpen.mp3'))
local output = file:read('*all')
file:close()
print(output) 
  
local file2 = assert(io.popen('omxplayer --vol -1500 /home/pi/MyHDD/AlarmSounds/GarageOpen.mp3'))
local output2 = file2:read('*all')
file2:close()
print(output2) 

return commandArray
Thanks for your support!

Re: LUA script: Turn Plug ON and play alarm sound with OmxPlayer

Posted: Friday 03 July 2020 14:37
by bewo
Hi gemminiss,

if you run your posted script, the plug isn't on and has no power in the moment you start the alarm sound!

The commandArray-Command is executed when you reach the "return". A possible way is to power on the plug via curl and the Json-API before you start the sound. ;)