Can door sensor trigger audio on Raspberry Pi

Discussions about RaZberry - Z-Wave board for Raspberry computer
highspeedz
Posts: 7
Joined: 02 Aug 2016 04:31

Can door sensor trigger audio on Raspberry Pi

Post 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?
highspeedz
Posts: 7
Joined: 02 Aug 2016 04:31

Re: Can door sensor trigger audio on Raspberry Pi

Post 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.
the wife
Posts: 23
Joined: 27 Oct 2015 21:02

Re: Can door sensor trigger audio on Raspberry Pi

Post 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.
highspeedz
Posts: 7
Joined: 02 Aug 2016 04:31

Re: Can door sensor trigger audio on Raspberry Pi

Post 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.
highspeedz
Posts: 7
Joined: 02 Aug 2016 04:31

Re: Can door sensor trigger audio on Raspberry Pi

Post 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"');  
 });  

the wife
Posts: 23
Joined: 27 Oct 2015 21:02

Re: Can door sensor trigger audio on Raspberry Pi

Post 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.
highspeedz
Posts: 7
Joined: 02 Aug 2016 04:31

Re: Can door sensor trigger audio on Raspberry Pi

Post 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.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Can door sensor trigger audio on Raspberry Pi

Post 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)
Since 29-12-2016 I am no longer a moderator for this forum
highspeedz
Posts: 7
Joined: 02 Aug 2016 04:31

Re: Can door sensor trigger audio on Raspberry Pi

Post 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.
highspeedz
Posts: 7
Joined: 02 Aug 2016 04:31

Re: Can door sensor trigger audio on Raspberry Pi

Post by highspeedz »

OK...changed (this.value = 255) to (this.value == 255) that fixed it. Thanks for the help!
Post Reply