Put my telegram code in the main configuration.yaml, but is there any way to include it in a separate file rather then clutter up the main config? Does it use a reserved keyword like telegram: !include telegram.yaml
And would i put the notification code block in there as well ?
From the docs, you really should only have the following lines in your configuration.yaml file. Everything else, at least in my case, ends up in separate automation files (specifically actions section).
# Example configuration.yaml entry for the Telegram Bot
telegram_bot:
- platform: polling
api_key: YOUR_API_KEY
allowed_chat_ids:
- CHAT_ID_1 # example: 123456789 for the chat_id of a user
- CHAT_ID_2 # example: -987654321 for the chat_id of a group
- CHAT_ID_3
# Example configuration.yaml entry for the notifier
notify:
- platform: telegram
name: NOTIFIER_NAME
chat_id: CHAT_ID_1
# It is possible to add multiple notifiers by using another chat_id
# the example belows shows an additional notifier which sends messages to the bot which is added to a group
- platform: telegram
name: NOTIFIER_NAME_OF_GROUP
chat_id: CHAT_ID_2
Yes that works, but the working configuration need to be in “configuration.yaml”…
When we try to use an include like:
telegram: !include telegram.yaml
The same configuration dosn’t work and I got an error:
KeyError: 'telegram_bot'
2023-01-07 19:23:15.800 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of telegram. Setup failed for dependencies: telegram_bot
2023-01-07 19:23:15.819 ERROR (MainThread) [homeassistant.setup] Setup failed for telegram: (DependencyError(...), 'Could not setup dependencies: telegram_bot')
I guess if it’s important to get 5 or so lines of code out of configuration.yaml and into something separate you can use !include. But there is no telegram entry for your config. It is telegram_bot. So you’d put this in your config (still need the notify component too).