Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post Reply
dutchnld
Posts: 26
Joined: Friday 23 October 2015 22:18
Target OS: Raspberry Pi
Domoticz version: 3.5974
Location: Amsterdam, Netherlands
Contact:

Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by dutchnld » Wednesday 23 November 2016 1:33

Hi All,

I've been looking all over the forum but couldnt find anything related to my wish...
I'd like to use the 3.5MM audio output of the raspberry pi to play a sound (whatever) when something happens.

How can you trigger a sound when a (virtual) switch turns off/on?
Preferably a long sound, but if it can play a defined .wav or .mp3 thats flexible using the right file.

Usage examples:

- Your door sensor is activated after 2AM, while your sleeping -> Sound alert!
- A button or dummy switch is activated -> you get a (happy) sound alert. (Dishwasher is ready, at a certain time (alarm), etc ...)

I really hope that one of you was able to control the audio-output of a Pi using Domoticz!

Thanks!
-----
Raspberry Pi Model 2 B w/ Domoticz 3.5974 + Monit + Pi-Hole + RaZberry Z-wave module + RFXcom 433 USB

trixwood
Posts: 510
Joined: Friday 18 March 2016 8:20
Target OS: -
Domoticz version: Offline
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by trixwood » Wednesday 23 November 2016 4:10

Script the notification yourself :-)

Setup your pi for sound...

http://www.raspberrypi-spy.co.uk/2013/0 ... ine-audio/



Create your own script file in the script folder... use aplay :-) or any of the alternatives...
something like

Code: Select all

#!/bin/bash
aplay ~/Luftalarm.wav
(with the right location/name of the music file & player commando...)

Fill it in into Settings->Notification->Custom HTTP/Action (or create a virtual sensor which triggers the script)

And you got what you want...

dutchnld
Posts: 26
Joined: Friday 23 October 2015 22:18
Target OS: Raspberry Pi
Domoticz version: 3.5974
Location: Amsterdam, Netherlands
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by dutchnld » Sunday 27 November 2016 23:54

Hi trixwood,

Thanks a lot for your suggestion!

With your advice I only got halfway unfortunately.
I'm able to execute a script and play a .wav file perfectly, using the commandline.
Both a .sh and .pl script work.

/home/pi/domoticz/scripts/wavtest.sh
/home/pi/domoticz/scripts/wavtest.pl

But when I enter it in a dummy switch nothing happens.
I use this url in the on/off action:

script:///home/pi/domoticz/scripts/wavtest.sh
or
script:///home/pi/domoticz/scripts/wavtest.pl


Normal domoticz log (error log is empty!):
2016-11-27 22:47:09.252 User: jonas initiated a switch command (410/AlarmScript/On)
2016-11-27 22:47:10.222 Executing script: /home/pi/domoticz/scripts/wavtest.sh
2016-11-27 22:47:11.301 User: jonas initiated a switch command (410/AlarmScript/Off)
2016-11-27 22:47:12.292 Executing script: /home/pi/domoticz/scripts/wavtest.pl
2016-11-27 22:47:13.253 User: jonas initiated a switch command (410/AlarmScript/On)
2016-11-27 22:47:14.239 Executing script: /home/pi/domoticz/scripts/wavtest.sh


Contents of my script:

#!/bin/bash
aplay ~/police_s.wav > /dev/null 2>&1 &


I tried the following:
- changed permissions with sudo chmod +x wavtest.sh (and wavtest.pl)
- changed owner with
sudo chown pi:pi wavtest.pl
sudo chown pi:root wavtest.pl
- changed your script by adding /dev/... (read it in the forum)
- even tried to run the .pl file with a .sh file (works in command line)


Any help is greatly appreciated!
-----
Raspberry Pi Model 2 B w/ Domoticz 3.5974 + Monit + Pi-Hole + RaZberry Z-wave module + RFXcom 433 USB

trixwood
Posts: 510
Joined: Friday 18 March 2016 8:20
Target OS: -
Domoticz version: Offline
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by trixwood » Monday 28 November 2016 11:45

replace

script:///home/pi/domoticz/scripts/wavtest.sh

with

script://wavtest.sh

script:// points to the script folder of domoticz :-)

oopee
Posts: 112
Joined: Monday 12 August 2013 11:15
Target OS: Raspberry Pi
Domoticz version: 3.x
Location: Finland
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by oopee » Monday 28 November 2016 13:18

If above (script path) does not help, try to include full path to aplay in your script.

dutchnld
Posts: 26
Joined: Friday 23 October 2015 22:18
Target OS: Raspberry Pi
Domoticz version: 3.5974
Location: Amsterdam, Netherlands
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by dutchnld » Monday 28 November 2016 20:59

Hi trixwood and oopee,

i tried both your suggestions but still no sound. :(

First I changed the path and tried my dummy switch -> nothing
Then I got into the commandline and typed 'which aplay' and it returned /usr/bin/aplay

So I changed the script to:

Code: Select all

#!/bin/bash
/usr/bin/aplay ~/police_s.wav > /dev/null 2>&1 &
My log is still showing no errors and gives this:

2016-11-28 19:51:15.049 User: Admin initiated a switch command (410/AlarmScript/Off)
2016-11-28 19:51:16.019 Executing script: /home/pi/domoticz/scripts/wavtest.sh
2016-11-28 19:51:17.190 User: Admin initiated a switch command (410/AlarmScript/On)
2016-11-28 19:51:18.173 Executing script: /home/pi/domoticz/scripts/wavtest.sh

What I would like to do is have the most simple (hello world?) script to check if the combination of my dummy-switch and the script really works.
Then I only have to focus on the audio script, which then only works in command line.

Thanks again!
-----
Raspberry Pi Model 2 B w/ Domoticz 3.5974 + Monit + Pi-Hole + RaZberry Z-wave module + RFXcom 433 USB

pvm
Posts: 952
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: Stable
Location: NL
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by pvm » Monday 28 November 2016 23:20

When the script is executed by any other user than pi it will not find the sound file. Replace the ~/ with the full path: /home/pi/
Synology NAS, PI3, ZWave, Xiamo zigbee devices, BTLE plant sensor

dutchnld
Posts: 26
Joined: Friday 23 October 2015 22:18
Target OS: Raspberry Pi
Domoticz version: 3.5974
Location: Amsterdam, Netherlands
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by dutchnld » Monday 28 November 2016 23:44

@pvm you are the (wo)man of the day!!!

problem is solved by adding the full path of the .wav file.

After that I also removed the full path of aplay and it still works.

Final script:
#!/bin/bash
aplay /home/pi/police_s.wav > /dev/null 2>&1 &
Usage examples:

- cat entered the house after 9PM (so i can close the lock and won't find dead birds/mice on the stairs they catch in the middle of the night)
- email from specific person/company arrives (it opens a virtual switch via outlook run a program) and can now play a sound!
- when a burglar enters the house it plays a nasty loud noise (although they know where my Pi is then....)
- the doorbutton is pressed and a sound plays (cheap extra doorbel this way) ( i have 2 clickonclickoff doorbells around the house)
- and probably many more i find useful later....
-----
Raspberry Pi Model 2 B w/ Domoticz 3.5974 + Monit + Pi-Hole + RaZberry Z-wave module + RFXcom 433 USB

User avatar
capman
Posts: 202
Joined: Friday 12 July 2013 20:48
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Belgium
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by capman » Tuesday 29 November 2016 20:00

A want the same thing. But my domoticz is running on a synology , and a running max2play on a seperate raspberry pi. A think that a just use the script and change it to the ip adres of the rpi ?

pvm
Posts: 952
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: Stable
Location: NL
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by pvm » Tuesday 29 November 2016 20:13

I'm not a max2play expert but I guess you have to clear the current playlist and put the required track in?
Synology NAS, PI3, ZWave, Xiamo zigbee devices, BTLE plant sensor

EDsteve
Posts: 36
Joined: Thursday 13 October 2016 11:43
Target OS: Linux
Domoticz version:
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by EDsteve » Friday 20 January 2017 13:42

Hi,

i am working on something similar. Sound should play after event triggers. My script as posted in this threat:

Code: Select all

#!/bin/bash
aplay /usr/share/sounds/alsa/Front_Center.wav  > /dev/null 2>&1 &
The script runs perfectly from the command line with sudo.

But domoticz just shows this without error or sound:

Code: Select all

2017-01-20 18:51:41.964 Executing script: /home/fa/domoticz/scripts/creepsound.sh
SOLUTION:
my user was not in the audio group.
For linux noobs like me:

Code: Select all

sudo usermod -g <audio> username

MCPXXL
Posts: 2
Joined: Monday 06 March 2017 16:31
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by MCPXXL » Monday 06 March 2017 16:42

Hello
I am really new in pi and scripting as a windows user

I have the same problems like the other or better more of them because everything is a miracle atm

So i got running my aplay script from command prompt with ./mp3.sh on my usb audio

Code: Select all

#!/bin/bash
sudo aplay ~/mp3/bob_marley-a_la_la_la_la_long_v2.wav  > /dev/null 2>&1 &
exit 0

On command prompt i run this without messages and sound plays until it ends
pi@raspberrypi:~/domoticz/scripts$ /home/pi/domoticz/scripts/mp3.sh



On Activation:
script:///home/pi/domoticz/scripts/mp3.sh

After a lot of 256 errors i now get this shown in log

2017-03-06 15:20:10.314 Executing script: /home/pi/domoticz/scripts/mp3.sh

But no sound is to hear :-(


Is there any idea what the hell i am to stupid for ?

MCPXXL
Posts: 2
Joined: Monday 06 March 2017 16:31
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector

Post by MCPXXL » Monday 13 March 2017 17:48

no one any idea ?

Post Reply

Who is online

Users browsing this forum: naitsirhc and 1 guest