Hi,
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:
- Python Telegram Bot to listen to and download incoming messages
- Small HTTP server to make those messages available to your home mediaplayers
- 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
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.