Hi all,
I’m relatively new to home assistant with most of my automations being built in the GUI. I’ve been trying to build an automation that does the following:
- A button is pressed as a trigger
- An AI response is generated using the Google Gemini integration using the AI task action using a response variable of AI_Task
- Copy the response to a Input Text helper
- Use the input text helper to trigger Alexa to read out the generated message
The idea is that when a button is pressed, it will generate a funny response based on my prompt and read it aloud on an Alexa device.
For some reason, I’m getting an error that says “Error rendering data template: UndefinedError: ‘ai_result’ is undefined” whenever the automation is run but I cant work out why.
With the help of Google Gemini, I’ve added a step to generate a notification which shows the AI response data and when running the automation the notification triggers and I successfully see the response. I’ve also used the actions tab in developer tools to verify the call to Gemini is working, which it is as i get the expected response back.
Would any of you kind people be able to help me understand what I’m doing wrong? YAML is as follows:
alias: AI Test
description: ""
triggers:
- type: changed_states
device_id: 2c76e3d4e8c28b80c6466d02c8d39515
entity_id: 55248869f2c5e09f827bb38edd4cdcfc
domain: light
trigger: device
conditions: []
actions:
- action: ai_task.generate_data
metadata: {}
data:
task_name: Generate Response
instructions: >-
Generate a very short and funny announcement to tell people that the
Sock and Conker Pub is now open for business. Include a funny warning
about not getting too pissed.
entity_id: ai_task.google_ai_task
response_variable: ai_result
- data:
name: AI Test
message: "{{ ai_result | default('AI task returned nothing') }}"
action: logbook.log
- data:
title: AI Result
message: >-
{{ ai_result.response | default(ai_result) | default('No response from
AI') }}
action: persistent_notification.create
- target:
entity_id: input_text.pub_open
data:
value: >-
{{ ai_result.response | default(ai_result) | default('No response from
AI') }}
action: input_text.set_value
- action: notify.alexa_media_office
data:
message: >-
{{ ai_result.response | default(ai_result) | default('No response from
AI') }}
data:
type: tts
mode: single