I am trying to do a template sensor that has a trigger with a condition that does an action and I’m running into formatting trouble.
I have a templates.yaml this is included from configuration.yaml. Here is what I have, but I cannot figure out where to put the condition so that it only runs on Mon-Fri:
- trigger:
- trigger: time
at: "08:45:00"
condition:
- condition: time
action:
- action: google_generative_ai_conversation.generate_content
response_variable: response
data:
prompt: >-
Tell me a joke
I cannot figure out how to get the condition. I’ve been following the docs and every combination of putting a condition in gives me some kind of error.
Why are you trying to do this in a ‘template sensor with an action’ rather than using a simple automation?
You could easily add the condition there in - even in the GUI - where it would look like this:
The short answer is probably “ignorance” as I can’t figure out how to do this in an automation. What I’m doing is getting a AI response and putting that in a response variable. Then passing that variable to a rest command to do a POST as a message body. I’ve done similar things with a trigger template, but it just triggers on a simple state change, not a time trigger only on certain days.
I’m using a script to do this - probably can easily be done in an automation as well, but … see the end:
sequence:
- action: google_generative_ai_conversation.generate_content
data:
prompt: >-
Pick a A-List actor whose birthday it is today and respond with a
sentence in the following structure but do not pronounce any special
caharacters like 'asterisk'
Fun Fact for the Day - Did you know it's <Actor's Name> birthday today?
<He/She/They are turning XX years old and one of their best known roles
was in <the name of movie or TV show>
response_variable: generated_content
- data:
message: "{{ generated_content['text'] }}"
title: AI Testing
data:
ttl: 0
priority: high
action: notify.mobile_app_pixel_4a
But beware: the result might just be a hallucination; i.e. the joke might not be funny