Haunted house - how to play audio and immediately switch tracks

I’m using home assistant to automate a haunted house. So far I’ve just been automating lighting effects and DMX devices, but I’d like to add audio. I was thinking I could use a DLNA receiver like AudioCast, and then hook that up to the house sound system (separate channel per room). It integrates easily with home assistant, but my issue is that I normally have background music going, and when I want to trigger a scene change, there’s a delay of a few seconds before the DLNA device can change tracks where there is silence, and that won’t fly. Are there any tricks I could do to eliminate that and make it gapless? Or even some other way I could play audio through home assistant?

You could give this a try:
DF-Player mini — ESPHome

It’s fairly easy to set up, not sure if the signal is high enough to be played on speakers the way you want.
They are cheap enough to test I believe.

All the speakers have amplifiers, so I don’t think volume would be an issue. Thanks, I’ll check it out!

Ok, a few noob questions. So I guess I could pick up some DF-player minis on amazon, along with some NodeMCU ESP8266 boards, so then I should be able to easily integrate with home assistant? I already have worked with ESPHome to do some motion sensors using ESP32 boards, so I know how to do that much. Where does the headphone jack come in? Do I need to just buy that component separately, and then solder the 2 leads onto the corresponding pins of the NodeMCU?

Yes that is one method.
Or you cut the wire on the speakers and solder that on.
Or just look around and see if you have something laying around.

Thanks. I’m a little short on time to get this working. This would work with a ESP32, not only an ESP8266, right? I see in the DF-Player information it talks about setting up a UART bus in my configuration. I’m still relatively new to home assistant, so do you happen to know if there’s some step by step instructions to getting this set up? I did some quick searching around but didn’t find anything.

ESP8266 is fine.
I have mine connected to a 8266.

I can post my configuration later when I’m at the computer.

This is all there is to it:

  - service: dfplayer_next
      - dfplayer.play_next:
  - service: dfplayer_play
      file: int
      - dfplayer.play: !lambda 'return file;'

  tx_pin: GPIO2
  rx_pin: GPIO4
  baud_rate: 9600

# Declare DFPlayer mini module
      logger.log: 'Somebody press play!'

I don’t have any need for the other services but both wiring and configuration of this is very simple.

So that goes in the configuration.yaml file? Where do you make the association between a ESPHome integration and the uart or services?

This is ESP-Home yaml.
That goes in the configuration of the device/GUI of ESP-Home.

The device is then visible here:

and the service here:

or in automations/scripts

Got everything hooked up and working, but the sound quality is pretty awful. Is that to be expected or is there something that can be done to improve that? Right now I’m using headphones hooked up to the speaker pins. Would it sound better using the DAC pins with an external stereo?

Also, is it possible to add some basic controls to a card on the dashboard? Volume control, track selection, play, pause?

Add the services to the yaml and you should have those controls.

I can’t say that it’s bad sound in it.

Here is a tiny 1 inch speaker in this, similar to this one. Perhaps the same, not sure.
Amazon.com: Adafruit Mini Metal Speaker w/Wires - 8 ohm 0.5W [ADA1890] : Electronics
Connected without any amplifier, just directly on to the df player

(22) Chernobyl - YouTube

And keep in mind that the recording here is soon 40 years old and from tapes to digital (I assume), then recorded on a mobile phone.
So I can’t say that it sounds bad.

I ended up hooking up to my stereo via the DAC pins and it sounds better.

I did add those services in the yaml, which allowed me to call those services in the developer section. But when I go to the ESPHome devices, there is one device for my MP3 player, but that device doesn’t have any entities, which doesn’t seem right. Is it?

For the dashboard, I see I could add a button, but that only seems to work with entities.

The DF player does not have any entities so that seems correct.
It only has services.

You could add a button in ESP-Home yaml that press play, pause, volume and all those services.
Or you create a input_button in HA that call the services on the device.
Whichever you want.

Personally I would do a ESP-Home button since that follows the device and is easier to understand what it does

EDIT make sure you first measure the voltage on that pin so that it’s not a 5 volt pin.

I just had a look at the datasheet, you could actually get one entity.
Adding a cable to the BUSY pin and adding a binary sensor in ESP-Home means you can get the status of the player.

Thanks, I took a look and it seems like making a button on in the ESPHome yaml shouldn’t be too hard. How would I go about creating a button that can take an input to make it play a specific track? Or some other way to get a track selection capability onto the dashboard.

There are services for that.
Have a look in the documentations for DF player as I posted in the first post here.

Going to bed now so I can’t help at the moment