Problem with automation sending a message with text and payload

Hi folks,

back again as I’m learning fast what I want to achive with HA (really great tool).
Problem is that my knowledge at some points is still laking some levels :slight_smile:

First of all, I figured myself out (by reading many examples and documentations), how to read the correct SNMP values from my Windows Server to sensors :upside_down_face:

Now I want to send an automated notification via Telegram, when e.g. percent used disc space is >80%.
Fine, working.
Now I want to know which of my 3 discs firred the automation. Stuck :frowning_face:
Most probably I could use a lengthy 'if elif endif’ structure but I guess this can be done easier.

So, here is my most recent work:

- id: '1575363343504'
  alias: Disc full LRSERVER2
  description: ''
  - above: '80'
    entity_id: sensor.lrserver2_storage_used_percent_disc_c
    platform: numeric_state
  - above: '80'
    entity_id: sensor.lrserver2_storage_used_percent_disc_f
    platform: numeric_state
  - above: '80'
    entity_id: sensor.lrserver2_storage_used_percent_disc_g
    platform: numeric_state
  condition: []
  - data_template:
      message: Disc LRSERVER2 above 80%  {{ trigger.entity_id }}
    service: notify.telegram

If I just send plain text in the message like

 message: Disc LRSERVER2 above 80%

everything is working fine.

When using the {{ entity_id }} in the message I get this error in the log.

Error sending message: Can't parse entities: can't find end of the entity starting at byte offset 74. Args: (999047806, 'Disc LRSERVER2 above 80%  sensor.lrserver2_storage_used_percent_disc_g'), kwargs: {'parse_mode': 'Markdown', 'disable_notification': False, 'disable_web_page_preview': None, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}

I’ve tried various options of brackets, quotes etc. (like in Automation Templating automation 2) but no success.

Who might shed some more light on my miserable life :joy:

Thanks upfront to these great people that monitor all us noobs and help so fast, like you did with me in the past days.


Did you try:

{{ trigger.to_state.entity_id }}

Hmmm, same result.

The text that has to be sent is already correct in the error log

'Disc LRSERVER2 above 80% sensor.lrserver2_storage_used_percent_disc_g'

Maybe the message is just too long??

Ok I just read that there seems to be a issue with underscore character in telegram notification.

Could you try this:

  - data_template: >
      message: >
        Disc LRSERVER2 above 80%  {{ trigger.entity_id | replace('_','-') }}
    service: notify.telegram

Or this if the friendly name of the device doesn’t contain any underscore:

  - data_template: >
      message: >
        Disc LRSERVER2 above 80%  {{ }}
    service: notify.telegram

BINGO, that was tricky.

Maybe it would be easier to just send the last character of that entity_id string along with the static text.
Unfortunaltey I have no idea how to do something like (right (in_string ,1)) to get only the rightmost character in HA.

Does {{ trigger.entity_id[-1] }} work?

It needs to be

{{ trigger.entity_id[-1] }}

without β€œ:”, your code will cut-off the rightmost character

More info can be found here:

1 Like

Or the friendly name (if the sensors have one).

Yeah, I thought I fixed it before anyone saw. LOL.

Always my preference

1 Like

Thanks again,

all three versions work!

Will keep them as reference in my automation.yaml for future use.

You can’t stop learning one new thing every day :slight_smile:

1 Like