Random choise mp3 playlist
Moderators: grovkillen, Stuntteam, TD-er
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Random choise mp3 playlist
I use the PFplayer mini on my ESP8266 device with the latest rom.It works great but is there a a rule to start playing the playlist like a Lucky shot, so not sequently but randomly?
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
We don't have a random function (which is a great feature by the way), but you could create one in the rules.
What you could do, is use the RSSI as random generator and multiply it by the uptime.
Let's assume you have the current track nr stored in variable #1 and number of tracks in variable #2
In this example I will store the random number in variable #3.
With this code your next track nr is in variable #1 (to be used in rules with [int#1])
(untested code)
What you could do, is use the RSSI as random generator and multiply it by the uptime.
Let's assume you have the current track nr stored in variable #1 and number of tracks in variable #2
In this example I will store the random number in variable #3.
Code: Select all
let,3,abs(%rssi%) * %uptime%
let,1,([int#3]*[int#1])%[int#2]
(untested code)
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
Looking at the commands for the DFR-0299, there is a command available to get random playback, it just isn't available to be set.
And the same goes for 'repeat', AFAICS, which would probably be useful here as well.
Wouldn't be too hard to add, except I don't have such unit available, so actual testing would have to be done by you or someone else. What type and flash configuration (.bin file name is helpful) do you use?
And the same goes for 'repeat', AFAICS, which would probably be useful here as well.
Wouldn't be too hard to add, except I don't have such unit available, so actual testing would have to be done by you or someone else. What type and flash configuration (.bin file name is helpful) do you use?
/Ton (PayPal.me)
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
I've opened a pull request (PR #3615) adding a mode and a repeat command.Dick60 wrote: 01 May 2021, 08:01 I use the PFplayer mini on my ESP8266 device with the latest rom.It works great but is there a a rule to start playing the playlist like a Lucky shot, so not sequently but randomly?
This plugin is only available in the 'test' .bin files, but as they are currently too big, they won't be available in the PR builds. (There's a separate PR #3600 to try and solve that).
I can provide you with an (adapted) 'test' build if you provide the type you need, and a list of other plugins that must be available too (if any), as I have to leave some out to create a working build.
Based on your highly appreciated feedback we can opt to actually include it in ESPEasy.
/Ton (PayPal.me)
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Re: Random choise mp3 playlist
thanks for the explanation. At the moment I use the test.bin because that was the only bin where the MP3 player was available. What i need in my project is the mp3 player and some normal switches. I appreciate the offer, to make an costum test.bin for me. After a succesfull implementation I can give you feedback of my findings.
I hope you have enough info to create the test.bin.
I hope you have enough info to create the test.bin.
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
Here's a test-build (attached below) with the new commands included.Dick60 wrote: 01 May 2021, 12:19 At the moment I use the test.bin because that was the only bin where the MP3 player was available. What i need in my project is the mp3 player and some normal switches. I appreciate the offer, to make an costum test.bin for me. After a succesfull implementation I can give you feedback of my findings.
From the (also updated) documentation:
You do not have the required permissions to view the files attached to this post.
/Ton (PayPal.me)
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Re: Random choise mp3 playlist
I hope, there is no misunderstanding from my side, I have load the attached Bin on my NodeMcu without any problems, created the device DFPLAYER-MINI and tested the play mode (http://xxx.xxx.x.xx/control?cmd=play,3). Worked perfect. Tried the new option MODE at boot
Did not work. Tried http://xxx.xxx.x.xx/control?cmd=mode,3 in my IE, Did not work.
Any idea? What am I doing wrong?
Code: Select all
On System#Boot do
vol,10
mode,3
delay,180 //play the song for 30 seconds (this is a generic command!)
stop
endonAny idea? What am I doing wrong?
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
Not sure if you are doing anything wrong, there are a lot of possible causes here
- You can enter the commands, as shown in the documentation above, on the Tools page, no prefix like control?cmd= etc needed there, and the quickest way to test a command
- Calling that type of commands from the System#Boot event might be a bit 'early', not sure if the plugin is already fully initialized at that point (though I'd expect it would be). Adding a delay like you did is a big no-no, so that's why I updated the example code, see below.
- I have no player module available, so I've been unable to do any testing at all, just extended the existing command structure
- Chinese clones are not necessarily 100% compatible with the original player, so they can have a chip that doesn't support these commands, don't know what exact type of module you are using
Updated Rules example (as available in the updated documentation):
- You can enter the commands, as shown in the documentation above, on the Tools page, no prefix like control?cmd= etc needed there, and the quickest way to test a command
- Calling that type of commands from the System#Boot event might be a bit 'early', not sure if the plugin is already fully initialized at that point (though I'd expect it would be). Adding a delay like you did is a big no-no, so that's why I updated the example code, see below.
- I have no player module available, so I've been unable to do any testing at all, just extended the existing command structure
- Chinese clones are not necessarily 100% compatible with the original player, so they can have a chip that doesn't support these commands, don't know what exact type of module you are using
Updated Rules example (as available in the updated documentation):
Code: Select all
On System#Boot do
vol,10
play,255 // file number 255
timerSet,1,30 //play the song for 30 seconds (this is a generic command!)
Endon
On Rules#Timer=1 do
Stop
Endon
/Ton (PayPal.me)
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Re: Random choise mp3 playlist
I've tested the new command MODE as described in your previous answere. The PLAY option is working but the MODE,3 without the "control?cmd=" (http://xxx.xxx.x.xx/mode,3) is not working for now. Probably I have to wait for the final version of the plug-in.
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
You always need to include a command prefix as you tried first.Dick60 wrote: 02 May 2021, 14:50 I've tested the new command MODE as described in your previous answere. The PLAY option is working but the MODE,3 without the "control?cmd=" (http://xxx.xxx.x.xx/mode,3) is not working for now. Probably I have to wait for the final version of the plug-in.
Can you try sending the command in the "command" input field on the Tools page?
If you submit the command you will see some output, which may also state if it is an unknown command.
To be honest, I do find it a bit too generic, so maybe it conflicts with some other plugin?
You can also add the "task prefix" to the command to make sure you address it to the task you want to control.
See: https://espeasy.readthedocs.io/en/lates ... f-a-plugin
Also if you submitted the command there, the browser will reload with the command encoded in a new URL in the browser URL bar, so you can use that later on other devices.
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Re: Random choise mp3 playlist
this is all above my level of knowledge. Probably I use Variables for now to monitor the mp3's already played and that the new play not start Always with the same mp3. This is part of my alarm system (barking dog) and you do not want to start with the same mp3 but "randomly".
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
I will order a MP3-player module from my friends at Ali, but delivery will take a couple of weeks, so any testing by me will be postponed until then.
/Ton (PayPal.me)
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Re: Random choise mp3 playlist
thank you for the effort. I appreciate it.
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Re: Random choise mp3 playlist
The MP3 is working perfectly using the "normal control options mentioned in the WIKI. A nice, missing function, would be the option to put the volume and the Play number in a rule. Bur for now I m happy with it and thiefs are welcome with the sound of barking agressieve dogs. 
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
Today I did some further investigation, but the limitation here seems to be in the chips/modules, not related to the plugin. They just don't conform to the documentation of the DFPlayer module, and that mode command just doesn't do what the documentation prescribes.Dick60 wrote: 02 May 2021, 14:50 I've tested the new command MODE as described in your previous answere. The PLAY option is working but the MODE,3 without the "control?cmd=" (http://xxx.xxx.x.xx/mode,3) is not working for now. Probably I have to wait for the final version of the plug-in.
I've put a note in the documentation, and declared the work on the PR as completed.
The 'repeat' command is working as expected (when executed, plays all mp3's from first to last, then starts at the first again).
Now we wait for that PR (#3615) to be merged in ESPEasy.
/Ton (PayPal.me)
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
It has been merged
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Re: Random choise mp3 playlist
Perhaps a stupid remark, is it ready for testing? Is the option for volume level, mentioned before not possible using rules?
Code: Select all
On System#Boot do
[u][b]vol,10[/b][/u]
play,255 // file number 255
timerSet,1,30 //play the song for 30 seconds (this is a generic command!)
Endon
On Rules#Timer=1 do
Stop
Endon-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
AFAICS, the 'vol,<volume>' command should work as intended, or did I misunderstand your question?
That command uses exacty the same function call as the initial volume, settable in the configuration.
That command uses exacty the same function call as the initial volume, settable in the configuration.
/Ton (PayPal.me)
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
Here's the latest build from the Github Actions download: (same .bin I posted earlier)
You do not have the required permissions to view the files attached to this post.
/Ton (PayPal.me)
-
TyraNoah
- New user
- Posts: 2
- Joined: 23 May 2021, 01:09
Re: Random choise mp3 playlist
Quite a lot that I really overlooked! That is helpful!
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Re: Random choise mp3 playlist
I am sorry, I don't understand, which BIN do i need to load to test the results?
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
You can download a .bin (in a .zip file) from post #19, above. Assuming that fits your ESP. If you need another type of build, just name it, and I'll put it here for download too.
/Ton (PayPal.me)
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Re: Random choise mp3 playlist
That is what I did, copied it in the latest release (20210802) bin folder, strted the flasher and selected the .bin you send to me. Finished succefull but as soon as I want to add the MP3 device, it is not in the list. Any idea or what am I doing wrong.
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
Check on the Info page (or the site footer) what .bin file you are using, it is in the 'test' builds. Looks like I posted the wrong .bin file
The improvements aren't included in the release build yet, so I'll post a test build asap.
The improvements aren't included in the release build yet, so I'll post a test build asap.
/Ton (PayPal.me)
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
A bin that does actually include the updated DFPlayer MP3 plugin:
(based on today's 'mega' branch, as the improvements have already been merged, but are not released yet)
(based on today's 'mega' branch, as the improvements have already been merged, but are not released yet)
You do not have the required permissions to view the files attached to this post.
/Ton (PayPal.me)
-
Dick60
- Normal user
- Posts: 244
- Joined: 11 Feb 2018, 17:35
- Location: The Netherlands
Re: Random choise mp3 playlist
I tested it and it works as expected. Thanks for the very very good service you delivered. 
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
-
Sminter4
- Normal user
- Posts: 44
- Joined: 04 Aug 2021, 23:25
- Location: DE
Re: Random choise mp3 playlist
I'm also looking for a random number, but one that's plugin-independent and has the option to restrict it between a min and max value.
A function like this would be cool: let,<var nr>,rnd,<min>,<max>
Is this or something similar possible?
A function like this would be cool: let,<var nr>,rnd,<min>,<max>
Is this or something similar possible?
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
It would then be something like:
Or in old-style notation:
Note: The conversion %c_random%(min,max) doesn't yet exist!
Code: Select all
let,random,%c_random%(%v_min%,%v_max%)
Code: Select all
let,1,%c_random%(1,100)
/Ton (PayPal.me)
-
Sminter4
- Normal user
- Posts: 44
- Joined: 04 Aug 2021, 23:25
- Location: DE
Re: Random choise mp3 playlist
Is such a function feasible?
And if so, when?
And if so, when?
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
We're very close to making a new official release and this will not really affect existing code.
So I think we can include it as it is a nice feature to have.
So I think we can include it as it is a nice feature to have.
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
Added the feature, it will be included in the next upcoming build, which will very likely be in April this year 
-
Sminter4
- Normal user
- Posts: 44
- Joined: 04 Aug 2021, 23:25
- Location: DE
Re: Random choise mp3 playlist
Wow - you guys are awesome! 
I've developed a new feature so quickly on the side.
I'm looking forward to testing it! I urgently need it for my new project...
I've developed a new feature so quickly on the side.
I'm looking forward to testing it! I urgently need it for my new project...
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
What build binary do you need, so I can make a test build for you to test it.
Will nearly be the same as the upcoming release build
Will nearly be the same as the upcoming release build
-
Sminter4
- Normal user
- Posts: 44
- Joined: 04 Aug 2021, 23:25
- Location: DE
Re: Random choise mp3 playlist
Gladly. I need the normal_ESP8266_4M1M build.
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
-
Sminter4
- Normal user
- Posts: 44
- Joined: 04 Aug 2021, 23:25
- Location: DE
Re: Random choise mp3 playlist
With the few tests I was able to perform, I couldn't find any errors in the random function. 
For my application, I don't need any decimal places. However, I can round them with
However, this only seems to work with the number variables. The name variables are spitting out incorrect values here.
It seems as if the next largest number variable is simply rounded instead of the word variable.
For my application, I don't need any decimal places. However, I can round them with
Code: Select all
[int#1]Code: Select all
[int#%v_random%]-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
Code: Select all
let,1,%c_random%(1,100)
logentry,"My random value: [int#1]"
Or
Code: Select all
let,1,%c_random%(%v_min%,%v_max%)
let,random,[int#1]
logentry,"My random value: %v_random%"
Never tested it.
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
That should be:Sminter4 wrote: 29 Apr 2025, 21:45 With the few tests I was able to perform, I couldn't find any errors in the random function.
For my application, I don't need any decimal places. However, I can round them withHowever, this only seems to work with the number variables. The name variables are spitting out incorrect values here.Code: Select all
[int#1]It seems as if the next largest number variable is simply rounded instead of the word variable.Code: Select all
[int#%v_random%]
Code: Select all
let,random,%c_random%(1,100)
...[int#random]...
/Ton (PayPal.me)
-
Sminter4
- Normal user
- Posts: 44
- Joined: 04 Aug 2021, 23:25
- Location: DE
Re: Random choise mp3 playlist
I tested the commands on the tools page. And I can now confirm that this syntax works:
If it's well documented, it shouldn't be a problem...
Code: Select all
[int#random]-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
Well Ton made the named variables, so without having read the docs, I can be sure he did a good job.
And Ton can confirm I didn't read the docs for it, judging our Signal chat of a few minutes ago
And Ton can confirm I didn't read the docs for it, judging our Signal chat of a few minutes ago
-
Ath
- Normal user
- Posts: 4621
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Random choise mp3 playlist
For reference, the use of Internal variables is documented here
/Ton (PayPal.me)
-
Sminter4
- Normal user
- Posts: 44
- Joined: 04 Aug 2021, 23:25
- Location: DE
Re: Random choise mp3 playlist
Now I need the random function in other projects as well. Therefore, I only just noticed that the current official build (April 30, 2025) doesn't support this function at all.
I can test everything successfully in the version posted here in the forum on April 29, 2025. Or has the function not been included?
I can test everything successfully in the version posted here in the forum on April 29, 2025. Or has the function not been included?
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
-
Sminter4
- Normal user
- Posts: 44
- Joined: 04 Aug 2021, 23:25
- Location: DE
Re: Random choise mp3 playlist
I used the "ESP_Easy_mega_20250612_collection_G_ESP8266_4M1M.bin" version of the web flasher. Unfortunately, the random function fails here as well.
Can you create a build G for the 8266 with the random function?
Can you create a build G for the 8266 with the random function?
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
I can but right now it is excluded in builds with LIMIT_BUILD_SIZE set, which are nearly all ESP8266 builds right now to make it fit....
I will check to see how much difference it makes so we could remove this restriction.
It really has become extremely hard to make it all fit on ESP8266.
So that's why we have decided a while ago that new features will not be added to ESP8266 builds (can still be used in custom builds though).
However I think it might not be that much extra for the random function, so I can make it part of any build (likely 'minimal OTA' builds for 1M flash might still no longer fit...)
I will check to see how much difference it makes so we could remove this restriction.
It really has become extremely hard to make it all fit on ESP8266.
So that's why we have decided a while ago that new features will not be added to ESP8266 builds (can still be used in custom builds though).
However I think it might not be that much extra for the random function, so I can make it part of any build (likely 'minimal OTA' builds for 1M flash might still no longer fit...)
-
Sminter4
- Normal user
- Posts: 44
- Joined: 04 Aug 2021, 23:25
- Location: DE
Re: Random choise mp3 playlist
Why was the random function removed from the last build?TD-er wrote: 29 Apr 2025, 12:40 Added the feature, it will be included in the next upcoming build, which will very likely be in April this year![]()
Can I add the function by commenting it out in a custom build?
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
Just made a build for it, will upload it to the web flasher page:
https://github.com/letscontrolit/ESPEas ... 5656037422
And it wasn't removed, as long as it was merged, it was wrapped in the check for LIMIT_BUILD_SIZE flags.
https://github.com/letscontrolit/ESPEas ... 5656037422
And it wasn't removed, as long as it was merged, it was wrapped in the check for LIMIT_BUILD_SIZE flags.
-
TD-er
- Core team member
- Posts: 10333
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Random choise mp3 playlist
Just uploaded that build to here: https://td-er.nl/ESPEasy/latest/
You might need to refresh the page to see the 20250614 build.
You might need to refresh the page to see the 20250614 build.
-
Sminter4
- Normal user
- Posts: 44
- Joined: 04 Aug 2021, 23:25
- Location: DE
Re: Random choise mp3 playlist
Thanks - the feature is included again in build ESP_Easy_mega_20250614_collection_G_ESP8266_4M1M.
Now I can continue my project.

Now I can continue my project.
Who is online
Users browsing this forum: Ahrefs [Bot], Anthropic Claude Bot [bot], Google [Bot] and 1 guest