Assist custom sentences

I’m a beginner with HA and, after discovering the Companion app will let me use voice without HTTPS (online posts on that topic are contradictory), am trying to make Assist more useful. There’s a lot in the documentation about using custom phrases etc (in Assist - Custom Sentences - Home Assistant). It isn’t clear to me from this instruction whether, after adding a custom sentence using “Create automation”, we’re meant to add this in configuration.yaml and/or the config directory as well. Anyway, doing all of this didn’t work initially for me this morning even after reloading YAML, and Assist just said “Sorry, I didn’t understand that”.

What worked for me for both TV_power_on and TV_power_off scripts after several attempts was just creating automations with the trigger sentence (When the sentence ‘Switch off the tele’ or 'Switch off the tally’ is said) and the action “Call a service ‘Scripts: TV_power_off’”.

This is my automation

alias: To turn off the TV
description: Should run the script TV_power_off
trigger:
  - platform: conversation
    command:
      - Switch off the tele
      - Switch off the tally
condition: []
action:
  - service: script.tv_power_off
    data: {}
    response_variable: R
mode: single

I’m trying to understand how Home Assistant is processing voice commands but, strangely, the debug log below doesn’t show details of the script that was called (TV_power_off) - a potential source of confusion with similarly named scripts for on and off where the device remote only has a power toggle. (The reason for using scripts here is to check the device state before toggling - my Google Home incorrectly turns on the TV at bedtime when I run a routine.) Is there any way to get HA to show the exact action performed in response to the trigger?

Thanks.

(Assist debug log)

stage: done
run:
  pipeline: 01h5z2s1a14bnzvqwfq7jn171b
  language: en 
events:
  - type: run-start
    data:
      pipeline: 01h5z2s1a14bnzvqwfq7jn171b
      language: en
      runner_data:
        stt_binary_handler_id: 1
        timeout: 30
    timestamp: "2023-07-31T09:39:06.885629+00:00"
  - type: stt-start
    data:
      engine: stt.faster_whisper
      metadata:
        language: en
        format: wav
        codec: pcm
        bit_rate: 16
        sample_rate: 16000
        channel: 1
    timestamp: "2023-07-31T09:39:06.886010+00:00"
  - type: stt-end
    data:
      stt_output:
        text: " Switch off the tele."
    timestamp: "2023-07-31T09:39:14.257017+00:00"
  - type: intent-start
    data:
      engine: homeassistant
      language: en
      intent_input: " Switch off the tele."
      conversation_id: null
      device_id: null
    timestamp: "2023-07-31T09:39:14.257093+00:00"
  - type: intent-end
    data:
      intent_output:
        response:
          speech:
            plain:
              speech: Done
              extra_data: null
          card: {}
          language: en-GB
          response_type: action_done
          data:
            targets: []
            success: []
            failed: []
        conversation_id: null
    timestamp: "2023-07-31T09:39:14.334905+00:00"
  - type: tts-start
    data:
      engine: tts.google_en_com
      language: en-gb
      voice: null
      tts_input: Done
    timestamp: "2023-07-31T09:39:14.335036+00:00"
  - type: tts-end
    data:
      tts_output:
        media_id: media-source://tts/tts.google_en_com?message=Done&language=en-gb
        url: >-
          /api/tts_proxy/e9b450d14bc2363d292c84f17cfad5cfbd58a458_en-gb_-_tts.google_en_com.mp3
        mime_type: audio/mpeg
    timestamp: "2023-07-31T09:39:14.335747+00:00"
  - type: run-end
    data: null
    timestamp: "2023-07-31T09:39:14.335823+00:00"
stt:
  engine: stt.faster_whisper
  metadata:
    language: en
    format: wav
    codec: pcm
    bit_rate: 16
    sample_rate: 16000
    channel: 1
  done: true
  stt_output:
    text: " Switch off the tele."
intent:
  engine: homeassistant
  language: en
  intent_input: " Switch off the tele."
  conversation_id: null
  device_id: null
  done: true
  intent_output:
    response:
      speech:
        plain:
          speech: Done
          extra_data: null
      card: {}
      language: en-GB
      response_type: action_done
      data:
        targets: []
        success: []
        failed: []
    conversation_id: null
tts:
  engine: tts.google_en_com
  language: en-gb
  voice: null
  tts_input: Done
  done: true
  tts_output:
    media_id: media-source://tts/tts.google_en_com?message=Done&language=en-gb
    url: >-
      /api/tts_proxy/e9b450d14bc2363d292c84f17cfad5cfbd58a458_en-gb_-_tts.google_en_com.mp3
    mime_type: audio/mpeg

I tried it three times, but I’m sorry, I still don’t get what you want, what you need or what isn’t working for you. It sounds a little confusing… :slight_smile:

Maybe try to explain it in a little more order. What is it, that you want? Do want to know how custom sentences work? And with the TV I’m totally lost, what remote, what toogle? What your remote offers to control your TV didn’t need to be the same as what you can send as a command from HA.

Anyway, as I said, it’s confusing, at least for me, so please try to make clear, what you want. :slight_smile:

Sorry if it wasn’t clear. I’m just trying to understand what HA is doing and why the names of the scripts invoked don’t appear in the log files. Rather than just send a power toggle command, I’m using two YAML scripts to switch the TV on or off only if it isn’t already in the requested state - something that Google can’t manage. Here’s my TV_power_off script, which I found difficult to create because I’m used to if…then syntax and not YAML.

alias: TV_power_off
sequence:
  - condition: or
    conditions:
      - condition: state
        entity_id: media_player.lg_webos_tv_907b
        state: "on"
      - condition: state
        entity_id: media_player.lg_webos_tv_907b
        state: playing
      - condition: state
        entity_id: media_player.lg_webos_tv_907b
        state: paused
  - service: remote.send_command
    data:
      num_repeats: 1
      delay_secs: 0.4
      hold_secs: 0
      device: TV
      command: Power
    target:
      device_id: e7efb16b0ec3f1049df123c211d97c49
mode: single
icon: mdi:television

My aim next is to create a script for bedtime that, when I say “Bedtime”, will turn off all the lights downstairs, switch on my bedside lamp and then switch off the TV if it happens to be on - the only bit that Google gets wrong. I have heard that there are separate on and off commands for my LG TV, but can only get commands into my Broadlink RM4 Pro remote device by teaching the system these via the existing remote: this has no separate on and off, only a power toggle button. It may be that HA could send the right commands directly to the TV but I’ve no way of finding out those codes.