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

Moderator: leecollings

Post Reply
gemminiss
Posts: 3
Joined: Tuesday 06 March 2018 16:33
Target OS: Windows
Domoticz version:
Contact:

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

Post 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!
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

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

Post 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. ;)
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest