I am trying to get the entity_id which triggered an automation and send it with telegram.
With {{trigger.entity_id}} I get a telegram message but at the line where the entity_id should be there is just an empty line, no error entry in the log.
The message I get:
Kitchen LED Light
[emoji light_bulb] ON
2018-11-14 26:52:45
That is quite odd, and might be an issue. I have a similar issue where I want to parse the entity ID and pull a number from the name based on the underscores. This may be my issue.
{% if trigger.entity_id == 'light.kitchen_node_1_led_light_1' %}
7: with underscore
{% endif %}
sends: 7: with underscore
Not working:
{% if trigger.entity_id == 'light.kitchennode1ledlight1' %}
7: without underscore
{% endif %}
sends an empty line
When I use trigger.from_state.entity_id instead of trigger.entity_id the same happens.
Telegram callback:
I am also using telegram callback, same thing here:
The callback is waiting to receive : /dafang_1_get_1_snapshot
in message {{trigger.event.data.data}} telegram sends /dafang1get1snapshot
Works:
{% if trigger.event.data.data == '/dafang_1_get_1_snapshot' %}
with underscore
{% endif %}
sends: with underscore
Not working:
{% if trigger.event.data.data == '/dafang1get2snapshots' %}
without underscore
{% endif %}
sends an empty line
In summary:
{{trigger.to_state.entity_id}} sends light.kitchennode1ledlight1,it removes the underscores when sent as a telegram message.
trigger.entity_id is working when used in an if but not when I want to send it as a telegram message with {{trigger.entity_id}}
entity_id is always sent without an underscore, but when you want to use it in an if statement you have to use underscore in order to get a true if statement.
___Working: {% if trigger.entity_id == 'light.kitchen_node_1_led_light_1' %} Not working: {% if trigger.entity_id == 'light.kitchennode1ledlight1' %}
___Working: {% if trigger.from_state.entity_id == 'light.kitchen_node_1_led_light_1' %} Not working:{% if trigger.from_state.entity_id == 'light.kitchennode1ledlight1' %}
___Working: {% if trigger.event.data.data == '/dafang_1_get_1_snapshot' %} Not working: {% if trigger.event.data.data == '/dafang1get2snapshots' %}
I’m having a weird issue with entity ID though, even though it seems like it should work. Rather than retype, I’ll just link my post here in case anyone has any ideas or recommendations. At this point I’m about to give up and just do a long if elif statement, which would be a bit annoying.
-not working
Error: Error sending message: Can't parse entities: can't find end of the entity starting at byte offset 27. Args: (373476846, 'Kitchen LED Light\n⚫ OFF _'), kwargs: {'parse_mode': 'Markdown', 'disable_notification': False, 'disable_web_page_preview': None, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}b
byte offset 27 is the underscore.
{{ '_' }}not working
No double quotes because it use them around the whole message.
Error: Can't parse entities: can't find end of the entity starting at byte offset 27. Args: (373476846, 'Kitchen LED Light\n⚫ OFF _'), kwargs: {'parse_mode': 'Markdown', 'disable_notification': False, 'disable_web_page_preview': None, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}
It might be a problem with the telegram component or telegram itself.
So I’m guessing underscores mean something in markdown for telegram.
@naitsimp, that’s why your entity id’s are getting changed, and its on telegrams side. So the underscores are actually there, it’s just that markdown is suppressing them.
EDIT: FYI I debugged into telegram and it does not doctor your messages. It just passes them through. So this is 100% on the telegram side.
Can you show an example of how the automation should look using parse_mode? I haven’t seen that used before. See my automation below. Whenever someone isn’t home, their state is returned as not_home and it causes the automation to error out.