Using template and secrets to pass telegram chat id fails

Hi,

I’m having a problem to pass telegram chat id to my script. The idea is to take name from input_select and build a string that matches to one in secrets. Pass this to telegram to send messages. But does not seem to work.

Here’s the data:
script

search_selected_phone:
  sequence:
  - service: telegram_bot.send_message
    data_template:
      # below line does not work
      target: !secret telegram_chat_id_{{states("input_select.lost_phones").lower()}}
      # below line works 
      # target: !secret telegram_chat_id_juha #{{states("input_select.lost_phones").lower()}}
      title: 'Searching phone'

secrets

telegram_chat_id_juha: '123456'
telegram_chat_id_tiina: '654321'

input select

input_select:
  lost_phones:
    name: Phone to search
    options:
     - Tiina
     - Juha

I tried putting quotes to varying places around {{ }} and the whole thing. No positive results.

Error i get

ERROR (MainThread) [homeassistant.core] Invalid service data for telegram_bot.send_message: expected int @ data['target'][0]. Got '!'

Any tips how to select correct chat id without hardcoding it to the script page with if else template?

Put the whole thing into the secret, I have never had success putting a secret in the middle or on the end of a string

2 Likes