I am attempting to use the OpenAI integration to create an image based on a prompt and display it in a card. I have followed the instructions from this page:
However, the image is not displaying. Something seems to be going wrong with my template sensor. Here is my current progress.
- Created script to call OpenAI service and store response in a variable and then fire an event with the url from the response data.
sequence:
- service: openai_conversation.generate_image
data:
size: '512'
config_entry: ***REDACTED***
prompt: race between a greyhound and cheetah on the beach
response_variable: generated_image
- event: new_openai_image
event_data:
url: '{{ generated_image.url }}'
mode: single
-
I verified that the event is firing as expected using the developer tools to listen for events at that event_name.
-
I verified that the url shown in the event is working. I see the expected image when I navigate to the url in my browser.
-
Created a template sensor using event platform, copying from the above documentation.
- trigger:
alias: "Update image when a new OpenAI image is generated"
platform: event
event_type: new_openai_image
image:
name: "OpenAI generated image"
url: "{{ trigger.event.data.url }}"
-
The configuration successfully loads and I see a new entity with the given name. When I run the script, the state of the entity updates with the time that the script was run to create a new image.
-
However, when I click to open the entity, I just see a broken image.
-
When I check the logs, I see a 403 response error.
-
Inside the error message, there are two slightly different URLs. The URL from the first half of the error message is the same as what I see from my event data. I can copy this URL into my browser and successfully see the image. But the URL listed in the second half of the error message has UTF character replacements. And if I paste it into my browser, I get the 403 error.
- Some of the / characters from the original URL are replaced with %2F in the malformed URL.
- Some of the % characters from the original URL are replaced with %25 in the malformed URL.