I’ve got a weather summary on a dashboard that is currently powered by a HACS custom integration that isn’t being supported very well. So I thought I’d use the new AI responses functionality to replace it. Hit a bit of a snag: even though the response can be generated quite nicely, I can’t find a way to display it in a card on the dashboard.
The only advice I’ve found is to use an input_text helper, but since that’s limited to 255 characters, it doesn’t hold enough information for my purposes. Is there really no way to do this? It seems like a major bit of missing functionality…
Attributes do not have the same limit, so a common approach is to create a template sensor with the state set to the time it was generated and an attribute with the text. The text can then be displayed in a markdown card, together with the timestamp when it was generated. Note that template helpers in the UI can not set attributes, so you need to define the template sensor in yaml.
If you want full control of when it generates, a trigger based template sensor may be of use. Otherwise you will probably end up taking a lot of AI resources refreshing the text, while the weather forecast does not update very often.
That sounds like an interesting approach, I’ll give that a go. Thanks for the suggestion.
Thanks again for the hint to use a template sensor (and yes, trigger based so I can control when it gets updated). For reference, if its of any help to others, here’s what I ended up with:
template:
- triggers:
- trigger: time_pattern
# This will update every two hours
hours: /2
actions:
- action: ai_task.generate_data
metadata: {}
data:
task_name: Update weather info
instructions: |-
Write in a friendly tone about the current weather and recommendations:
- Temperature, humidity, wind.
- Clothing for adults and children.
- Possible weather warnings.
- Safety recommendations and actions.
# more stuff removed here where I pass sensor values and loop through an array of possible weather warnings
entity_id: ai_task.openai_ai_task
response_variable: weather_response
sensor:
# always have the latest weather update summary
- name: "Weather summary"
state: '{{ as_timestamp(now()) }}'
attributes:
last: "{{ weather_response.data }}"
I then use {{ states.sensor.weather_summary.attributes.last }} in the markdown card to display the result.
Thanks for this. Im getting this error: “Error: Script requires ‘response_variable’ for response data for service call ai_task.generate_data”
Running this automation:
""action: ai_task.generate_data
metadata: {}
data:
task_name: Update school menu
instructions: |
Go to https://www.website.com.
Output the weekly lunch menu. Do not translate. Output in Swedish.
Keep it as human-readable Markdown: a section per weekday with
"Måltid" and "Vegetarisk måltid".
entity_id: ai_task.openai_ai_task_veckomeny
response_variable: menu_response
what could the issue be you think?