Telegram will not work

Hi Hass’s friends, I’ve been trying telegram polling for several days, but I do not want to go … I do not know what to do for you to ask for help … here is my configuration.yaml, Id and Api keys are correct.

indent preformatted text by 4 spaces
#TELEGRAM
telegram_bot:
  - platform: polling
    api_key: AAHna1pbxxxxVplTgrrYlyQCf4Eb_VV4zuU
    allowed_chat_ids:
      - 347xxx731

#NOTIFIER
notify:
  - name: telegram
    platform: telegram
    api_key: AAHna1pbqlt2VplTgrrYlyQCf4Eb_VV4zuU
    chat_id: 347387731

In check validate, if checked ok but in home assistant log:
indent preformatted text by 4 spaces
2017-11-16 21:37:35 ERROR (MainThread) [homeassistant.components.telegram_bot] Error setting up platform polling
Traceback (most recent call last):
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/telegram_bot/init.py”, line 232, in async_setup
platform.async_setup_platform(hass, p_config)
File “/usr/lib/python3.5/asyncio/coroutines.py”, line 210, in coro
res = func(*args, **kw)
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/telegram_bot/polling.py”, line 31, in async_setup_platform
bot = telegram.Bot(config[CONF_API_KEY])
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/telegram/bot.py”, line 105, in init
self.token = self._validate_token(token)
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/telegram/bot.py”, line 131, in _validate_token
raise InvalidToken()
telegram.error.InvalidToken: Invalid token
2017-11-16 21:37:35 ERROR (MainThread) [homeassistant.setup] Setup failed for telegram_bot: Component failed to initialize.
2017-11-16 21:37:35 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of notify.telegram. Setup failed for dependencies: telegram_bot
2017-11-16 21:37:35 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform notify.telegram: Could not setup all dependencies.
2017-11-16 21:37:35 ERROR (MainThread) [homeassistant.components.notify] Unknown notification service specified
2017-11-16 21:37:36 ERROR (Thread-14) [homeassistant.util.yaml] YAML file /home/homeassistant/.homeassistant/known_devices.yaml contains duplicate key “icon”. Check lines 132 and 136.
2017-11-16 21:37:45 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.
2017-11-16 21:40:19 WARNING (MainThread) [homeassistant.components.device_tracker] Updating device list from nmap_tracker took longer than the scheduled scan interval 0:00:10
2017-11-16 21:42:09 WARNING (MainThread) [homeassistant.components.device_tracker] Updating device list from nmap_tracker took longer than the scheduled scan interval 0:00:10

where am I wrong???
Thanks.

Try comment out api_key from notify. Also you shouldn’t post your api key with you chat id… you might find strange messages turning up in the middle of the night

I did not understand what I have to do?

Try this

#NOTIFIER
notify:
  - name: telegram
    platform: telegram
#    api_key: AAHna1pbqlt2VplTgrrYlyQCf4Eb_VV4zuU
    chat_id: 347387731

not work :disappointed:

indent preformatted text by 4 spaces

2017-11-16 22:40:13 ERROR (Thread-13) [homeassistant.util.yaml] YAML file /home/homeassistant/.homeassistant/known_devices.yaml contains duplicate key “icon”. Check lines 132 and 136.
2017-11-16 22:40:14 ERROR (MainThread) [homeassistant.components.telegram_bot] Error setting up platform polling
Traceback (most recent call last):
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/telegram_bot/init.py”, line 232, in async_setup
platform.async_setup_platform(hass, p_config)
File “/usr/lib/python3.5/asyncio/coroutines.py”, line 210, in coro
res = func(*args, **kw)
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/telegram_bot/polling.py”, line 31, in async_setup_platform
bot = telegram.Bot(config[CONF_API_KEY])
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/telegram/bot.py”, line 105, in init
self.token = self._validate_token(token)
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/telegram/bot.py”, line 131, in _validate_token
raise InvalidToken()
telegram.error.InvalidToken: Invalid token
2017-11-16 22:40:14 ERROR (MainThread) [homeassistant.setup] Setup failed for telegram_bot: Component failed to initialize.
2017-11-16 22:40:14 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of notify.telegram. Setup failed for dependencies: telegram_bot
2017-11-16 22:40:14 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform notify.telegram: Could not setup all dependencies.
2017-11-16 22:40:14 ERROR (MainThread) [homeassistant.components.notify] Unknown notification service specified
2017-11-16 22:40:22 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.

Your api key is wrong. There are meant to be more numbers in front of it. It should be something like
api_key: xxxxxxxx:AAHna1pbqlt2VplTgrrYlyQCf4Eb_VV4zuU

i generate a new token.
Paste from botfather:
BotFather:
You can use this token to access HTTP API:
4xxxxxxx7:AAFeu-_Uh6-DYbxySVyFNwdopDZVud7XyXk

For a description of the Bot API, see this page: https://core.telegram.org/bots/api

http ???

Set this as your api_key
api_key: 4xxxxxxx7:AAFeu-_Uh6-DYbxySVyFNwdopDZVud7XyXk

Ok, no errors will appear… hass log: ok no errors
how do i test it?

ok work fine!!!
Ty very much!!! i’ m so happy!!!

Good to hear you got it working

1 Like

I am also having trouble booting up telegram… I’m just trying to use the platform for the first time on Home Assistant 0.58.

I’ve got the API key and chat ID from Telegram and the config seems pretty straight forward…

telegram_bot:
  - platform: polling
    api_key: 4.......9:A.................................o
    allowed_chat_ids:
      - 4.......1

notify:
  - name: telegram
    platform: telegram
    chat_id: 4.......1

However, telegram fails to initialize and I’m seeing this in the log…

INFO (MainThread) [homeassistant.loader] Loaded notify.telegram from homeassistant.components.notify.telegram
INFO (MainThread) [homeassistant.loader] Loaded telegram_bot from homeassistant.components.telegram_bot
INFO (MainThread) [homeassistant.loader] Loaded telegram_bot.polling from homeassistant.components.telegram_bot.polling
INFO (MainThread) [homeassistant.setup] Setting up telegram_bot
INFO (MainThread) [homeassistant.components.telegram_bot] Setting up telegram_bot.polling
ERROR (MainThread) [homeassistant.components.telegram_bot] Error setting up platform polling
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/telegram_bot/__init__.py", line 234, in async_setup
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/telegram_bot/polling.py", line 38, in async_setup_platform
    import telegram
  File "/Users/broox/.homeassistant/deps/lib/python/site-packages/telegram/__init__.py", line 45, in <module>
  File "/Users/broox/.homeassistant/deps/lib/python/site-packages/telegram/files/file.py", line 22, in <module>
INFO (MainThread) [homeassistant.setup] Setup of domain telegram_bot took 7.9 seconds.
ERROR (MainThread) [homeassistant.setup] Setup failed for telegram_bot: Component failed to initialize.
 - [telegram-bot](https://home-assistant.io/components/telegram_bot/)
 - [telegram-bot](https://home-assistant.io/components/telegram_bot/)
ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of notify.telegram. Setup failed for dependencies: telegram_bot
ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform notify.telegram: Could not setup all dependencies.
 - [telegram-bot](https://home-assistant.io/components/telegram_bot/)
 - notify.telegram
 - [telegram-bot](https://home-assistant.io/components/telegram_bot/)
 - [telegram-bot](https://home-assistant.io/components/telegram_bot/)
 - notify.telegram

The issue with mine was that I had a test.py file in my .homeassistant directory that had a syntax error in it… Apparently telegram loads up every file in your home-assistant directory and if anything in there has errors, it will blow up the telegram initialization.

heh.

Thank you SO much for posting your solution, @broox! I just ran into the same problem after Telegram had been working flawlessly for a long while. Out of nowhere, a restart of hassio produced these failure errors.

The problem for me ended up being that I needed some extra things quoted in my customize-glob.yaml file. The crazy part is that the configuration validation said all was well with no errors in the log. I guess the Telegram component is rather touchy, like you said. :exploding_head: