Telegram notifications don't work

Telegram notifications not working. Notify configuration as follows:

notify:
   - platform: telegram
     api_key: api_key
     chat_id: chat_id
     name: telegram_bot

Testing using the frontend developer tools (Testing section of: https://home-assistant.io/components/notify/). Frontend claims to successfully call service, but I am not actually receiving any notifications on telegram. Terminal trace as follows:

INFO:homeassistant.components.http:Serving /api/services/notify/telegram_bot to 192.168.2.64 (auth: True)
INFO:homeassistant.core:Bus:Handling <Event call_service[L]: service=telegram_bot, service_call_id=1979007536-4, domain=notify, service_data=message=The sun is {% if is_state('sun.sun', 'above_horizon') %}up{% else %}down{% endif %}!>
ERROR:homeassistant.core:Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 1054, in execute_service
    service_handler.func(service_call)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/notify/__init__.py", line 110, in notify_message
    notify_service.send_message(**kwargs)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/notify/telegram.py", line 122, in send_message
    parse_mode=parse_mode)
  File "/home/pi/.homeassistant/deps/telegram/bot.py", line 125, in decorator
    result = func(self, *args, **kwargs)
  File "/home/pi/.homeassistant/deps/telegram/bot.py", line 151, in decorator
    result = self._request.post(url, data, timeout=kwargs.get('timeout'))
  File "/home/pi/.homeassistant/deps/telegram/utils/request.py", line 207, in post
    **urlopen_kwargs)
  File "/home/pi/.homeassistant/deps/telegram/utils/request.py", line 132, in _request_wrapper
    resp = self._con_pool.request(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 72, in request
    **urlopen_kw)
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 135, in request_encode_body
    **urlopen_kw)
TypeError: urlopen() got multiple values for keyword argument 'body'
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=sun.sun, old_state=<state sun.sun=above_horizon; next_setting=2016-12-30T15:58:28+00:00, azimuth=221.86, next_rising=2016-12-31T08:06:12+00:00, friendly_name=Sun, elevation=5.09 @ 2016-12-30T14:55:17.490240+00:00>, new_state=<state sun.sun=above_horizon; next_setting=2016-12-30T15:58:28+00:00, azimuth=222.07, next_rising=2016-12-31T08:06:12+00:00, friendly_name=Sun, elevation=4.99 @ 2016-12-30T14:55:17.490240+00:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=sun.sun, old_state=<state sun.sun=above_horizon; next_setting=2016-12-30T15:58:28+00:00, azimuth=222.07, next_rising=2016-12-31T08:06:12+00:00, friendly_name=Sun, elevation=4.99 @ 2016-12-30T14:55:17.490240+00:00>, new_state=<state sun.sun=above_horizon; next_setting=2016-12-30T15:58:28+00:00, azimuth=222.27, next_rising=2016-12-31T08:06:12+00:00, friendly_name=Sun, elevation=4.89 @ 2016-12-30T14:55:17.490240+00:00>>

I’ve double checked all credentials, and the terminal doesn’t complain about anything not being authorised…

Can you post whatever script or automation is calling Telegram to do the notification? I don’t use Telegram, but this error makes me think it might be in the formatting of the notification itself.

I’m doing exactly as described in the notifications ‘Test if it works’ section:

“A simple way to test if you have set up your notify platform correctly is to use service developer tool icon Services from the Developer Tools. Choose your service (notify/xyz) from the list of Available services: and enter something like the sample below into the Service Data field and hit CALL SERVICE.”

{
  "message": "The sun is {% if is_state('sun.sun', 'above_horizon') %}up{% else %}down{% endif %}!"
}

Thank you for your help!

Well we can rule out the test as I just ran it with pushbullet and it worked fine on my end. Everything sent and the sun condition sent was correct as well.

I looked at all the telegram threads I could find and didn’t see anything related.

Can you try again, using another sensor for your example? I’m just wildly guessing now, but could it be that the time you called the test, the sun was moving fast enough that during the call, the azimuth changed leaving HA with two values when telegram was only expecting one?

It’s a wild guess though as when I put your template in the dev-template checker, it gives me the proper value of “up” without any errors.

Same result, I removed all of the conditions and just changed the data to:

{
  "message": "The sun is down!"
}

Which gives basically the same trace:

INFO:homeassistant.components.http:Serving /api/services/notify/telegram_bot to 192.168.2.64 (auth: True)
INFO:homeassistant.core:Bus:Handling <Event call_service[L]: service_call_id=1979232816-3, domain=notify, service_data=message=The sun is down!, service=telegram_bot>
ERROR:homeassistant.core:Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 1054, in execute_service
    service_handler.func(service_call)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/notify/__init__.py", line 110, in notify_message
    notify_service.send_message(**kwargs)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/notify/telegram.py", line 122, in send_message
    parse_mode=parse_mode)
  File "/home/pi/.homeassistant/deps/telegram/bot.py", line 125, in decorator
    result = func(self, *args, **kwargs)
  File "/home/pi/.homeassistant/deps/telegram/bot.py", line 151, in decorator
    result = self._request.post(url, data, timeout=kwargs.get('timeout'))
  File "/home/pi/.homeassistant/deps/telegram/utils/request.py", line 207, in post
    **urlopen_kwargs)
  File "/home/pi/.homeassistant/deps/telegram/utils/request.py", line 132, in _request_wrapper
    resp = self._con_pool.request(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 72, in request
    **urlopen_kw)
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 135, in request_encode_body
    **urlopen_kw)
TypeError: urlopen() got multiple values for keyword argument 'body'
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=<state sun.sun=below_horizon; elevation=-6.31, azimuth=240.28, next_rising=2016-12-31T08:06:12+00:00, friendly_name=Sun, next_setting=2016-12-31T15:59:28+00:00 @ 2016-12-30T16:40:01.176460+00:00>, new_state=<state sun.sun=below_horizon; elevation=-6.45, azimuth=240.47, next_rising=2016-12-31T08:06:12+00:00, friendly_name=Sun, next_setting=2016-12-31T15:59:28+00:00 @ 2016-12-30T16:40:01.176460+00:00>, entity_id=sun.sun>

Thanks again for your help. I really have no idea why it’s not working :confused:

Me either. Even looked at pull requests and issues. I’m assuming you are using the latest build, if not please try updating as there was a commit for telegram in the last version here:

Beyond that, I can only suggest trying the HA Github chatroom. A lot of devs hang out there and may be better equipped to figure out what’s going on.

https://gitter.im/home-assistant/home-assistant

Sorry I couldn’t be of more help.

Yes, I’m using the latest. I’ll take a look, thanks.

No, you’ve been a great help, really. Thanks :slight_smile:

@alexhalford did you ever get this resolved? I am having the exact same issue.

I had the same issue. But after updating to the latest version 0.39.1, it works for me!