Could you share a trace from an occurrence where it used the wrong date?
Conversation from today, Jan 6th. Using OpenAI and OpenWeatherMap.
Request: What is the weather forecast for Wednesday?
Response: The weather forecast for Wednesday, January 10, 2025, is snowy with a high temperature of 26°F and a low of 18°F. The wind speed will be 8 mph, and the humidity will be around 66%. There is a 20% chance of precipitation.
Script trace:
{
"trace": {
"last_step": "sequence/3",
"run_id": "e9d2ec0b0edef5ed771d6850b73a8a01",
"state": "stopped",
"script_execution": "finished",
"timestamp": {
"start": "2025-01-06T17:55:42.442290+00:00",
"finish": "2025-01-06T17:55:42.445640+00:00"
},
"domain": "script",
"item_id": "weather_forecast_for_llm",
"trace": {
"sequence/0": [
{
"path": "sequence/0",
"timestamp": "2025-01-06T17:55:42.442782+00:00",
"changed_variables": {
"this": {
"entity_id": "script.weather_forecast_for_llm",
"state": "off",
"attributes": {
"last_triggered": "2025-01-06T17:54:57.231192+00:00",
"mode": "parallel",
"current": 0,
"max": 10,
"icon": "mdi:weather-partly-rainy",
"friendly_name": "Weather Forecast for LLM"
},
"last_changed": "2025-01-06T17:54:57.234240+00:00",
"last_reported": "2025-01-06T17:54:57.234240+00:00",
"last_updated": "2025-01-06T17:54:57.234240+00:00",
"context": {
"id": "01JGYC2QZ9H583KR0W3W04FQAB",
"parent_id": null,
"user_id": "fc1e2afd1a6f41a2b487ed85885bcacb"
}
},
"start_of_period": "2025-01-10T00:00:00",
"end_of_period": "2025-01-10T23:59:59",
"context": {
"id": "01JGYC45BS01NKE5TSHAD2T6QW",
"parent_id": null,
"user_id": "fc1e2afd1a6f41a2b487ed85885bcacb"
},
"version": 1.1,
"weather_entity": "weather.openweathermap",
"start": "2025-01-10T00:00:00-06:00",
"end": "2025-01-10T23:59:59-06:00",
"full_days": true
}
}
],
"sequence/1": [
{
"path": "sequence/1",
"timestamp": "2025-01-06T17:55:42.443405+00:00",
"changed_variables": {
"weather_response": {
"weather.openweathermap": {
"forecast": [
{
"datetime": "2025-01-06T17:00:00+00:00",
"condition": "cloudy",
"temperature": 26,
"templow": 18,
"pressure": 30.24,
"cloud_coverage": 88,
"wind_speed": 14.7,
"wind_bearing": 353,
"uv_index": 1.09,
"precipitation_probability": 14,
"precipitation": 0,
"dew_point": 19,
"wind_gust_speed": 33.96,
"humidity": 74
},
{
"datetime": "2025-01-07T17:00:00+00:00",
"condition": "cloudy",
"temperature": 25,
"templow": 15,
"pressure": 30.45,
"cloud_coverage": 100,
"wind_speed": 8.99,
"wind_bearing": 316,
"uv_index": 0.91,
"precipitation_probability": 0,
"precipitation": 0,
"dew_point": 4,
"wind_gust_speed": 17.05,
"humidity": 47
},
{
"datetime": "2025-01-08T17:00:00+00:00",
"condition": "cloudy",
"temperature": 22,
"templow": 14,
"pressure": 30.36,
"cloud_coverage": 75,
"wind_speed": 7.38,
"wind_bearing": 296,
"uv_index": 0.87,
"precipitation_probability": 0,
"precipitation": 0,
"dew_point": 3,
"wind_gust_speed": 13.35,
"humidity": 50
},
{
"datetime": "2025-01-09T17:00:00+00:00",
"condition": "sunny",
"temperature": 28,
"templow": 15,
"pressure": 30.33,
"cloud_coverage": 8,
"wind_speed": 7.31,
"wind_bearing": 205,
"uv_index": 1.25,
"precipitation_probability": 0,
"precipitation": 0,
"dew_point": -5,
"wind_gust_speed": 15.39,
"humidity": 28
},
{
"datetime": "2025-01-10T17:00:00+00:00",
"condition": "snowy",
"temperature": 26,
"templow": 18,
"pressure": 30.15,
"cloud_coverage": 100,
"wind_speed": 7.54,
"wind_bearing": 207,
"uv_index": 2,
"precipitation_probability": 20,
"precipitation": 0.01,
"dew_point": 14,
"wind_gust_speed": 17.31,
"humidity": 66
},
{
"datetime": "2025-01-11T18:00:00+00:00",
"condition": "snowy",
"temperature": 30,
"templow": 19,
"pressure": 29.94,
"cloud_coverage": 27,
"wind_speed": 4.92,
"wind_bearing": 194,
"uv_index": 2,
"precipitation_probability": 20,
"precipitation": 0,
"dew_point": 18,
"wind_gust_speed": 13.15,
"humidity": 68
},
{
"datetime": "2025-01-12T18:00:00+00:00",
"condition": "cloudy",
"temperature": 29,
"templow": 21,
"pressure": 30.09,
"cloud_coverage": 87,
"wind_speed": 5.21,
"wind_bearing": 217,
"uv_index": 2,
"precipitation_probability": 0,
"precipitation": 0,
"dew_point": 19,
"wind_gust_speed": 9.64,
"humidity": 67
},
{
"datetime": "2025-01-13T18:00:00+00:00",
"condition": "snowy",
"temperature": 30,
"templow": 21,
"pressure": 30.15,
"cloud_coverage": 66,
"wind_speed": 8.37,
"wind_bearing": 307,
"uv_index": 2,
"precipitation_probability": 20,
"precipitation": 0.01,
"dew_point": 20,
"wind_gust_speed": 12.21,
"humidity": 67
}
]
}
}
},
"result": {
"params": {
"domain": "weather",
"service": "get_forecasts",
"service_data": {
"type": "daily",
"entity_id": [
"weather.openweathermap"
]
},
"target": {
"entity_id": [
"weather.openweathermap"
]
}
},
"running_script": false
}
}
],
"sequence/2": [
{
"path": "sequence/2",
"timestamp": "2025-01-06T17:55:42.444350+00:00",
"changed_variables": {
"response": {
"averaged_weather_data_for_period": {
"start_of_period": "2025-01-10T00:00:00-06:00",
"end_of_period": "2025-01-10T23:59:59-06:00",
"condition": "snowy",
"temperature": 26,
"templow": 18,
"pressure": 30,
"cloud_coverage": 100,
"wind_speed": 8,
"wind_bearing": 207,
"uv_index": 2,
"precipitation_probability": 20,
"precipitation": 0,
"dew_point": 14,
"wind_gust_speed": 17,
"humidity": 66
}
}
}
}
],
"sequence/3": [
{
"path": "sequence/3",
"timestamp": "2025-01-06T17:55:42.445421+00:00",
"result": {
"stop": "",
"error": false
}
}
]
},
"config": {
"mode": "parallel",
"max_exceeded": "silent",
"description": "Fetches the weather forecast for either a part of a day, or one or more full days. In case the weather for the weekend is requested, this means Saturday and Sunday",
"fields": {
"start_of_period": {
"selector": {
"datetime": null
},
"name": "Start of period",
"description": "Start of the period for which the weather is requested. use an isoformat datetime string.",
"required": true
},
"end_of_period": {
"selector": {
"datetime": null
},
"name": "End of period",
"description": "End of the period for which the weather is requested. use an isoformat datetime string.",
"required": true
}
},
"sequence": [
{
"variables": {
"version": 1.1,
"weather_entity": "weather.openweathermap",
"start": "{{ (start_of_period | as_datetime | as_local).isoformat() }}",
"end": "{% set start = as_datetime(start) %} {% set day = start.time() == today_at().time() %} {% set delta = timedelta(days=1 if day else 0, hours=0 if day else 1) %} {{ (end_of_period | as_datetime(default=start+delta) | as_local).isoformat() }}\n",
"full_days": "{% set start = start | as_datetime %} {% set end = end | as_datetime %} {{\n start.time() == today_at().time()\n and ((end - start).total_seconds() / 3600) | round | int % 24 in [23, 0, 1]\n}}\n"
}
},
{
"action": "weather.get_forecasts",
"data": {
"type": "{{ 'daily' if full_days else 'hourly' }}"
},
"target": {
"entity_id": "weather.openweathermap"
},
"response_variable": "weather_response"
},
{
"variables": {
"response": {
"averaged_weather_data_for_period": "{% set weather_data = weather_response[weather_entity].forecast\n | selectattr('datetime', '>=', start)\n | selectattr('datetime', '<', end)\n | list\n%} {% set ns = namespace(combined={}) %} {% for item in weather_data[0].keys() | reject('eq', 'datetime')%}\n {% set combine = weather_data | map(attribute=item) | list %}\n {% set combine = combine | statistical_mode if combine[0] is string else combine | average | round %}\n {% set ns.combined = dict(ns.combined, **{item: combine}) %}\n{% endfor %} {{ dict(start_of_period=start, end_of_period=end, **ns.combined) }}\n"
}
}
},
{
"stop": "",
"response_variable": "response"
}
],
"alias": "Weather Forecast for LLM",
"icon": "mdi:weather-partly-rainy"
},
"blueprint_inputs": {
"alias": "Weather Forecast for LLM",
"use_blueprint": {
"path": "TheFes/fetch_weather_forecast_by_llm.yaml",
"input": {
"weather_entity": "weather.openweathermap"
}
},
"description": "Fetches the weather forecast for either a part of a day, or one or more full days. In case the weather for the weekend is requested, this means Saturday and Sunday",
"icon": "mdi:weather-partly-rainy"
},
"context": {
"id": "01JGYC45BS01NKE5TSHAD2T6QW",
"parent_id": null,
"user_id": "fc1e2afd1a6f41a2b487ed85885bcacb"
}
},
"logbookEntries": [
{
"state": "on",
"entity_id": "script.weather_forecast_for_llm",
"icon": "mdi:weather-partly-rainy",
"when": 1736186142.4425197,
"context_user_id": "fc1e2afd1a6f41a2b487ed85885bcacb"
},
{
"state": "off",
"entity_id": "script.weather_forecast_for_llm",
"icon": "mdi:weather-partly-rainy",
"when": 1736186142.445523,
"context_user_id": "fc1e2afd1a6f41a2b487ed85885bcacb",
"context_state": "on",
"context_entity_id": "script.weather_forecast_for_llm"
}
]
}
That’s weird, why does it take the 10th of January for Wednesday. What do you get when you ask it which date it will be next Wednesday
Apparently both Gemini and OpenAI suck at it.
When I ask Gemini which date it will be next Wednesday it will give 2025-01-15, which is actually a Wednesday, but not the next one.
ChatGPT also gives the 10th of January for me, which doesn’t make sense
At least it’s not the script
Is there a way to automate updating the OpenAI system prompt? That way the prompt could contain the correct dates for all days of the week and increase the chance it gets it right?
I modified the OpenAI service instructions to include a template with 7 days of dates and days of the week. In my limited testing so far, it seems to significantly improve the ability of ChatGPT to get the correct date from a day of the week.
You are a voice assistant for Home Assistant.
Answer questions about the world truthfully.
Answer in plain text. Keep it simple and to the point. Do not use lists or bullet points.
Use the following information when answering questions related to weather forecasts. If a date is not specified in the request, provide the weather forecast for today.
Today is {{ now().strftime('%A %Y-%m-%d') }}
Tomorrow is {{ (now() + timedelta(days=1)).strftime('%A %Y-%m-%d') }}
{% for dayoffsets in [2, 3, 4, 5, 6] -%}
{{ (now() + timedelta(days=dayoffsets)).strftime('%A') }} is {{ (now() + timedelta(days=dayoffsets)).strftime('%Y-%m-%d') }}
{% endfor %}
Yes, this was something I wanted to test myself as well. Good to hear it helps.
This does mean that you are sending this information with every conversation you have with ChatGPT, so it will increase your token usage.
Stupid question, but I didn’t see it in the initial instructions, but do I need to manually set the start date in the script for this to work?
The idea is that the LLM runs the script, you don’t have to set the start and end manually. Why would you want to set it manually?
You can run it in developer tools > actions, and then you will see the same input parameters as the LLM should use.
Or you can search for the script using the icon in the header bar
I was just trying to troubleshoot as I am having the same issue as above, where the LLM (in this case Ollama/Qwen) tells me that it doesn’t have real time access and the script is never being triggered.
Full disclosure, for some odd reason, I could never save the blueprint script. So I took the script and saved it in my script yaml. The only thing I changed (after putting in weather provider) was the name (I included the description from the initial post)
That should work as well, that’s how I initially tested it.
What is the YAML of the script you now have? And you did expose that script to Assist right?
llm_forecast:
description: >-
Fetches the weather forecast for either a part of a day, or one or more full days. In case the weather for the weekend is requested, this means Saturday and Sunday
mode: parallel
max_exceeded: silent
fields:
start_of_period:
selector:
datetime: null
name: Start of period
description: >-
Start of the period for which the weather is requested. use an isoformat
datetime string.
required: true
end_of_period:
selector:
datetime: null
name: End of period
description: >-
End of the period for which the weather is requested. use an isoformat
datetime string.
required: true
sequence:
- variables:
version: 1.2
weather_entity: weather.forecast_indian_ln1_media_pa
start: "{{ (start_of_period | as_datetime | as_local).isoformat() }}"
end: >
{% set start = as_datetime(start) %} {% set day = start.time() ==
today_at().time() %} {% set delta = timedelta(days=1 if day else 0,
hours=0 if day else 1) %} {% set end = end_of_period |
as_datetime(default=start+delta) | as_local %} {{ (end if end > start
else start + delta).isoformat() }}
full_days: >
{% set start = start | as_datetime %} {% set end = end | as_datetime %}
{{
start.time() == today_at().time()
and ((end - start).total_seconds() / 3600) | round | int % 24 in [23, 0, 1]
}}
- action: weather.get_forecasts
data:
type: "{{ 'daily' if full_days else 'hourly' }}"
target:
entity_id: weather.forecast
response_variable: weather_response
- variables:
response:
averaged_weather_data_for_period: >
{% set weather_data = weather_response[weather_entity].forecast
| selectattr('datetime', '>=', start)
| selectattr('datetime', '<', end)
| list
%} {% set ns = namespace(combined={}) %} {% for item in
weather_data[0].keys() | reject('eq', 'datetime')%}
{% set combine = weather_data | map(attribute=item) | list %}
{% set combine = combine | statistical_mode if combine[0] is string else combine | average | round %}
{% set ns.combined = dict(ns.combined, **{item: combine}) %}
{% endfor %} {{ dict(start_of_period=start, end_of_period=end,
**ns.combined) }}
- stop: ""
response_variable: response
alias: LLM Forecasts
Here is my script, and yes I did expose to Assist and gave it an alias of Forecast
Does it work if you run it in developer tools > actions?
I get a reponse from running it in Actions if I set the start and end date. If i only set the start date, I get an error
Which error do you get in that case?
It tells me that end date is required
You can set required: false
for that field
Hmm still gives me an error. Says end_petiod is undefined (this is still through actions)
Change the definition for the end
variable in the script to this
end: >
{% set start = as_datetime(start) %}
{% set day = start.time() == today_at().time() %}
{% set delta = timedelta(days=1 if day else 0, hours=0 if day else 1) %}
{% set end = end_of_period | default(start) | as_datetime(default=start+delta) | as_local %}
{{ (end if end > start else start + delta).isoformat() }}