Thanks man. It works like a charm.
I am sorry. I am totally new to this. May I know where do you save the script and what do you add into /etc/rc.local?
I manage to make the telebot to autostart using systemd similar to what I did for Home Assistant.
-
sudo pico /lib/systemd/system/[email protected]
-
Copy and paste the following into the file…
[Unit]
Description=Home Assistant Telegram Bot
After=network.target[Service]
Type=simple
User=%i
ExecStart=/home/pi/hass-telebot/hass-telebot.py /home/pi/hass-telebot/hass-telebot.cfg[Install]
WantedBy=multi-user.target -
Exit and save.
-
sudo systemctl --system daemon-reload
-
sudo systemctl enable ha-telebot@pi
-
sudo systemctl start ha-telebot@pi
-
sudo reboot
If you make any changes to hass-telebot.py file, you need to sudo systemctl restart ha-telebot@pi
before your changes are effective.
I am beginning to modify the hass-telebot.py file and manage to create some pretty cool interactions. However, I need some helps on customizing the some aspect of the bot. I have searched the documentations from telegram and telepot website but it seems way too advance for my understanding.
Currently I have a chat group consisting of my family members and the bot. My questions are…
- When any of the members send this command
/menu
, the custom keyboard will appear on every members phone. Is there anyway to make the keyboard appear only on the member’s phone who issued the command? - How do I make the bot to response differently base on who issued the command? For example, when member A send
/menu
to the chat group, he will be served with a keyboard made specifically for him. When other members send the same command, they will receive different type of keyboard.
If anyone knows the answer, please help. Thanks.
It’s awesome!!!
Thanks for the project!
From Uruguay,
Andrés.
Sorry kinda left this for a bit, as myself and a couple of others started working on a more generic bot framework we could use to add bots to for various chat services.
I need to go find out where that got to
@Soul
Able to share any code on this new project ? I was looking at improving/adapting what you shared here, but if it is to be replaced soon with something fancier I’d love to collaborate !
You have any news on that?
I’m interested in knowing.
I am wondering is it possible to use voice message to send command to the telebot? Maybe using some STT engine to convert the audio to text for use in the Telebot.
I managed to do a custom component of the telebot.
Have a look here:
Who knows it might become a component in hass itself.
thanks for sharing this. looks amazing. However, I have few questions/suggestions…
- I am wondering is it possible to have separate commands for different chat IDs? For example I only want User1 to have access to certain commands and User2 to have different set of commands. This is to restrict what a user can do like switch on/off lights in common areas but not in other user’s room.
- Can a command be normal text like “switch off living room lights” or “what is the temperature in bedroom”?
- If yes, can it understand it loosely or other variations such as “turn off lights in living room” or “what is bedroom’s temperature”. The idea is to have a normal conversation with the bot but it still understand me.
- Can the keyboard arrange in other arrangement like the buttons align in 2 or 3 columns?
Currently not possible. Shouldn’t be too hard to implement though…
That would be totally awesome, but unfortunately I have no idea how to do that. I guess you’ll have to dive in python nltk toolkit…
Don’t know. I’ll look into that… (together with the user id refinements…)
I am having all the above features by customizing the python script from https://github.com/GussyH/hass-telebot.
However, I feel that your approach is much cleaner and proper. I really like to set up a Telegram bot as a component and configure it in HA.
Right now, my script is really messy and hard to customize and grow.
For the natural language command, I use something like this…
if command == 'how is the weather' or (('how' in command or 'what' in command) and ('weather' in command or 'forecast' in command)):
Doesn’t work yet, but I guess that could be done by doing the following (adding a list of possible keyword combinations.):
hass_telepot:
bot_token: !secret telepot_api_key
allowed_chat_ids: !secret telepot_chat_id
commands:
- keywords:
- how is the weather
- how, weather
- how, forecast
- what, weather
- what, forecast
script:
service: input_boolean.turn_on
entity_id: input_boolean.away
Good idea. Maybe you can make it like nested conditions…
hass_telepot:
bot_token: !secret telepot_api_key
allowed_chat_ids: !secret telepot_chat_id
commands:
keyword: or
- keywords: 'how is the weather'
- keywords:
- keyword: and
keywords:
- keyword: or
keywords:
- 'how'
- 'what'
- keyword: or
keywords:
- 'weather'
- 'forecast'
script:
service: input_boolean.turn_on
entity_id: input_boolean.away
Though I don’t like the whole nesting of keywords it is more in line with the hass way of doing things…
So you’re probably right doing like you suggested… I look into it. Not tonight though.
I am already happy that you looked into my suggestions. Thank you so much.
@masterkenobi if you want to talk to your hass using natural language, you should definitely take a look to api.ai and similar services. Even more so hass 0.38 has official support for api.ai https://home-assistant.io/components/apiai/. I did not checked new component by myself but playing with api.ai service recently and found it really interesting.
There is also Tasker plugin Autovoice which is now supports api.ai which you could use to send arbitrary commands anywhere from Android device.
That looks nice! But it requires your hass instance to be exposed to the Internet. I did try to enable that in the past, but failed, and actually don’t like doing it for potential safety issues. I did make this telegram component to somehow be able to talk to hass without having to do the above… So for me it makes little sense for me doing it now.
Ps. There is also “telegram webhook” component being released. But this also requires hass to be exposed.