- alias: 'Conversation'
initial_state: 'on'
trigger:
platform: event
event_type: telegram_text
condition:
condition: template
value_template: >-
{% set device = trigger.event.data.text|lower|replace('turn on ','')|replace('turn off ','') %}
{% for entity in states.group.controllable_devices.attributes.entity_id if states[entity.split('.')[0]][entity.split('.')[1]].name|lower == device -%}
true
{%- else -%}
false
{%- endfor -%}
action:
- service: conversation.process
data_template:
text: '{{ trigger.event.data.text|lower }}'
- service: telegram_bot.send_message
data_template:
message: >-
{% set device = trigger.event.data.text|lower|replace('turn on ','')|replace('turn off ','') %}
OK, {{ trigger.event.data.text|lower|replace('turn','turning') }}.
title: ''
target: '{{ trigger.event.data.user_id }}'
- alias: 'Conversation Device Not Found'
initial_state: 'on'
trigger:
platform: event
event_type: telegram_text
condition:
condition: template
value_template: >-
{% set device = trigger.event.data.text|lower|replace('turn on ','')|replace('turn off ','') %}
{% for entity in states.group.controllable_devices.attributes.entity_id if states[entity.split('.')[0]][entity.split('.')[1]].name|lower == device -%}
false
{%- else -%}
true
{%- endfor -%}
action:
service: telegram_bot.send_message
data_template:
message: >-
{% set device = trigger.event.data.text|lower|replace('turn on ','')|replace('turn off ','') %}
I'm sorry. I cannot find the device named {{device}} in the house.
title: ''
target: '{{ trigger.event.data.user_id }}'
with this automation, I can send text message to my HA via Telegram using the same command for the conversation component such as “turn [on/off] [Friendly Name]”.
UPDATE 1: Limit the devices that can be controlled by using group. Then added the ability to response back the result of the request whether it is successful or not.
when was conversation added? I was looking for a way to have the telegram bot turn off specific entity using a template. What does your conversation config look like?
Great! I was using Telegram Bot for controlling several devices but didn’t know about the conversation component so I created an automation for every command. Now this has much more use
Regarding to your conversation with telegram bot to turn on/off device
Do I have to put anything in the intent_script.yaml and conversation.yaml ?
As I didn’t use telegram bot. Can it trigger and service from something else to be able to turn on/off device?
Currently, I am able to use conversation and intent_script to turn on/off device, but I have to add in each of the devices in both conversation and intent_script. Is there anyway to make it shorter or more simpler like what you did?
example:
- alias: 'Conversation'
initial_state: 'on'
trigger:
platform: event
event_type: telegram_text <== can it be conversation or ?
action:
- service: conversation.process
data_template:
text: '{{ trigger.event.data.text|lower }}'
- service: telegram_bot.send_message <=== can it be something?
@masterkenobi I have followed your instructions and have added the group and the automation but when I turn on say my heater from Telegram it says its turning the heater on but nothing happens and it keeps on sending me the message that it is turning the heater on.
Do I have set up any script? because I only have conversation: in my configuration.yaml
I am trying to use your project but i have a doubt.
Must i insert friendly name inside the controllable devices group or not?
If not in conversation i must put the device name inserted into the group or only the friendly_name?