Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
Moderator: leecollings
-
- Posts: 20
- Joined: Friday 23 October 2015 22:18
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.5974
- Location: Amsterdam, Netherlands
- Contact:
Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
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!
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
Raspberry Pi Model 2 B w/ Domoticz 3.5974 + Monit + Pi-Hole + RaZberry Z-wave module + RFXcom 433 USB
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
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
(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...

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

something like
Code: Select all
#!/bin/bash
aplay ~/Luftalarm.wav
Fill it in into Settings->Notification->Custom HTTP/Action (or create a virtual sensor which triggers the script)
And you got what you want...
-
- Posts: 20
- Joined: Friday 23 October 2015 22:18
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.5974
- Location: Amsterdam, Netherlands
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
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!
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
Raspberry Pi Model 2 B w/ Domoticz 3.5974 + Monit + Pi-Hole + RaZberry Z-wave module + RFXcom 433 USB
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
replace
script:///home/pi/domoticz/scripts/wavtest.sh
with
script://wavtest.sh
script:// points to the script folder of domoticz
script:///home/pi/domoticz/scripts/wavtest.sh
with
script://wavtest.sh
script:// points to the script folder of domoticz

-
- Posts: 40
- Joined: Monday 12 August 2013 11:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.x
- Location: Finland
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
If above (script path) does not help, try to include full path to aplay in your script.
-
- Posts: 20
- Joined: Friday 23 October 2015 22:18
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.5974
- Location: Amsterdam, Netherlands
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
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:
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!
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 &
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
Raspberry Pi Model 2 B w/ Domoticz 3.5974 + Monit + Pi-Hole + RaZberry Z-wave module + RFXcom 433 USB
-
- Posts: 550
- Joined: Tuesday 17 June 2014 22:14
- Target OS: NAS (Synology & others)
- Domoticz version: 4.10538
- Location: NL
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
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, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
-
- Posts: 20
- Joined: Friday 23 October 2015 22:18
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.5974
- Location: Amsterdam, Netherlands
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
@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:
- 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....
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:
Usage examples:#!/bin/bash
aplay /home/pi/police_s.wav > /dev/null 2>&1 &
- 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
Raspberry Pi Model 2 B w/ Domoticz 3.5974 + Monit + Pi-Hole + RaZberry Z-wave module + RFXcom 433 USB
- capman
- Posts: 153
- Joined: Friday 12 July 2013 20:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Belgium
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
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 ?
-
- Posts: 550
- Joined: Tuesday 17 June 2014 22:14
- Target OS: NAS (Synology & others)
- Domoticz version: 4.10538
- Location: NL
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
I'm not a max2play expert but I guess you have to clear the current playlist and put the required track in?
Synology NAS, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
-
- Posts: 26
- 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
Hi,
i am working on something similar. Sound should play after event triggers. My script as posted in this threat:
The script runs perfectly from the command line with sudo.
But domoticz just shows this without error or sound:
SOLUTION:
my user was not in the audio group.
For linux noobs like me:
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 &
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
my user was not in the audio group.
For linux noobs like me:
Code: Select all
sudo usermod -g <audio> username
-
- Posts: 2
- Joined: Monday 06 March 2017 15:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
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
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 ?
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 ?
-
- Posts: 2
- Joined: Monday 06 March 2017 15:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
no one any idea ?
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
I've the same problem
Everything is standard, followed: https://www.raspberrypi-spy.co.uk/2013/ ... ine-audio/
I hear the sound when I run in the command line:
But when I make a dummy switch in Domoticz and add as 'On Action':
It doesn't work, I don't hear any sound
In Domoticz I use a user: admin
Everything is standard, followed: https://www.raspberrypi-spy.co.uk/2013/ ... ine-audio/
I hear the sound when I run in the command line:
Code: Select all
aplay /home/pi/police_s.wav > /dev/null 2>&1 &
Code: Select all
script://aplay/home/pi/police_s.wav > /dev/null 2>&1 &
In Domoticz I use a user: admin
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
Found it,
The script wasn't executable yet..
But now I've another problem, when the music plays, domoticz doesn't execute other events.
So I want to flash a light, it wait till the music is ended.
But in the event maker I set them on at the same moment.. :S
Is the rpi or domoticz not capable to execute this together?
The script wasn't executable yet..
But now I've another problem, when the music plays, domoticz doesn't execute other events.
So I want to flash a light, it wait till the music is ended.
But in the event maker I set them on at the same moment.. :S
Is the rpi or domoticz not capable to execute this together?
-
- Posts: 643
- Joined: Thursday 10 November 2016 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
1: Your script call line is directly using aplay (not a .sh script file with this line inside): How can aplay be installed without +x rights?
2: Not sure, directly calling aplay, you're last & for running the sound in background is taken into account.
Try making a true script file, with commands launched from it in background when needed, so Domoticz event system does not have to wait till you're command end before going ahead.
I have such speech synthesis notifications (using espeak) that for sure do not lock Domoticz when processed (they are indeed sometimes mixed together when they overlap)!
-
- Posts: 1
- Joined: Sunday 16 June 2019 21:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
Hi all!
I want domoticz notifications to play through google home mini.
I paird raspberry pi and google home mini.
I made a script that plays an audio file. If I run it from the terminal, then the sound plays in google home. If the script is launched from Domoticz, then the sound plays through the built-in sound card.
Can anyone suggest what to do?
Here is the script
I want domoticz notifications to play through google home mini.
I paird raspberry pi and google home mini.
I made a script that plays an audio file. If I run it from the terminal, then the sound plays in google home. If the script is launched from Domoticz, then the sound plays through the built-in sound card.
Can anyone suggest what to do?
Here is the script
Code: Select all
#!/bin/bash
/usr/bin/mplayer -ao alsa /home/pi/mysound.mp3 > /dev/null 2>&1
Re: Play Audio alert / Sound using the 3.5 MM Raspberry Pi connector
Hi There, I've got the same script as above; when using in terminal the sounds play well, also on the good 3,5 mm output. only when I want to activate the script in Domoticz it shows in the log that its executed but the sound isn't playing over te speakers on that 3,5mm output. I read something about user rights for the audio group, but which user should I add? Pi and root is recently added and didn't fix the problem.
Who is online
Users browsing this forum: No registered users and 0 guests