#Using Lists or Slots in Trigger Sentences?

1 messages · Page 1 of 1 (latest)

queen anchor
#

Alright, so my wife and I have a few apps that are really terrible about letting us know when we have a new message(s). Or we turn off notifications from that app because their notifications are all-or-nothing and we hate the dozens of pushy notifications they send each day. So I set up buttons I called "Ping" buttons found in a Ping subview in a dashboard (They all call a corresponding script). But, I thought it might be easier if we could ask Home Assistant to ping other person.

But, I really don't want to set up 5 different triggers for each app.

I'd rather have one trigger with the sentence similar to
tell my wife to check her {app_name}

and for whatever is said in {app_name} to determine which choice of actions is run. So if I say "tell my wife to check her snapchat", it'll run a script that sends her a notification to check her snapchat.

I've been trying to read up on intent, custom sentences, and custom responses and such, but so much of it gives complex examples I don't quite understand or talk about files that don't pre-exist in my files. And when I mention lists in searches, I get results about to-do lists which have nothing to do with what I'm trying to do.

(slightly related, I also re-did setting the lights to certain colors just so the assistant would respond with "as you wish").

Can I get a super beginner's guide on setting such wildcard words? Or whatever it takes to set this up correctly?

gray tinsel
#

Here's example:

language: "en"
intents:
  AnyListAddItem:
    data:
      - sentences:
        - "add {item} to <articles> {anylist} list"

  AnyListRemoveItem:
    data:
      - sentences:
        - "remove {item} from <articles> {anylist} list"

  AnyListGetItems:
    data:
      - sentences:
        - "(whats | what's | what is | what do i have) (in | on) <articles> {anylist} list"

lists:
  item:
    wildcard: true
  anylist:
    values:
      - in: "(costco | costa | cosco)"
        out:
          name: "Costco"
          entity_id: "todo.anylist_costco"
      - in: "errands"
        out: 
          name: "Errands"
          entity_id: "todo.anylist_errands"

expansion_rules:
  articles: "[the | my]"
queen anchor
#

1: I understand nothing of what you just put

2: my post has nothing to do with to-do lists.

gray tinsel
stiff basalt
#

Maybe take a look at https://www.home-assistant.io/voice_control/custom_sentences/ to get started? It describes how to add a custom sentence trigger to an automation with a wild card slot like you are looking for. From there you can use the value in that slot and do what you need with it. 🙂

Home Assistant

Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server.

queen anchor
# stiff basalt Maybe take a look at https://www.home-assistant.io/voice_control/custom_sentence...

I set up a test

`alias: wildcard test
description: ""
triggers:

  • trigger: conversation
    command:
    • I pick [the color] {color}
      conditions: []
      actions:
  • set_conversation_response: Me, too. {{trigger.slots.color}} is my favorite.
    mode: single`

This works as you'd expect. But, when I try to add a "choose" with an option based on the color I said, all I get back is "Done". I thought a template condition would work fine.

`alias: wildcard test
description: ""
triggers:

  • trigger: conversation
    command:
    • I pick [the color] {color}
      conditions: []
      actions:
  • choose:
    • conditions:
      • condition: template
        value_template: "{{trigger.slots.color}} == "red"". ## (FOUND THE PROBLEM. IT'S HOW THIS IS FORMATTED)
        sequence:
      • set_conversation_response: Me, too. {{trigger.slots.color}} is my favorite.
        mode: single`
zenith vault
#

try {{ 'red' in trigger.slots.color | lower }}

#

Regarding your original request, please show us the actions of your “ping” script. The use of wildcards is excessive; it is better to use a custom sentence in YAML with a predefined list of several options, as shown above.

queen anchor
#

I figured out what I was trying to do.

For anyone else stumbling on this who may have also been confused on how to do something like this, here's a small example using lights because those are easy to understand.

This example will change the color of a single light. Like any automation, we start with the trigger. The trigger will be a sentence trigger as we're setting up a custom sentence we can speak into our HA voice assistant.

triggers:
- trigger: conversation
command: set the lightbulb to {color}

Yes, just write it like that. Normally, if I'd want it red, here's how a light.turn_on action would look in YAML

actions:
- action: light.turn_on
metadata: {}
data:
rgb_color:
- 255 # red
- 0 # green
- 0 # blue
target:
entity_id: light.the_lightbulb

If you add the choose building block, you can add conditions to each choice so that only the correct one gets applied. It looks like this in YAML:

actions:
- choose:
- conditions: [] # I left the condition blank for now
sequence:
- action: light.turn_on # here's the action we saw earlier
metadata: {}
data:
rgb_color:
- 255
- 0
- 0
target:
entity_id: light.the_lightbulb

#

Now, if I add a condition based on a template, I could write {{ trigger.slots.color == 'red' }} in the conditions. In YAML, that makes it look like this:

actions:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.slots.color == 'red' }}" # this is the magic
sequence:
- action: light.turn_on
metadata: {}
data:
rgb_color:
- 255
- 0
- 0
target:
entity_id: light.the_lightbulb

What's actually happening? The documentation has this to say:

Adding one or more {lists} to your trigger sentences will capture any text at that point in the sentence. A slots object will be available in the trigger data. This allows you to match sentences with variable parts...

The way this makes sense to me is I think of it as putting a "slot" in the sentence using the {curly brackets}. You can put anything in the curly brackets to name the slot and use trigger.slots.[your_chosen_slot_name] to refer to it later in the automation.