Turn an ESP8266 WemosD1Mini into an audio notifier for Home Assistant: Play MP3, TTS & RTTL

It is the audio file that plays at the beginning when the device connects to Wifi & MQTT.

2 Likes

Thanks for the reply!

Any chance you might be able to help me out? I hear the startup sound, but I’m not seeing any entries for this in MQTT.

Better tts quality:

  1. Enabling local http (not https) by installation and configuration of NGINX reverse Proxy.

  2. Http service folder configuration (/config/www)
    "Hosting files
    If you want to use Home Assistant to host or serve static files then create a directory called www under the configuration path (/config). The static files in www/ can be accessed by the following URL http://your.local.ip:8123/local/"

  3. Chache folder for Google tts configuration
    # Text to speech
    tts:
    - platform: google_translate
    language: ‘pl’ (Your language)
    cache: true
    cache_dir: /config/www
    time_memory: 300

  4. Node-RED (install node-red-contrib-fs, node-red-contrib-fs-ops)

  • Calling Google tts on different automation - for me message to Kodi Player (creates file xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_pl_-_google_translate.mp3 in /config/www folder)

  • and automation:


    Watch
    File(S): /config/www
    File Lister
    Start Folder: /config/www
    File Pattern: *.mp3
    Address URL
    var file = msg.payload;
    {
    msg.payload = “http://your.local.ip:8123/local/”+file;
    }
    return msg;
    Delay
    I have set it to 15s, but I think it is necessary to modify it and link it to the *.mp3 size
    File Delete
    Path: /config/www
    Filename: msg.payload

    Thanks MrDIY

1 Like

I did have pop sound at the end of mp3 clip, I added 3 seconds silence at the end of the file , and managed to hear the sound very well without pops :slight_smile:

thank you MrDIY

MrDIY,

Kindly if you have (esp8266_mrdiy_mqtt_local_notifier.bin) with (external I2S DAC enabled) instead of (esp8266_mrdiy_mqtt_local_notifier.ino), I have problem compiling the file

Thank you in Advance :slight_smile:

Hi thanks for this great project ! I’ve made some little modifications on it :

  • Ported to platformio
  • Can be compiled for ESP8266 and ESP32
  • Google Translate TTS added (so a little less “cloudless” but multilingual and better voice than the included ESP8266SAM)
  • This code also allows to switch easily between no DAC (version used by mr DIY) , external DAC or internal DAC (for ESP32).
  • You’ll also find some useful comments for wiring your DAC quickly or to improve the code.
  • Support AAC playback (and may be flac) which is useful for online radio :wink:

I still have some bugs related to the compatibility with of the ESP8266Audio library (these bugs are described in the github’s readme, help is welcome :wink: )

1 Like

I have made many updates on the initial project these last days. Please find the list below.
There still a this issue about Google TTS (if a good ESP developper can take a look it would be welcome! :sweat_smile:)
++!

/*******************************************************************************************
"MrDiy Audio Notifier"  
Credits to original source : https://gitlab.com/MrDIYca/mrdiy-audio-notifier
Modified by Schmurtz for Platformio and ESP32 : 

Release Notes (yyyy/mm/dd): 
V0.1 - 2021/12/22 : 
  - Added these comments, pinouts and additionnal DAC settings  
  - Now compatible with platformio  
  - Now compatible wih ESP32
  - Added support for Google Translate TTS  
V0.2 - 2021/12/29 : 
  - fix playing RTTTL & SAM 
  - added aac playback, useful for many radios  
  - added flac playback (working?)  
  - added comments to change the SAMvoice (robot, elf , ET...)  
  - fix errors msg "connect on fd 63, errno: 118, "Host is unreachable""
due to mqtt actions before wifi connects
V0.3 - 2022/01/03 : 
  - Migrate to IotWebConf 3.2.0   (Thanks to markvader) 
V0.4 - 2022/01/08 : 
  - NEW: You can set these options directly in web interface
		(These settings are saved & restored after a reboot)
		 * audio output (no DAC, internal or external DAC), reboot required 
		 * audio volume 
		 * default TTS sam voice style can be set in web interface  
		 * default TTS google voice language can be set in web interface
  - NEW: Firmware update with web interface 
  - NEW: MQTT command feedback msg when a problems are detected (topic "answer")
  - FIX : longer MQTT server name are supported 
  - Breaking change : MQTT TTS commands renamed: samvoice /googlevoice  
  - Less different firmwares + Schmurtz_ESP_Flasher : Windows script for easy flashing  

/*******************************************************************************************```
2 Likes

@MrDIY
Is there a chance, that your feature is getting a component within esphome?
Have you already build something with the amplifier PAM8403 (like you said at 2min20s at your video)?

I build a multisensor just like this one but with an esp32

By the way I use other esp32 with relays (silent solid state relays) and switches to control light and many others (garage door, lawn irrigation, heating control…) and for controlling LED-lights with WLED.

I want to have a multisensor in every room for every possible home automation purpose. One goal is to notify via audio that the door bell was pressed and someone is at the door. I can imagine many other purpose to notify with sound (call the kids to eat). Right now I do that with simple passive buzzer and the Rtttl component of ESPHome (Rtttl Buzzer — ESPHome).

Your approach is great but I need an extra ESP just for this feature. If I could use an ESPHome component I would only need an amplifier and 2 speaker, both very cheap, and my multisensor would have a great and flexible feature.

Why ESP32 and not ESP8266?
Because of Bluetooth. I didn’t test it yet, but from all I have read…

…it should be possible to connect ESP32(-multisensor) not only to HomeAssistant via WiFi but additionally with each other via BLE. So all these ESP32 should work even if my router/WiFi and/or HomeAssistant is damaged.

@MrDIY (is there a better topic than this one?)
Is it possible to combine your Noise Detector with this audio player in one ESP8266 (https://www.youtube.com/watch?v=_D4Go4CFwes). The noise detection just doesn’t work with ESP32, I had numerous sensors (KY-038 / KY-037, MAX9814, MAX4466, INMP441) and I think, the ADC from ESP32 doesn’t work as the one from ESP8266. If your player doesn’t get into ESPHome in time (what I think), so I could use two features in one D1-mini.

Update to version 0.5 :

  • NEW: increase and decrease volume with MQTT commands (+ and -)
  • NEW: increase and decrease volume physical buttons on GPIO 13 and 14
2 Likes

Great work!

1 Like

Thanks to the readme of this repo and this reddit post it is now possible to use MrDIY Notifier with Home Assistant TTS.
It use an atomation which replicate the current audio source from another player to the MrDIY Notifier.
It could be nice to have a real entity media player dedicated to MrDiy Notifier but in the meantime it helps.

alias: Send audio to MrDIY Notifier
description: ''
trigger:
  - platform: state
    entity_id: media_player.GoogleHome
    to: playing
condition: []
action:
  - service: mqtt.publish
    data:
      topic: diy/play
      payload_template: >-
        {{
        states.media_player.GoogleHome.attributes['media_content_id']}}
mode: single
2 Likes

I’m looking for a way to transform MrDiy Notifier into a real Media Player entity in Home Assistant.

After some research, Media_player.template (Community post & Github repo) seems very nice too !

Edit : hass-multiroom-mqtt-mediaplayer github & community post could be an alternative too.

1 Like

Hiya Mr. Schmurtz!

I just wanted to stop by and say thank you for your efforts on this project. I was pointed to your code two days ago by Mr DIY and I just got my I2C circuit up and running. This works really well and I can’t wait to transfer it from breadboard to soldered circuit. I’ll be doing that step next.

I am running version 0.4 and just randomly stumbled upon this post saying you upgrading to 0.5 yesterday! I’ll flash it ASAP.

Thank you and thank you Mr DIY for this project. This was just challenging enough for a beginner like me to Home Automation, Home Assistant, ESP8266 and MQTT to get working. You guys are awesome, keep up the great work

3 Likes

Thanks @HurstOlds , happy to see that someone else than me use it :sweat_smile:
This is typically the best feedback that we could expect when we work on this kind of project :wink:

Good news : you can now declare MrDiy Notififier as media player in Home Assistant so sending TTS to the notifier is even easier.
image

This new feature is in progress, not sure which MQTT media player I will use at the end but for now it’s starting to work with “media-player-template”, see my post about it here (still in progress…).

May be the Notifier status would be easier to retrieve with hass-multiroom-mqtt-mediaplayer or hass-mqtt-mediaplayer… We will see that later …

2 Likes

Edit: I didn’t see your link in the post on how to implement this as a media player. I look thru that and give it a try.

Also, I flashed version 0.5 and reported a bug I’ve been having when trying to use /googlevoice/ commands. I reported the bug over on your github page.

I so far have two of these speakers up and running. One is 0.5 and the other is 0.4. I’ll reflash to 0.5 when I get a chance. I have at least one more I’m looking to assemble this week. The DAC circuit that you provided is awesome. Works really well and there are none of the hiss and pops that my previous circuit had that I built off the original MrDIY schematic.

I’m really enjoying this project. I still have to work on setting up a local HFS style file share for streaming/playing MP3 files on these speakers. I’ll be working on that this week as well. Thank you!!

Yes this is an identified bug. I’ve made a complete answer on your issue on Github. But when you use it like a media player this is a good workaround to use Google TTS without problems :wink:

About the new 0.5 : there is no big difference : it just allow to manage volume in a handier way. I don’t know if you see that : at the bottom of the web UI there’s a link to upload new firmware easily !

1 Like

Version 0.6 released : no more long hang after Google TTS playback. Not totally perfect but a lot better than before :wink:

As a reminder, since version 0.4 you can set the default google TTS language in the web UI or override it directly in your MQTT command :
Bonjour,fr
or
Guten Tag,de-DE

Awesome, I’m going to flash it now.

I have a question about updating firmware, that I haven’t been able to find in any of the readme docs. How do you use the GUI firmware update option? When I click on it, there’s an option to update the firmware, or update the filesystem.

Do I just pick the bin I need and do firmware? You have other files in the firmware folder, are those for updating the filesystem? (boot_app0, partitions.bin, bootloader_qio)

I just went from 0.5 to 0.6 by only flashing the firmware via the GUI and it’s not working correctly. I figured there must be more to it, in terms of updating via the GUI.

Also, as a feature request, do you think you can make the main GUI display which version of the software it’s running? I’m going to have upwards of 5 of these bad boys throughout the house, it’ll help track which firmware is on each one.

For now, to get to 0.6, I’ll just pull it out of my enclosure and flash it manually to see if 0.6 works that way.

Okay, so I had a chance to do some further testing. Looks like just choosing to flash the firmware bin to the unit works for upgrade. sending the /samvoice/ command is what was broken. I posted /samvoice/ as an issue on the github for version 0.6

After some further testing, here is what I’m seeing. I am running two of these speaker notifiers.
Speaker 1 was running firmware 0.4
Speaker 2 was running firmware 0.5

I upgraded speaker 2 to version 0.6 and it works, just samvoice is broken.

I just now upgraded speaker 1 to version 0.6 and there’s a problem running both at version 0.6 This was an issue I saw when running Mr DIY original firmware one more than one speaker. It’s basically created a MQTT storm, where both units keep firing off messages saying they’re idle and connected. When this happens, I can’t send commands to either speaker.

To further test, I downgraded speaker 1 to version 0.5. speaker 2 running version 0.6 and it has the same problem. Both are firing messages non stop via MQTT, causing neither of them to work.

So I stepped speaker 1 back down to version 0.4 . Speaker 2 is running latest 0.6 version, and now both work as expected. I presume version 0.5 introduced an issue that causes multiple notifiers to break.

One further test to confirm:

If both speaker/notifiers are running firmware version 0.4, they both work correctly. No issues with contention and no MQTT storm of broadcasts from the notifiers.