Restructure repository: organize blueprints into folders
Each blueprint now has its own folder containing: - blueprint.yaml: The automation code with a short header - README.md: Detailed documentation extracted from headers Updated CLAUDE.md with repository structure guidelines. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
30
Common/Telegram Commands/README.md
Normal file
30
Common/Telegram Commands/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Telegram Commands Blueprint
|
||||
|
||||
This blueprint responds to Telegram bot commands (e.g., /start, /help, /status). Each command can trigger a different callback action and send an optional reply.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. User sends a command to the Telegram bot (e.g., `/lights_on`)
|
||||
2. Home Assistant receives `telegram_command` event
|
||||
3. Blueprint matches command to the configured list
|
||||
4. Executes the corresponding callback action
|
||||
5. Optionally sends a reply message
|
||||
|
||||
## Command Format
|
||||
|
||||
Commands should start with "/" (e.g., `/status`, `/lights_on`, `/arm_alarm`). The bot must be configured to receive these commands.
|
||||
|
||||
## Example Configuration
|
||||
|
||||
| Commands | Answers |
|
||||
|----------|---------|
|
||||
| `/status` | "Status checked" |
|
||||
| `/lights_on` | "Lights turned on" |
|
||||
| `/lights_off` | "Lights turned off" |
|
||||
| `/arm` | "Alarm armed" |
|
||||
|
||||
Each command has its own callback action that executes when received.
|
||||
|
||||
## Author
|
||||
|
||||
Alexei Dolgolyov (dolgolyov.alexei@gmail.com)
|
||||
221
Common/Telegram Commands/blueprint.yaml
Normal file
221
Common/Telegram Commands/blueprint.yaml
Normal file
@@ -0,0 +1,221 @@
|
||||
# Telegram Commands Blueprint
|
||||
# Responds to Telegram bot commands by executing callback actions.
|
||||
# See README.md for detailed documentation.
|
||||
|
||||
blueprint:
|
||||
name: "Custom: Telegram Commands"
|
||||
description: >
|
||||
Responds to Telegram bot commands (like /start, /help) by executing
|
||||
corresponding callback actions. Supports up to 8 commands with
|
||||
individual callbacks and optional reply messages.
|
||||
domain: automation
|
||||
|
||||
input:
|
||||
# -------------------------------------------------------------------------
|
||||
# Command Configuration
|
||||
# -------------------------------------------------------------------------
|
||||
commands_group:
|
||||
name: "Commands"
|
||||
collapsed: false
|
||||
input:
|
||||
commands:
|
||||
name: Command List
|
||||
description: >
|
||||
List of Telegram commands to respond to (include the "/" prefix).
|
||||
Example: ["/status", "/lights_on", "/arm_alarm"]
|
||||
default: []
|
||||
selector:
|
||||
text:
|
||||
multiple: true
|
||||
|
||||
answers:
|
||||
name: Reply Messages (optional)
|
||||
description: >
|
||||
Reply message for each command (same order as commands list).
|
||||
Leave empty to not send any reply for that command.
|
||||
default: []
|
||||
selector:
|
||||
text:
|
||||
multiple: true
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Command Callbacks
|
||||
# -------------------------------------------------------------------------
|
||||
callbacks_group:
|
||||
name: "Callbacks"
|
||||
collapsed: false
|
||||
input:
|
||||
command_1_callback:
|
||||
name: Command 1 Callback
|
||||
description: Actions to run when first command is received
|
||||
default: []
|
||||
selector:
|
||||
action: {}
|
||||
|
||||
command_2_callback:
|
||||
name: Command 2 Callback
|
||||
description: Actions to run when second command is received
|
||||
default: []
|
||||
selector:
|
||||
action: {}
|
||||
|
||||
command_3_callback:
|
||||
name: Command 3 Callback
|
||||
description: Actions to run when third command is received
|
||||
default: []
|
||||
selector:
|
||||
action: {}
|
||||
|
||||
command_4_callback:
|
||||
name: Command 4 Callback
|
||||
description: Actions to run when fourth command is received
|
||||
default: []
|
||||
selector:
|
||||
action: {}
|
||||
|
||||
command_5_callback:
|
||||
name: Command 5 Callback
|
||||
description: Actions to run when fifth command is received
|
||||
default: []
|
||||
selector:
|
||||
action: {}
|
||||
|
||||
command_6_callback:
|
||||
name: Command 6 Callback
|
||||
description: Actions to run when sixth command is received
|
||||
default: []
|
||||
selector:
|
||||
action: {}
|
||||
|
||||
command_7_callback:
|
||||
name: Command 7 Callback
|
||||
description: Actions to run when seventh command is received
|
||||
default: []
|
||||
selector:
|
||||
action: {}
|
||||
|
||||
command_8_callback:
|
||||
name: Command 8 Callback
|
||||
description: Actions to run when eighth command is received
|
||||
default: []
|
||||
selector:
|
||||
action: {}
|
||||
|
||||
# Parallel mode allows multiple commands to be processed simultaneously
|
||||
mode: parallel
|
||||
|
||||
# =============================================================================
|
||||
# Trigger
|
||||
# =============================================================================
|
||||
trigger:
|
||||
# Listen for Telegram command events
|
||||
- platform: event
|
||||
event_type: telegram_command
|
||||
id: "telegram_command"
|
||||
|
||||
# =============================================================================
|
||||
# Variables
|
||||
# =============================================================================
|
||||
variables:
|
||||
# Input references
|
||||
commands: !input commands
|
||||
answers: !input answers
|
||||
|
||||
# Callback references (needed for condition checks)
|
||||
command_1_callback: !input command_1_callback
|
||||
command_2_callback: !input command_2_callback
|
||||
command_3_callback: !input command_3_callback
|
||||
command_4_callback: !input command_4_callback
|
||||
command_5_callback: !input command_5_callback
|
||||
command_6_callback: !input command_6_callback
|
||||
command_7_callback: !input command_7_callback
|
||||
command_8_callback: !input command_8_callback
|
||||
|
||||
# Extract command and chat ID from trigger event
|
||||
received_command: "{{ trigger.event.data.command | default('') }}"
|
||||
chat_id: "{{ trigger.event.data.chat_id | default('') }}"
|
||||
user_id: "{{ trigger.event.data.user_id | default('') }}"
|
||||
|
||||
# Find the index of the received command in our list
|
||||
# Returns -1 if command not found or callback is empty
|
||||
command_index: >
|
||||
{% set ns = namespace(idx=-1) %}
|
||||
{% for i in range(commands | length) %}
|
||||
{% if received_command == commands[i] %}
|
||||
{% set ns.idx = i %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ ns.idx }}
|
||||
|
||||
# Debug flag - set to true to enable persistent notifications for troubleshooting
|
||||
is_debug: false
|
||||
|
||||
# =============================================================================
|
||||
# Condition - Only proceed if we received a valid command
|
||||
# =============================================================================
|
||||
condition:
|
||||
- condition: template
|
||||
value_template: "{{ received_command != '' and command_index >= 0 }}"
|
||||
|
||||
# =============================================================================
|
||||
# Actions
|
||||
# =============================================================================
|
||||
action:
|
||||
# ---------------------------------------------------------------------------
|
||||
# Debug Logging (optional)
|
||||
# ---------------------------------------------------------------------------
|
||||
- choose:
|
||||
- conditions:
|
||||
- condition: template
|
||||
value_template: "{{ is_debug }}"
|
||||
sequence:
|
||||
- service: persistent_notification.create
|
||||
data:
|
||||
title: "Telegram Commands Debug"
|
||||
message: >
|
||||
Received command: {{ received_command }}
|
||||
Chat ID: {{ chat_id }}
|
||||
User ID: {{ user_id }}
|
||||
|
||||
Command index: {{ command_index }}
|
||||
Commands list: {{ commands }}
|
||||
Answers list: {{ answers }}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Execute Command Callback
|
||||
# ---------------------------------------------------------------------------
|
||||
- choose:
|
||||
- conditions: "{{ command_index == 0 and command_1_callback | length > 0 }}"
|
||||
sequence: !input command_1_callback
|
||||
- conditions: "{{ command_index == 1 and command_2_callback | length > 0 }}"
|
||||
sequence: !input command_2_callback
|
||||
- conditions: "{{ command_index == 2 and command_3_callback | length > 0 }}"
|
||||
sequence: !input command_3_callback
|
||||
- conditions: "{{ command_index == 3 and command_4_callback | length > 0 }}"
|
||||
sequence: !input command_4_callback
|
||||
- conditions: "{{ command_index == 4 and command_5_callback | length > 0 }}"
|
||||
sequence: !input command_5_callback
|
||||
- conditions: "{{ command_index == 5 and command_6_callback | length > 0 }}"
|
||||
sequence: !input command_6_callback
|
||||
- conditions: "{{ command_index == 6 and command_7_callback | length > 0 }}"
|
||||
sequence: !input command_7_callback
|
||||
- conditions: "{{ command_index == 7 and command_8_callback | length > 0 }}"
|
||||
sequence: !input command_8_callback
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Send Reply Message (if configured)
|
||||
# ---------------------------------------------------------------------------
|
||||
- variables:
|
||||
reply_message: >
|
||||
{% if command_index >= 0 and command_index < (answers | length) %}
|
||||
{{ answers[command_index] }}
|
||||
{% else %}
|
||||
{% endif %}
|
||||
|
||||
- choose:
|
||||
- conditions: "{{ reply_message | trim | length > 0 }}"
|
||||
sequence:
|
||||
- service: telegram_bot.send_message
|
||||
data:
|
||||
target: "{{ chat_id }}"
|
||||
message: "{{ reply_message }}"
|
||||
Reference in New Issue
Block a user