Working Automation with Telegram Errors

As the topic states, I have an automation that once triggered sends a picture via telegram, the automation triggers, picture gets sent, but I notice the following error in the log repeated multiple times.

2018-03-07 12:01:05 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback SendfilePayloadWriter._sendfile_cb(<Future cancelled>, 47, 40, 856680, 1473296, <_UnixSelecto...e debug=False>, True)
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
    self._callback(*self._args)
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_fileresponse.py", line 38, in _sendfile_cb
    loop.remove_writer(out_fd)
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 351, in remove_writer
    self._ensure_fd_no_transport(fd)
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 258, in _ensure_fd_no_transport
    fd, transport))
RuntimeError: File descriptor 47 is used by transport <_SelectorSocketTransport fd=47 read=polling write=<polling, bufsize=0>>

Can anyone provide some insight?

Automation:

  - alias: Living Room Motion
    trigger:
    - platform: state
      to: 'on'
      entity_id: binary_sensor.living_room_sensor_motion
    action:
    - service: script.living_room
    - service: notify.telegram
      data:
        title: Living Room Alert!
        message: Someone is in the house.
        data:
          photo:
            - file: /home/homeassistant/.homeassistant/cameraimages/living_room.jpg

I also notice on the receiving side, there is no title or message, just the picture, is this normal behavior when sending photo?

Thanks

90% sure action can only have 1 service. Could be the cause of the issue.

Well, I think the other 10% just out-ruled you, the both service run, and execute as expected, but could still be causing it to through the error.

Any idea how I can trouble shoot?

There is also examples in the docs that show the use of multiple service.

Automation Actions:

  action:
    # Actions are scripts so can also be a list of actions
    - service: notify.notify
      data:
        message: Beautiful sunset!
    - delay: 0:35
    - service: notify.notify
      data:
        message: Oh wow you really missed something great.

Have you tried using debug for the logger? This error could be unrelated to your automation.

Good to know, Iā€™ve always wanted to do that but created a script for it. I donā€™t know why that isnā€™t covered under the normal automation sectionā€¦ Seems like the docs are too segmented.

Itā€™s ironic, I rebooted just after my initial post and the error hasnā€™t showed up since, but i have seen the same error some time ago prior to this, I will debug and report back.

Thanks.

Automation just ran and was succesfull, but got the following error:

2018-03-07 14:46:06 ERROR (Thread-11) [homeassistant.components.telegram_bot] Error sending file: Timed out. Args: (390135429, <_io.BufferedReader name='/home/homeassistant/.homeassistant/cameraimages/living_room.jpg'>), kwargs: {'parse_mode': 'Markdown', 'reply_markup': None, 'disable_notification': False, 'timeout': None, 'caption': None, 'reply_to_message_id': None, 'disable_web_page_preview': None}

Still strugling to resolve the Telegram errors, error is created when any automation using Telegram is triggered.

Anyone have any idea how I can diagnose this error, or what needs to be changed/added?

2018-04-16 22:17:48 ERROR (Thread-10) [homeassistant.components.telegram_bot] Error sending message: Invalid server response. Args: (390135429, 'Pi3 CPU temperature is currently 128.6Ā°!'), kwargs: {'parse_mode': 'Markdown', 'timeout': None, 'reply_markup': None, 'disable_notification': False, 'reply_to_message_id': None, 'disable_web_page_preview': None}

So i must have missed your response a month ago.

Looks like its a bug in the telegram component. This is basically saying that the response from telegram is crap. There may be nothing you can do.

For some reason, the component doesnā€™t like the arguments or keyword arguments. The component must be looking for a specific number of arguments or a specific keyword argument that is missing.

Youā€™re only options are to debug the component and find out why it doesnā€™t like the arguments or keyword arguments.

@petro Thank you for following up.

After commenting, I did some reading on your postā€™s and recomendationā€™s, and ended up adding parse_mode: html which seems to be keeping it quite for the moment, will update on any changes.

Thanks.

telegram_bot:
  - platform: polling
    api_key: !secret telegram_api_key
    allowed_chat_ids:
      - !secret telegram_chat_id
    parse_mode: html

Hmm, maybe it was returning a string instead of the actual objects needed. I did find it odd that ā€˜Argsā€™ was capitalized. This leads me to believe that they printed a string and assumed it was a sentence and capitalized the first letter of the string. This is all conjecture though.

I was thinking it was expecting more unspecified info which i should provide, but didnā€™t know how.

I was also getting 502 errrors.

Talked too soon.

Still getting errorā€™s when sending image:

2018-04-17 10:40:53 ERROR (Thread-10) [homeassistant.components.telegram_bot] Error sending file: Timed out. Args: (390135429, <_io.BufferedReader name='/home/homeassistant/.homeassistant/cameraimages/frontdoor.jpg'>), kwargs: {'parse_mode': 'HTML', 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None, 'disable_web_page_preview': None, 'disable_notification': False, 'caption': None}

Thatā€™s a different error. That could be a connection issue.

Connection to the Bot?

Error looks similar, but for a different Automation.

2018-04-16 22:17:48 ERROR (Thread-10) [homeassistant.components.telegram_bot] Error sending message: Invalid server response. Args: (390135429,

2018-04-17 10:40:53 ERROR (Thread-10) [homeassistant.components.telegram_bot] Error sending file: Timed out. Args: (390135429,

The confusing part is that the message is sent and received with the image.

Well, the meat of the errors is here:

Error sending message: Invalid server response

and here:

Error sending file: Timed out.

I found the second error in the source file. Are you getting a debug message ā€œLast message ID: ā€¦ā€ before any these errors?

or ā€œUpdate last message: ā€¦ā€

I will set to debug and re-run automations

Itā€™s probably not worth it. I debugged down all the way to the errors and their meaning and both point to connection issues. Both errors inherit from NetworkError.

To what/where?

To the telegram bot Iā€™m guessing. I have no idea what this device is. If its internal to your network, then you are having network issues. If its external from your network, then itā€™s having trouble sending or receiving a ā€˜confirmationā€™ from the send.

I just looked it up, its a cloud based service. So most likely, your network isnā€™t routing the telegram bot responses back to HA properly. This may be caused by your router/network configuration.