Page 1 of 2

Can door sensor trigger audio on Raspberry Pi

Posted: 02 Aug 2016 05:08
by highspeedz
Can I use the Z-Wave Smart Home software to trigger an audio sound on the pi itself. I am using razberry on the raspberry pi. Currently the door opening will trigger the doorbell, but I would like to have the pi itself make a sound. Can this be done from the GUI? If not, is there another way?

Re: Can door sensor trigger audio on Raspberry Pi

Posted: 03 Aug 2016 23:52
by highspeedz
If no one knows an answer to the above question.. than perhaps another question would be what is a common thing to link the door sensor to. I am looking for an audible indication that the door has been opened.

Re: Can door sensor trigger audio on Raspberry Pi

Posted: 04 Aug 2016 13:40
by the wife
Not sure this would be the best way, but I have just tried it and it worked on my pi.

At the trigger point, you could do a system call such as this:

Code: Select all

system("omxplayer /opt/z-way-server/automation/siren.mp3");
On my pi, omxplayer was there by default but I do not know whether it is standard or whether it is the best way of playing sounds. siren.mp3 is just a test file I copied to the directory.

In order for any system call to work you need to add the command to .syscommands in /opt/z-way-server/automation. This is a hidden file.

I tried this from the UI 'Load JavaScript Code' app, binding to a switch value and it was triggered successfully. And it works from my own custom module. It is not something I have done before, so I do not know whether there are any pitfalls but I hope it is of help.

Re: Can door sensor trigger audio on Raspberry Pi

Posted: 05 Aug 2016 04:48
by highspeedz
Thanks for the response. I was able to get the sound to play from the command line. Can you show me the code you put in the "Load Custom Java Script" App.. Thanks.

Re: Can door sensor trigger audio on Raspberry Pi

Posted: 05 Aug 2016 14:46
by highspeedz
I ended up doing this...which seems close..but no sound..

Code: Select all

zway.devices[1].instances[0].commandClasses[32].data.level.bind(function() {  
   if (this.value = 255)  

     debugPrint("Executing trigger",this.value);  
     system('"/usr/bin/omxplayer /opt/z-way-server/automation/siren.mp3"');  
 });  


Re: Can door sensor trigger audio on Raspberry Pi

Posted: 05 Aug 2016 15:53
by the wife
My code was very similar, binding to a binarySwitch level though and I called omxplayer without the full path, which worked.

I just tried your system call on its own and I didn't get sound. When I checked the log file (/var/log/z-way-server.log the error was "This command is denied by policy" which usually means that the command is not in .syscommands

I think it is the single quote followed by double quote causing the issue. Maybe you were adding the whole expression to .syscommands?

Code: Select all

system("/usr/bin/omxplayer /opt/z-way-server/automation/siren.mp3");
does work for me, but only after I added /usr/bin/omxplayer to .syscommands and restarted z-way-server.

Re: Can door sensor trigger audio on Raspberry Pi

Posted: 05 Aug 2016 16:33
by highspeedz
OK.,.thanks..I will try tonight when I am back at the razberry.. Another problem is that I didn't realize I just needed "/usr/bin/omxplayer" ... I put the whole command in there.

Re: Can door sensor trigger audio on Raspberry Pi

Posted: 05 Aug 2016 17:25
by pz1
the wife wrote:

Code: Select all

system("/usr/bin/omxplayer /opt/z-way-server/automation/siren.mp3");
I fear that the mp3 will not survive a ZWay update. Directory

Code: Select all

/opt/z-way-server/automation/storage
is not affected by the update mechanism. (There is some discussion about a special user directory, but I have not seen that one yet)

Re: Can door sensor trigger audio on Raspberry Pi

Posted: 06 Aug 2016 01:17
by highspeedz
Not sure what I am doing wrong...when I use the code above...when I trigger the door sensor...the javascript gets in an infinite loop. It keeps executing over and over again...not sure what I am doing wrong.

Re: Can door sensor trigger audio on Raspberry Pi

Posted: 06 Aug 2016 03:23
by highspeedz
OK...changed (this.value = 255) to (this.value == 255) that fixed it. Thanks for the help!