Hi everyone,
I’m hoping someone can help me figure out a persistence issue with a daily AI image generator script I put together.
Right now, I have a working script that generates a daily AI image of a historic event using ai_task.generate_data and ai_task.generate_image. I am displaying this image on my dashboard using a trigger-based template image entity. It’s basically exactly what is shown in the official HA docs for weather visualization.
The Problem: Everything works perfectly when the script runs. However, because it relies on a triggered event, the image (and the template entity state) is completely lost every time I restart Home Assistant.
What I’ve Tried: I tried to save the generated_image.url to an input_text helper so I could restore or reference it upon restart. Unfortunately, this fails because the generated AI image URLs are incredibly long and exceed the 255-character limit of input_text entities.
Here is the script I am currently using:
alias: Historic AI Image
description: >-
Generates a daily AI image of a historical event with explanation, stores
result in helpers and fires event for dashboard display.
sequence:
- action: ai_task.generate_data
data:
instructions: >-
Today is {{ now().strftime('%B %d') }}. Find a fascinating, surprising,
or significant historical event that happened on this exact day in
history — from any field such as science, exploration, art, music,
sports, politics, technology, or nature. It is extremly important that
its accurate and it actually happend on that day.
Also create a vivid image generation prompt for this event. Choose a
creative and fitting art style (e.g. watercolor painting, oil painting,
pencil sketch, comic book style, impressionist, art nouveau, woodblock
print, charcoal drawing, stained glass, linocut, mosaic) — vary the
style for visual diversity.
The image must:
- Capture the most dramatic or emotionally powerful moment of the event
- Incorporate the date, year, and location visually into the composition
- Be visually rich and detailed
IMPORTANT: The title and description MUST be written in German. The
image_prompt should remain in English.
structure:
description:
description: >-
Engaging 1-2 sentence description of the event in German, max 200
characters
required: true
selector:
text: {}
image_prompt:
description: >-
Detailed vivid image generation prompt in English including art
style, scene details, colors, composition, and date/location
integration
required: true
selector:
text: {}
title:
description: Short event title in German, max 60 characters
required: true
selector:
text: {}
task_name: Historic event research
entity_id: ai_task.gemini_3_1_pro
response_variable: event_info
- action: ai_task.generate_image
data:
entity_id: ai_task.google_ai_task_images
instructions: "{{ event_info.data.image_prompt }}"
task_name: Generate AI Image of Historic Event
response_variable: generated_image
- event: historic_ai_image_generated
event_data:
url: "{{ generated_image.url }}"
title: "{{ event_info.data.title }}"
description: "{{ event_info.data.description }}"
- action: input_text.set_value
data:
entity_id: input_text.historic_event_title
value: "{{ event_info.data.title }}"
- action: input_text.set_value
data:
entity_id: input_text.historic_event_description
value: "{{ event_info.data.description }}"
- action: input_text.set_value
data:
entity_id: input_text.historic_event_image_url
value: "{{ generated_image.url.split('?')[0] }}"
This is what my template.yaml looks like:
- trigger:
- alias: "Update image when a new historic image is generated"
trigger: event
event_type: historic_ai_image_generated
image:
- name: "Historic AI generated image of Today"
unique_id: historic_ai_image_today
url: "http://localhost:8123{{ trigger.event.data.url }}"
Has anyone found a clever workaround to keep these trigger-based AI images visible after a reboot? Is there a better way to store long URLs, or a simple way to actually download/save the image file locally to the www folder as part of the script?
Thanks in advance for any advice!
Regards
Stefan
