Changing channels by voice on webos
I’m a beginner on HA and a non-programmer. With the help of ChatGPT, I’ve managed to do some simple things. My TV is already turning on by voice and changing channels through the dashboard, but I want to make it change channels by voice, either by channel name or channel number. ChatGPT has suggested several alternatives, but none of them worked. At least the last one, the voice assistant recognizes and responds that the request was answered, but nothing happens. Could some kind soul help me fix it?
scripts.yaml:
mudar_canal_por_numero:
alias: Mudar canal por número
description: Troca o canal da TV com base no número
fields:
canal_numero:
description: Número do canal
example: 1
sequence:
- variables:
canal_nome: >
{% set canais = {
'1': 'Das Erste HD',
'2': 'SWR RP HD',
'3': 'WDR HD Köln'
} %}
{{ canais[canal_numero|string] if canal_numero|string in canais else '' }}
- condition: template
value_template: "{{ canal_nome != '' }}"
- service: input_select.select_option
target:
entity_id: input_select.tv_channel
data:
option: "{{ canal_nome }}"
configuration.yaml:
tv_channel:
name: Canal da TV
options:
- "Das Erste HD"
- "SWR RP HD"
- "WDR HD Köln"
icon: mdi:television
automations.yaml - for changing chanels voice control:
- id: 'trocar_canal_por_voz'
alias: Mudar canal por voz
trigger:
- platform: conversation
command:
- mudar pro canal 1
- mudar pro canal 2
- mudar pro canal 3
- trocar pro o canal 1
- trocar pro o canal 2
- trocar pro o canal 3
- canal 1
- canal 2
- canal 3
action:
- variables:
numero: >
{% if '1' in trigger.command %} 1
{% elif '2' in trigger.command %} 2
{% elif '3' in trigger.command %} 3
{% else %} 0
{% endif %}
- service: script.mudar_canal_por_numero
data:
canal_numero: "{{ numero }}"
- service: conversation.process
data:
text: Canal {{ numero }} selecionado
mode: single
automations.yaml - Where the channel changing throug Dashoard already works:
- alias: Trocar canal da TV
id: trocar_canal_tv
trigger:
- platform: state
entity_id: input_select.tv_channel
action:
- service: media_player.play_media
target:
entity_id: media_player.lg_webos_tv_oled55b9dla
data:
media_content_id: '{{ states(''input_select.tv_channel'') }}'
media_content_type: channel
mode: restart