#Getting an LLM to convert time sensors to local time

1 messages · Page 1 of 1 (latest)

livid hazel
#

I know LLMs can be stubborn, but I’m pulling my hair out on this one.

I have a few sensors with bus departure times. These apparently are always provided to the assistant in ISO 8601 format with a +00:00 offset. I’ve been trying to get the LLM to convert to local time for me, but it really struggles.

It seems to ignore the instructions, even if I add instructions to double check. If I ask it to walk me through its process, it eventually figures it out.

I’ve asked it to give me improved instructions and used those, but no luck. Here’s what I have so far.


You are a helpful voice assistant for Home Assistant at a home in San Francisco, CA.

When providing responses:

* Be concise, clear, and to the point, as your replies will be used with a TTS system, and the results will be cached for reuse.
* Recognize that sensor timestamps are in UTC. ISO times for UTC are denoted by a "+00:00" or "Z" suffix. 
* The local time zone of the home is Pacific Time, which is UTC minus 8 hours, or minus 7 hours during Daylight Savings Time.
* When providing a time, always provide it in local time, accounting for Daylight Savings Time when applicable.
* Use a 12-hour format with AM or PM for exact times.
* If an event is 30 minutes or less away, provide the time as a relative duration (e.g., "in 25 minutes"). This increases the likelihood of a cache hit.
* For events more than 30 minutes away, always provide the exact time (e.g., "The next bus is at 9:15 AM").
* Always answer with a value from a sensor rather than guessing or providing one from memory. If there is no sensor, you may use your memory but you must always tell the user by stating with something like: "I'm not sure, but if I remember correctly it is..."

Answer in plain text. Be consistent in your phrasing to improve cache reusability.
Examples:

* If asked "When is the next bus?" at 8:30 AM, and the bus is at 8:32, respond with "The next bus is in 2 minutes."
* If asked "When is the next bus?" at 8:30 AM, and the bus is at 8:50 AM, respond with "The next bus is in 20 minutes."
* If asked "When is the next bus?" at 8:30 AM, and the bus is at 9:15 AM, respond with "The next bus is at 9:15 AM."

Before responding, walk through your steps again and make sure you followed these instructions.

Any tips on improving the prompt? I’m wondering if it might perform better if I make it more concise, but I thought examples would be helpful (the LLM also recommended them).

I might also stop exposing these sensors and instead template in the values I want the LLM to use with Jinja.

digital otter
#

I'd remove the asterisks from each thing you are listing, those aren't necessary and may be confusing the LLM.

#

Also depends on the LLM. For OpenAI all I had to add to have it report times in 12 hour format was "Give times in 12 hour format."

livid hazel
#

I'll give those changes a go. THe biggest issue is the time zone though. The sensor shows me bus in 10 minutes and it will say "8 hours and 10 minutes", which is weird because it seems like it is maybe considering local time when following the "use relative time when less than 30 min rule" but then giving the delta ignoring timezones anyway.

covert crest
#

I'm on the sam boat 😉

digital otter
#

Guessing timezone is set correctly in home Assistant settings? I assume so but figured I'd ask 😁

covert crest
#

The issue is that Llama sometime foget to apply rules given. And if you ask: "Did you followed rules bout time?", then llama realize his mistake (TZ not applied...)
or
from time to time he doesnt take the actual time but something else.... ( hours are wrong, minutes are wrong too )
or
If you validate a given time, he think the time will never change, and always give you the same time ....
And sometime reply with a logic like : 5h34 - 1h = 6h34 🙂 🙂

digital otter
#

Ah, yeah that isn't surprising then, the local models like llama struggle with fine-grained instructions I have noticed.

frigid wave
#

I think this

Before responding, walk through your steps again and make sure you followed these instructions.

is useless, at least with non-reasoning models. It's just text generator, it cannot "think" before it started responding, so it builds response word by word as it goes.

vital yoke
#

Seems like a lot of computing power to use when a template would be faster and 100% reliable. The LLM will consider all of those instructions with every request, even if it doesn't include a time element. So those instructions will complicate other requests.

livid hazel
livid hazel
#

I also want to add a "When is ___" sentence to the intents repo to solve this offline.

#

Refactored with a template, and that's working well. Thanks!

livid hazel
#

Since I'm building a template anyway, I just made it a sentence automation.