Sentence parses but when checked for 'if defined' it defaults to something else

I have these sentence triggers:

triggers:
  - command:
      - >-
        (Set [a] reminder | Remind me) [ to | about ] {reminderDescription} on
        {reminderDate} at {reminderTime} 
      - >-
        (Set [a] reminder | Remind me) [ to | about ] {reminderDescription} at
        {reminderTime} on {reminderDate} 
      - >-
        (Set [a] reminder | Remind me) [ to | about ] {reminderDescription} (at
        | in ) {reminderTime}

The output of this is fed to OpenAI in this sentence:-

              text: >
                The current date and time is {{states.sensor.date.state}}
                {{states.sensor.time.state}}:00. Rewrite
                '{{trigger.slots.reminderTime}}' on
                '{{trigger.slots.reminderDate if defined else
                states.sensor.date.state}}' to time format 'YYYY-MM-DD
                HH:MM:SS'.  The answer should be a datetime and must be in the
                future. In your response return exactly 19 characters of the
                datetime string in format 'YYYY-MM-DD HH:MM:SS'

if I check the value of trigger.slots.reminderDate it is assigned a correct value, such as ‘February 7’

But when checked in the text section above, it defaults to 31/01/25 (todays date), because I’m guessing if defined thinks its not defined ?

If I change that part of the text to just:

'{{trigger.slots.reminderDate}}' it works fine.

But I want to have the if defined part as sometimes the sentence triggers dont include the date, so how can I get it to work ?

EDIT:- In the end I changed the if defined check to

                '{% if trigger.slots.reminderDate | length >0 %}
                {{ trigger.slots.reminderDate }}
                else
                {{ states.sensor.time.date }}
                {%endif%}'

And it works fine.

Don’t know if this is relevant, but in your sentences shouldn’t…

[ to | about ]

be…

[ ( to | about ) ]

Thanks for the heads up. I’ve struggled to find the docs for the sentence definition structure, don’t suppose you have a link ?

Also, a separate issue. If I say the sentence ‘Remind me to eat cakes at 5pm on Feb 7’

The reminder message is just ‘e’ as the ‘at’ part of eat seems to be parsed into the rest of the sentence. How do I stop that (I assume I can enforced some spaces to do this ?)

EDIT: I fixed the ‘e’ problem by changing the spacings as I suspected.

1 Like

Thanks @jackjourneyman.

Looks like [ to | about ] is ok. There is an example on that page.

Ok, I didn’t fix my ‘e’ problem.

This trigger:-

triggers:
  - command:
      - >-
        (Set [a] reminder | Remind me | Tell me) [to | about] {reminderDescription} ( at | in ) {reminderTime}

When I say ‘remind me to eat cakes at 7pm’

The response is read back and the ‘reminderDescription’ is just the letter ‘e’.
Its like its splitting the word eat so that the next part of the sentence matches. But why ?

That’s exactly what it did. What’s the speech pipeline say STT passed?

In short I got fed up with trying to get this stuff to catch alll the variation and turned off local first and let the llm sort it out. Even the STT is the bottle neck I’ve seen some absolutely absurd speech translations…

Me no Friday, not… Ugh… How did STT get manatee out of Car?

I think trying to set long reminders this way is fraught with issues. Words in the reminder can then trigger other parts of the sentence matching, or in the case above, weirdly split words.

I can solve the problem by restructuring the sentence so the date and time are spoken first, but even then, unless I am very fluid with my sentences, they seem to get cut off half way.

The LLM (in this case OpenAI and chatgpt 4o-mini) can add items to a todo list I have called reminders, but it won’t set dates and times. If you have this working, I’d love to know how.

FYI, the STT seemed fine (google STT):

Natural Language Processing1.54s ✅
Engine
conversation.chatgpt
Language
en-GB
Input
remind me to eat cakes at 7:00 p.m.
Response type
action_done
Prefer handling locally
true
Processed locally
false
1 Like

I’ve been working on this one… It’s… Picky. I’ve been successfully You have to set an intent up (or script) for each set date, set time etc. I’ve got basic ToDo handling but stopped as apparently there’s something coming in the Feb beta and think I’ll already need to revert some of my custom intents because of it. I wanted to wait see why changed then start back on it.

The case involves accepting anything in the input then no matter what outputting a valid datetime in local. It will take HEAVY use of the easy time template. Because try as I might I simply cant get the AI to drop a Unix time epoch in the response.

The blueprint I am hacking around with, takes the trigger slot {reminderDate} and passes it to OpenAI to reformat into a date time like so:-

   - data:
              agent_id: xyz
              text: >
                The current date and time is {{states.sensor.date.state}}
                {{states.sensor.time.state}}:00. Rewrite
                '{{trigger.slots.reminderTime}}' on '{% if
                trigger.slots.reminderDate | length >0 %} {{
                trigger.slots.reminderDate }} {%else%} {{
                states.sensor.time.date }} {%endif%}' to time format 'YYYY-MM-DD
                HH:MM:SS'.  The answer should be a datetime and must be in the
                future. In your response return exactly 19 characters of the
                datetime string in format 'YYYY-MM-DD HH:MM:SS'
            response_variable: response_from_ai

This actually works really well, if you can get the slot variable to populate accurately, which is the problem, so the local bit is letting the side down.

I then just save the response and the {reminderDescription} into a todo list:


          - alias: Save reminder in todo list
            data:
              item: "{{trigger.slots.reminderDescription}}"
              due_datetime: "{{ response_from_ai.response.speech.plain.speech }}"
            target:
              entity_id: "{{todo_list}}"
            action: todo.add_item
1 Like