ESPHOME I2S to make some noise without any media server

I am beating my head against a wall doing something that I thought should be more simple but has become complicated.

I have a small device flashed with ESPHOME but that doesn’t actually connect to Home Assistant, it is set up to read from an MQTT server on a rPi on a weather station, and sound an alert under certain conditions based on MQTT subscription.

It works fine but is rather a mess of case, hardware, etc. and I was going to get some M5Stack stuff to make it a bit more professional and maybe one of their batteries (right now it needs a plug-in).

The old one is simple – rtttl, a esp8266_pwm output, and I provide a bunmch of notes and duration in a string. Simple, a bit arcane, but works.

The SPK that I got from M5Stack has i2s_audio, and I can set it up as a media player through HA and it works fine. A ha… thinks I… this must be easy now to play a tune, either hard coded or a wave file or something.

Everything I can find posted is either about being a media player for some other thing (e.g. HA), or are not really esphome items, but direct arduino. Maybe I haven’t found the right keyword combination. And it’s not apparent I can drive the SPK from M5Stack with rtttl, I’m afraid to try and might blow it up.

Am I missing something straightforward, is there a simple way to just make some noises with i2s without a media server coming into play? I use this out in isolated places for astronomy and the only device readily available is that rPi (and this is also the thing that, if MQTT disappears, needs to make noise to wake me up, so it needs to be self contained).

Any examples out there of ESPHOME using i2s to make noise in isolation, just itself, no HA. (Yes, I realize a certain discontinuity in asking abuot espHOME and not wanting HOME assistant involved, but I use esphome a lot and it’s very handy and it worked great for rtttl).

Linwood

PS. Yes, I plan to not use the SPK which has a dangly speaker, but could not get the atom with built in speaker, it was out of stock, so this is just a draft version.

I did find this:

https://github.com/jn3va/ESPHomeXTronicalWAVPlayer/tree/main

I’m struggling to figure out though if this is hardware compatible with the M5Stack SPK. That’s the problem with esphome – it allows one to remain pretty ignorant of all the underlying, close-to-hardware details. Sorry… did I say problem, I meant beauty of esphome. :slight_smile:

Other examples, desired, as well as any comments on hardware compatibility of someone has used an SPK before.

In case anyone else shows up here, the repo above will work, but only as-is. The XT_DAC_Audio files in that project (and not quite that, there’s an include missing in XT_DAC_Audio.cpp:

#include "soc/rtc_io_reg.h" // https://esp32.com/viewtopic.php?t=27178

With those original (2019) files and that fix, it will play the included song, however if you download the current version from XTronical, it goes into a reboot loop and will not come up. Not sure why. I tried a couple different versions, one would reboot but then go into a reboot loop as soon as you tried to play, one just wouldn’t boot.

So this gets close but I don’t really want to run versions from 2019, seems likely an esphome (or included code) will break it at some point.

A hardware based solution could be maybe a dfplayer module which is cheap and has a SD card slot as well as an integrated DAC. Could load your noise as files on a micro SD card and your esphome node can then play that locally

This is an unusual situation, most of my (dozens) of esphome devices are either hacked switches or lights, or stuffed in plastic project boxes and plugged into a usb cord.

This one I really wanted a packaged solution, with battery, in fairly minimal size. The M5Stack stuff looked good since it is all so nicely packaged. And I don’t have a 3D printer myself either.

I already have a workable but ugly (and not battery powered) solution. I was hoping for something pretty and already battery pack integrated. Hence my M5Stack obsession.