Playback Telegram Voice messages using HA

I wanted to be able to playback voice messages at home when im on the go. Telegram with its open API seemed to be the best way for this and there allready is a component available for it.
But the current implementations dont support this as far as i could see so i created my own little python script to accomplish this.

I would love to create a true ha component for this in the future but at the moment it is a standalone application and you probably need a seperate telegram bot if you are using a telegram component for other stuff at the moment.

This python program has 3 main components:

  1. Python Telegram Bot to listen to and download incoming messages
  2. Small HTTP server to make those messages available to your home mediaplayers
  3. MQTT client to publish the info that a new message has arrived

So when a voice message is incoming for from a known/allowed user the voice message will be downloaded and made available through the webserver. It then sends a MQTT payload out with the necessary information:
Type: Text or Voice (atm)
User: From which telegram user
Contant: content of the messagt (text) or url for the mediafile (ogg, for voice messages).

The program has a built in queue, so for example if you send a 20 seconds long message and right after that short one it will fire the mqtt publish for the second message 21 seconds later, so the mediaplayer will have time to playback the first one.
Maybe there is a way for this in HA, but i couldnt find it :wink:

You can find everything on this github page:

There is a Dockerfile available to build your own container. The program requires in config.yaml file inside a “conf” folder with the configuration options, so you should map the /opt/tele2mqtt/conf folder of your container to a outside place.

To integrate everything into HA you can take this as an example:

This is a proof of concept atm but it is working quite well for me at home.

I also want to add more features to this in the future (Audio besides voice), scheduling messages (wakeup message for my girlfriend) and im not 100% sure about the current communication with HA using json payloads and sensors.

But maybe someone else was looking for something like this and wants to try it.


Nice! I had this working when I was using Domoticz, so definitely going to take a look at it :grinning:

Just wondering if the voice files can’t be placed in the /config/www folder instead of a separate HTTP server?

Thanks for the feedback.
Yeahr your right, if you run this on the same machine as HA you really dont need the webserver.
I wrote this on my computer and for testing it was necessary to have a webserver on this.

Will add the Option to ditch this and specifiy your ha/www directory in the config files.

Some how posted on wrong thread. Mobile browser issues I guess.

I have this running with the minimal python config. I too think its a bit much for such a small script but its the cleanest way to run this on my server where all the HA stuff is in seperate containers. This should not really ask for much cpu/ram usage. If you map the conf folder to a outside location you can easily change the settings.

I will upload a new version soon with an option to use a different location for file downloads (HA WWW directory for example) and disable the builtin webserver. Better Instructions coming soon as well.
I also plan to upload a findished docker build so you dont have to build it yourself.


To whoever tries this in 2021 and later:
In the Dockerfile add a particular version of python-telegram-bot that was actual at the time of creation.
I.e. your line #4 should look like this:

RUN pip install paho-mqtt python-telegram-bot==10.1.0 pyyaml