Skip to content

Instantly share code, notes, and snippets.

@tetele
Last active February 16, 2024 23:30
Show Gist options
  • Save tetele/be17790f0ca94f286f94fbae8878a26e to your computer and use it in GitHub Desktop.
Save tetele/be17790f0ca94f286f94fbae8878a26e to your computer and use it in GitHub Desktop.
# Custom sentences and intents for chaining and delaying intents

Here are a couple of custom sentences and custom intents that will handle the following scenarios in Home Assistant's Assist:

  • "turn on the bathroom light and then turn on the bathroom fan"
  • "turn off the living room heating in 10 minutes"

Installation

  • copy the contents of custom_sentences.yaml to <your config folder>/custom_sentences/en/chain_delay.yaml
  • append the contents of configuration.yaml to <your config folder>/configuration.yaml
  • restart HA (mandatory to reload the custom sentences)

After the restart, in any Assist session (voice or text) you can chain instructions using "and"/"and then"/"then" or instruct HA to do something after some time.

Limitations

  • due to this bug, you can only chain 2 sentences ("do this and then do that"). 3 or more will fail for some of the sentences.
  • stuff like "tell me what is the state of the temperature sensor in 5 seconds" will work, but will do nothing, as delayed intents responses are lost.
  • delaying intents depends on how well your STT engine can interpret numerals i.e. "3" instead of "three". If it doesn't want to transcribe numbers and it says it doesn't understand you, there's not much you can do.

GithubSponsor or BuyMeCoffee

intent_script:
ChaninedSentences:
speech:
text: OK
async_action: true
action:
- service: conversation.process
data:
agent_id: homeassistant
text: "{{ sentence_1 }}"
language: "{{ language }}"
- service: conversation.process
data:
agent_id: homeassistant
text: "{{ sentence_2 }}"
language: "{{ language }}"
HassDelayAction:
speech:
text: "I'll do it in {{number}} {{ time_units }}"
async_action: true
action:
- delay: >
{{ { time_units: number } }}
- service: conversation.process
data:
agent_id: homeassistant
text: "{{ sentence_1 }}"
language: "{{ language }}"
language: en
intents:
ChaninedSentences:
data:
- sentences:
- "{sentence_1} (then|and [then]) {sentence_2}"
slots:
language: en
HassDelayAction:
data:
- sentences:
- "({sentence_1};<in_time_interval>)"
slots:
language: en
- sentences:
- "({sentence_1};<in_time_interval>)"
expansion_rules:
time_interval: "(one|a[n]) {time_units}"
slots:
number: 1
language: en
- sentences:
- "({sentence_1};<in_time_interval>)"
expansion_rules:
time_interval: "(one|a[n]) half [of] [an] hour"
slots:
number: 30
time_units: minutes
language: en
lists:
sentence_1:
wildcard: true
sentence_2:
wildcard: true
number:
range:
from: 1
to: 500
time_units:
values:
- in: second[s]
out: seconds
- in: minute[s]
out: minutes
- in: hour[s]
out: hours
expansion_rules:
time_interval: "{number} {time_units}"
in_time_interval: "(in <time_interval> [from now]|<time_interval> from now)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment