Easiest way to play a mp3 audio file on Raspi with Dzvents?
Moderator: leecollings
-
paul402
- Posts: 105
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Easiest way to play a mp3 audio file on Raspi with Dzvents?
I have a warning script when the bathroom roof window is open for more than 30 minutes and when the outside temperature is less than 17C it sends a Telegram message. I have an amp and speaker attached to the Raspi but haven't worked out yet how to play an audio file with Dzvents. The file works fine in a terminal and from Thonny.
I couldn't see anything in the Dzvents help files. Did I miss it?
Would appreciate a link or tip to get this working.
Cheers
I couldn't see anything in the Dzvents help files. Did I miss it?
Would appreciate a link or tip to get this working.
Cheers
- habahabahaba
- Posts: 266
- Joined: Saturday 18 March 2023 14:44
- Target OS: Windows
- Domoticz version: 2024.4
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
If I understood you correctly you need
Code: Select all
domoticz.executeShellCommand(YOUR COMMAND )
- waltervl
- Posts: 6678
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
And make sure the command has an absolute path so some like /home/pi/scripts/yourbash.sh
You can also test it by running the command with sudo as that is what Domoticz is doing
You can also test it by running the command with sudo as that is what Domoticz is doing
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
paul402
- Posts: 105
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
Thanks for that. It's so easy when you know!
-
paul402
- Posts: 105
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
Well it didn't end up being easy!
This audio file in the /scripts directory
sh01CheckFridgeDoor.mp3
This python file in /scripts with all permissions
Plays perfect in Thonny.
CMD Box
Runs without error but no sound
Create a Domoticz script to run every minute.
Runs perfect without Domoticz errors but no sound.
I'm obviously doing something wrong but what?
It's driving me crazy.
This audio file in the /scripts directory
sh01CheckFridgeDoor.mp3
This python file in /scripts with all permissions
Code: Select all
#!/usr/bin/python3
import sys
sys.path.append('/home/pi/domoticz/scripts/python')
# to check path is updated
print (sys.path)
### File name here
af='/home/pi/domoticz/scripts/python/sh01CheckFridgeDoor.mp3'
import pygame
pygame.mixer.init()
pygame.mixer.music.load(af)
pygame.mixer.music.play()
CMD Box
Code: Select all
sudo/without sudo python/python3 /home/pi/domoticz/scripts/python/01pythonPlayAudioCheckFridgeDoor.py
Create a Domoticz script to run every minute.
Runs perfect without Domoticz errors but no sound.
I'm obviously doing something wrong but what?
It's driving me crazy.
- habahabahaba
- Posts: 266
- Joined: Saturday 18 March 2023 14:44
- Target OS: Windows
- Domoticz version: 2024.4
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
And what is your Dzvents script?
-
paul402
- Posts: 105
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
Code: Select all
return {
active = true,
logging = {
level = domoticz.LOG_DEBUG,
marker = 'audio output'
},
on = {
timer = {'Every minute'}
},
execute = function(domoticz)
local cde = "home/pi/Documents/01pythonPlayAudioCheckFridgeDoor.py"
domoticz.executeShellCommand({
command = cde,
callback = "myTrigger",
timeout = 2,
}
)
end
}
- habahabahaba
- Posts: 266
- Joined: Saturday 18 March 2023 14:44
- Target OS: Windows
- Domoticz version: 2024.4
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
If you are using "callback" so you have to use
"on = {
shellCommandResponses = { 'mycallbackstring' }"
Just try without callback and timeout - simple string.
"on = {
shellCommandResponses = { 'mycallbackstring' }"
Just try without callback and timeout - simple string.
- habahabahaba
- Posts: 266
- Joined: Saturday 18 March 2023 14:44
- Target OS: Windows
- Domoticz version: 2024.4
- Contact:
-
paul402
- Posts: 105
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
I guess you mean this format domoticz.executeShellCommand('some shell command')
So I should use
domoticz.executeShellCommand('home/pi/Documents/01pythonPlayAudioCheckFridgeDoor.py')
which executes without error but without sound. I think that it's time for bed. Enough for tonight.
So I should use
domoticz.executeShellCommand('home/pi/Documents/01pythonPlayAudioCheckFridgeDoor.py')
which executes without error but without sound. I think that it's time for bed. Enough for tonight.
- habahabahaba
- Posts: 266
- Joined: Saturday 18 March 2023 14:44
- Target OS: Windows
- Domoticz version: 2024.4
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
Slash befor the "home..."?
-
paul402
- Posts: 105
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
I eventually found a solution on stackexchange....
So you need to add this after the play() command then it works from the cli and Domoticz.
Who knows why!.... but I've wasted a lot of time on this.
I'm falling out of love with Raspis and its OS and dependencies. Designed by sadists for masochists...
So you need to add this after the play() command then it works from the cli and Domoticz.
Code: Select all
while pygame.mixer.music.get_busy() == True:
pass
I'm falling out of love with Raspis and its OS and dependencies. Designed by sadists for masochists...
- gizmocuz
- Posts: 2709
- Joined: Thursday 11 July 2013 18:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Top of the world
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
Raspbian is based on Debian which is a great OS.
Your issue was in a Python script, so there is no need to shout on Debian
Sure there are other ways to play this MP3 file.
Could be that dzVents/Domoticz now has to wait until the MP3 is played... which is not desired, better to play this in the background
You can also use mpg123 and play it in the background
Your issue was in a Python script, so there is no need to shout on Debian
Sure there are other ways to play this MP3 file.
Could be that dzVents/Domoticz now has to wait until the MP3 is played... which is not desired, better to play this in the background
You can also use mpg123 and play it in the background
Code: Select all
import subprocess
subprocess.Popen(["mpg123", "music.mp3"])
print("Started in background.")Quality outlives Quantity!
- waltervl
- Posts: 6678
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
domoticz.executeShellCommand is running the started proces/python script in async. So why in the Python script a subprocess?gizmocuz wrote: Tuesday 25 November 2025 8:48...
Could be that dzVents/Domoticz now has to wait until the MP3 is played... which is not desired, better to play this in the background
You can also use mpg123 and play it in the background
Code: Select all
import subprocess subprocess.Popen(["mpg123", "music.mp3"]) print("Started in background.")
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
paul402
- Posts: 105
- Joined: Monday 23 May 2016 23:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
Well blow me down! That worked on both my Domoticz Pi3 and Pi4 installations. Thank you.
I only had to add the Python exit() command to the script.
Thanks
I only had to add the Python exit() command to the script.
Thanks
- waltervl
- Posts: 6678
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
What worked? What solution did you end up with?paul402 wrote: Sunday 30 November 2025 11:14 Well blow me down! That worked on both my Domoticz Pi3 and Pi4 installations. Thank you.
I only had to add the Python exit() command to the script.
Thanks
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
- habahabahaba
- Posts: 266
- Joined: Saturday 18 March 2023 14:44
- Target OS: Windows
- Domoticz version: 2024.4
- Contact:
Re: Easiest way to play a mp3 audio file on Raspi with Dzvents?
Yes, show both full scripts please
Who is online
Users browsing this forum: No registered users and 1 guest