2017-06-29 15:02:39 ERROR (Thread-8) [homeassistant.components.telegram_bot] Error sending message
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/telegram_bot/__init__.py", line 414, in _send_msg
out = func_send(*args_rep, **kwargs_rep)
File "/home/homeassistant/.homeassistant/deps/telegram/bot.py", line 125, in decorator
result = func(self, *args, **kwargs)
File "/home/homeassistant/.homeassistant/deps/telegram/bot.py", line 158, in decorator
return Bot._message_wrapper(self, url, data, *args, **kwargs)
File "/home/homeassistant/.homeassistant/deps/telegram/bot.py", line 146, in _message_wrapper
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
File "/home/homeassistant/.homeassistant/deps/telegram/utils/request.py", line 252, in post
**urlopen_kwargs)
File "/home/homeassistant/.homeassistant/deps/telegram/utils/request.py", line 194, in _request_wrapper
raise BadRequest(message)
telegram.error.BadRequest: Can't parse entities in message text: can't find end of the entity starting at byte offset 24
When I do this I don’t have a problem and receive the message so it must be something in the variables:
It only happens if that device is not home. If I’m home it gets the status and sends it to. I think it’s something to do with the underscore in ‘not_home’, I was going to try and get the template to change not_home to ‘away’ and see if that fixes it, but I haven’t had chance.
I use “data” and not “data_template” and everything works fine as expected
action:
- service: notify.telegram
data:
message: "{% if is_state('device_tracker.oneplus_thomas', 'home') %} Thomas is at home.\n{% else %} Thomas is away.\n{% endif %}
{% if is_state('device_tracker.s4mini_maud', 'home') %} Maud is at home.\n\n{% else %} Maud is away.\n\n{% endif %}
Plafonnier is {{ states.light.plafonnier.state}} (/plafonnier)\n"
Like @anon43302295 says, it probably is a result of the parse mode, which is trying to make italic text out of bla.foo_bar, where the enclosing _ is missing. The number of _'s always has to be even.
I worked around that problem by setting the notifiers parse_mode option to html. Have a look at the polling or webhook documentation (depending on which one you use) and set the parse_mode to html. That way not_home won’t be a problem anymore.
Thanks, that was it! If I take a closer look at the message I can see the italic font. After setting the parse_mode to html it’s gone.
Now the next problem is this:
When the automation is executed I get the message in pushbullet with all the correct data in it.
Fot Telegram I have this in the log:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 101, in async_render
return self._compiled.render(kwargs).strip()
File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/sandbox.py", line 385, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'trigger' is undefined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
result = next(coro)
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 1021, in _event_to_service_call
yield from service_handler.func(service_call)
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/notify/__init__.py", line 125, in async_notify_message
kwargs[ATTR_TITLE] = title.async_render()
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 103, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'trigger' is undefined
It looks like I can’t get a variable from the trigger part.
So I need that for Telegram but not for pushbullet?
Take a look at the code. If this automation is triggered I don’t have the message in Telegram but the Pushbullet works fine. So I don’t need the to/from.