vladosam
(Vladimir)
June 22, 2017, 10:33am
1
If i use this automation nothing happens when i press button.
action:
service: notify.telegram
data:
title: 'Vrata otvorena!'
message: 'Sta da radim?'
data:
inline_keyboard:
- 'Lampa:/lights_on, Lampa_off:/lights_off'
- 'Help:/help, Start:/start'
and this works just fine
action:
service: notify.telegram
data:
title: 'Vrata otvorena!'
message: 'Sta da radim?'
data:
keyboard:
- /lights_on, /lights_off
- /help, /start
hellad
(AD)
August 22, 2017, 1:23pm
2
I can’t see any buttons in telegram message if I either use keyboard or inline_keyboard version of automation. Only text of message is displayed in reply to /start command.
Have you solved the issue?
vladosam
(Vladimir)
August 22, 2017, 5:07pm
3
This works in my automation:
- id: '4007'
alias: 'welcome telegram message'
hide_entity: true
trigger:
- platform: event
event_type: telegram_command
event_data:
command: '/start'
action:
- service: notify.telegram
data_template:
title: 'Welcome to Automata'
message: >
What shall we do today?
data:
keyboard:
- '/ikea_on, /lights_off, /status'
- '/alarm_on, /alarm_off, /help'
and inline_keyboard works but i don’t need it so i delete it from my configuration.
hellad
(AD)
August 22, 2017, 6:35pm
4
Thank you for quick reply.
It looks quite strange for me, because in my system (version 0.51.2) the same automation does not work:
- alias: ‘Telegram bot reply to start’
hide_entity: true
trigger:
platform: event
event_type: telegram_command
event_data:
command: ‘/start’
action:
- service: telegram_bot.send_message
data_template:
target: ‘{{ trigger.event.data.user_id }}’
message: ‘Commands:’
data:
keyboard:
- ‘/ping, /speak’
- ‘/photo, /status’
The only difference I see is type of service being used. Mine is telegram_bot. Does it matter that I use webhooks connection instead of polling? (Identation failed when text pasted)
vladosam
(Vladimir)
August 22, 2017, 7:21pm
5
Try to ad parse_mode: html to telegram_bot configuration. I had some problems with parse_mode: markdown. Maybe that could help.
hellad
(AD)
August 22, 2017, 7:47pm
6
vladosam:
parse_mode: html
Thank you for advise. Unfortunately it did not help
vladosam
(Vladimir)
August 22, 2017, 8:21pm
7
Can you change it to polling to test?
hellad
(AD)
August 22, 2017, 8:33pm
8
Yes, I tried. Result is the same - I see only text of message: . No commands.
That is mystique.
vladosam
(Vladimir)
August 22, 2017, 8:43pm
9
Do you get response if you manualy type command in telegram /ping?
hellad
(AD)
August 22, 2017, 9:15pm
10
Surely. All telegram commands work perfectly. The only issue with keyboard.
vladosam
(Vladimir)
August 23, 2017, 7:51am
11
Bummer. I know that telegram uses phone default keyboard to set size of commands. Maybe change keyboard? Reinstall telegram on phone?
hellad
(AD)
August 25, 2017, 10:36am
12
I will try telegram on different devices (IOS, android). Perhaps somewhere it will work.
And what about web version of telegram? It should work I suppose , but did not…
vladosam
(Vladimir)
August 25, 2017, 11:06am
13
Yea. If web version works then problem is in HA. Can you post configuration with proper formating? Maybe we can spot problem.
hellad
(AD)
August 25, 2017, 11:16am
14
Unfortunately in web version of telegram I see the same picture - only text of “message:” field . May be I should make a deep dive in some debug information. For example try to use network sniffer to see what is in the answer from telegram bot or telegram server. But in this case I need to know for sure what is there when everything is correct.
I’ll post relevant part of my config later. BTW thank you for your participation.
hellad
(AD)
August 25, 2017, 12:51pm
15
configuration.yaml
telegram_bot:
- platform: polling
api_key: !secret telegram_bot_pooling_api_key
parse_mode: html
allowed_chat_ids:
- !secret telegram_bot_chat_id_megafon
- !secret telegram_bot_chat_id_beeline
- !secret telegram_bot_pooling_chat_id_group
notify:
- platform: telegram
name: telegram_direct_bee
api_key: !secret telegram_bot_pooling_api_key
chat_id: !secret telegram_bot_chat_id_beeline
- platform: telegram
name: telegram_direct_mega
api_key: !secret telegram_bot_pooling_api_key
chat_id: !secret telegram_bot_chat_id_megafon
- platform: telegram
name: telegram_group
api_key: !secret telegram_bot_pooling_api_key
chat_id: !secret telegram_bot_pooling_chat_id_group
automation
- alias: 'Telegram bot reply pong to ping'
hide_entity: true
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/ping'
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.user_id }}'
message: >
{{now().strftime("%H:%M:%S %Y-%m-%d")}} Pong, Message from {{ trigger.event.data["user_id"] }}.
- alias: 'Telegram bot reply to start'
hide_entity: true
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/start'
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.user_id }}'
message: 'Commands:'
data:
inline_keyboard:
- 'Ping:/ping, Voice:/speak'
- 'Photo:/photo, Status:/status'
- alias: 'Telegram bot reply with Google TTS Speak'
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/speak'
action:
- service: tts.google_say
entity_id: media_player.vlcmp
data_template:
language: en
message: >
Attention, Weather forecast: {{ states('sensor.pws_weather_1d_metric') }}
- delay: 0:0:12
- service: tts.google_say
entity_id: media_player.vlcmp
data_template:
language: en
message: >
Current outdoor temperature is {{ states('sensor.owm_temperature')|int }} centigrades
- alias: 'Telegram bot send photo'
hide_entity: true
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/photo'
action:
- service: telegram_bot.send_photo
data_template:
target: '{{ trigger.event.data.user_id }}'
file: "/home/homeassistant/.homeassistant/www/camera.png"
- alias: 'Telegram reply with Status'
hide_entity: true
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/status'
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.user_id }}'
message: >-
System alive ;) ! Since last reboot {{states.sensor.since_last_boot.state}}.
Irina is at {{ states.device_tracker.irina.state|replace("_"," ") }} .
Andrey is at {{ states.device_tracker.andrey.state|replace("_"," ") }} .
Pavel is at {{ states.device_tracker.pavel.state|replace("_"," ") }} ,
and Prokhor is at {{ states.device_tracker.prokhor.state|replace("_"," ") }}.
Weather {{ states('sensor.pws_weather_1d_metric') }}. Temperature & humidity at home: {{ states('sensor.28000008a43272') }}C {{ states('sensor.hall_dht11_humidity') }}%.
AirCon status: Power {{ states.switch.fujitsu.state }}, current mode {{ states.input_select.bedroom_aircon_mode.state }}-{{ states.input_select.bedroom_aircon_fan.state }}-{{ states.input_slider.bedroom_aircon_temperature.state|int }} .
vladosam
(Vladimir)
August 25, 2017, 1:16pm
16
In my configuration notify is like this:
notify:
- name: telegram
platform: telegram
chat_id: !secret telegram_bot_ids
telegram_bot:
- platform: polling
api_key: !secret telegram_bot_api
parse_mode: html
allowed_chat_ids:
- !secret telegram_bot_ids
And then in automation i call notify service not telegram bot like this:
- id: '4007'
alias: 'welcome telegram message'
hide_entity: true
trigger:
- platform: event
event_type: telegram_command
event_data:
command: '/start'
action:
- service: notify.telegram
data_template:
title: 'Welcome to Automata'
message: >
What shall we do today?
data:
keyboard:
- '/ikea_on, /lights_off, /status'
- '/alarm_on, /alarm_off, /help'
I don’t use this target line.
hellad
(AD)
August 27, 2017, 6:11pm
17
I tried notify service instead of telegram_bot.message. And it works with keyboard: statement. But inline_keyboard: did not respond to my touches.
It is question to developers of telegram_bot component, could the “keyboard:” be used not only with notify.
I need to analyze what to do in my case. I’d like to keep universal approach when respond from bot can be sent to different people based on their chat_id. Notify does not have target parameter (in accordance with documentation).
Thank you for your help.
vladosam
(Vladimir)
August 28, 2017, 6:33am
18
Try this. In:
- alias: 'Telegram bot reply to start'
hide_entity: true
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/start'
Change telegram_command with:
- alias: 'Telegram bot reply to start'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/start'
vladosam
(Vladimir)
August 28, 2017, 7:10am
19
And i see that action is different in HA examples for telegram_chatbot. There is not data before inline_keyboard.
action:
- service: telegram_bot.send_message
data_template:
title: '*Dumb automation*'
target: '{{ trigger.event.data.user_id }}'
message: 'You said: {{ trigger.event.data.text }}'
disable_notification: true
inline_keyboard:
- "Edit message:/edit_msg, Don't:/do_nothing"
- "Remove this button:/remove button"
hellad
(AD)
August 29, 2017, 5:11pm
20
I think that “telegram_callback” should be used only for answers when keyboard is already formed.
You are right.
I tried to modify my config a bit. I’d like to test inline_keyboard again. Thus, I put in automation following config :
- alias: 'Telegram bot reply to start'
hide_entity: true
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/start'
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.user_id }}'
message: 'Commands:'
inline_keyboard:
- 'Ping:/ping, Restart:/rst, Status:/status'
- 'AC_on:/acon, AC_off:/acoff, Photo:/photo'
- alias: 'Telegram bot reply pong to ping'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/ping'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: >-
Callback received from {{ trigger.event.data.from_first }}.
Message id: {{ trigger.event.data.message.message_id }}.
Data: {{ trigger.event.data.data }}
{{now().strftime("%H:%M:%S %Y-%m-%d")}} Pong, Message from {{ trigger.event.data["user_id"] }}.
This time I see inline keyboard and get response to my touch on Ping key. But! That response is not a general message (as I expected) but some kind of popup push window with short life time .
In web client it looks like text on grey background (on screenshot attached).
So it’s unusable in such format and I’ll step back to “keyboard:” option.
P.S. In web client keys from “keyboard:” option remain on screen even after sending several messages. In application they disappear after first message…