Hi! I’ve spent about 7 hours trying to make it works, but without any success. The main idea is making some automations for telegram bot that will update last bot’s message with actual statuses of lights, switches and so on.
For example trigger for user message /smallroom should return response with small room’s statuses and buttons. One of button is /smallroom_floorlight and bot’s response should be the same as for /small_room. It meance that it uses the same template. So if I want to make for example 10 buttons for one room I should copy and paste all the message template 10 times for each automation.
Example of automation for /smallroom:
alias: Telegram SmallRoom
description: ''
trigger:
- platform: event
event_type: telegram_callback
event_data:
data: /smallroom
condition: []
action:
- service: telegram_bot.edit_message
data_template:
message_id: last
chat_id: '{{ trigger.event.data.user_id }}'
title: '{{"🛏"}} *Маленькая комната*'
message: >
🌡 Температура: {{states('sensor.small_room_temp_hum_temperature') }} °C
💧 Влажность: {{ states('sensor.small_room_temp_hum_humidity')}}
🚶♂️ Движение: {{
relative_time(states.binary_sensor.small_room_movement_occupancy.last_changed)
}} назад
🔆 Освещённость: {{ states('sensor.small_room_lumi_illuminance') }} lx
🎶 Люмик: {%- if is_state('media_player.lumi04','playing') %} ▶️ {%
endif -%} {%- if is_state('media_player.lumi04','paused') %} ⏸ {% endif
-%} {%- if is_state('media_player.lumi04','off') %} ⏹ {% endif -%} {{
state_attr('media_player.lumi04', 'media_title') }}
inline_keyboard:
- >-
{% if is_state('switch.small_room_ceiling_light','on') %}🟩 Верхний
свет{%- else -%}🟥 Верхний свет{%- endif %}:/smallroom_ceilinglight
- >-
{% if is_state('light.small_room_floor_light','on') %}🟩 Торшер{%-
else -%}🟥 Торшер {%- endif %}:/smallroom_floorlight, {% if
is_state('light.small_room_lumi_light','on') %}🟩 Люмик{%- else -%}🟥
Люмик {%- endif %}:/smallroom_lumilight
- ↩️ Назад в меню:/tostart
mode: single
initial_state: 'on'
For the /smallroom_floorlight I use three actions: toggling floor lamp, delay 1 second to make template able to get new actual status in third action and updating last telegram bot’s message
....
- service: telegram_bot.edit_message
data_template:
message_id: last
chat_id: '{{ trigger.event.data.user_id }}'
.....
with the same template as for /smallroom.
I’ve tried few variants like
message: !include templates/small_room.yaml
and few other variants, but got null in message field after saving.
I’m thinking about something like custom sensor without type that will return long line with my template but I’m not sure that this template will works inside template for this sensor. It makes me crazy.
Please, propmt me how to reuse the same templates in multiply automations.
Thank’s for