#Help needed to get AI Notifaction Text stored for Dashboard use

1 messages ยท Page 1 of 1 (latest)

fossil elm
#

I Made a Forum Post for my question here

https://community.home-assistant.io/t/help-needed-to-get-ai-notification-text-stored-for-dashboard-use/787256

But i thought i could Help to promote it Here too

ripe kite
#

I use a template sensor for this and store the response as an attribute.

- trigger:
  - platform: homeassistant
    event: start
  - platform: time_pattern
    hours: "0"
  action:
    - action: google_generative_ai_conversation.generate_content
      data:
        prompt: Generate a funny, sarcastic descrption of New Year's Eve. Do not include the name of the holiday in the response and generate a single response only. You can use markdown formatting and emojis in the response.
      response_variable: output
  sensor:
    - name: New Years Eve Description
      state: "{{ now() }}"
      attributes:
        message: "{{ iif('text' in output, output['text'], 'Error Generating Response') }}"
#

Then in the frontend, I use this template: {{ state_attr('sensor.new_years_eve_description', 'message') }}.

deft surge
raw scaffoldBOT
sour bronze
#

Yes, under template: as shown in the docs there

deft surge
sour bronze
#

That looks ... broken

#
    - trigger:
``` is empty - doing nothing
#

Whatever you did that was "needed", that wasn't it

deft surge
sour bronze
#
  - platform: homeassistant
    event: start
``` old style
```yaml
  - trigger: homeassistant
    event: start
``` new style
#

The YAML syntax changed with 2024.9 and 2024.10

deft surge
#

hmmm, so now I am lost. If I remove the one trigger line item, I get errors.

Configuration errors
Error loading /config/configuration.yaml: while parsing a block collection
  in "/config/configuration.yaml", line 322, column 3
expected <block end>, but found '?'
  in "/config/configuration.yaml", line 327, column 3

This is what I have to get the error above:

template:
  - trigger:
  - platform: homeassistant
    event: start
  - platform: time_pattern
    hours: "0"
  action:
    - action: google_generative_ai_conversation.generate_content
      data:
        prompt: Generate a funny, sarcastic descrption of New Year's Eve. Do not include the name of the holiday in the response and generate a single response only. You can use markdown formatting and emojis in the response.
      response_variable: output
  sensor:
    - name: New Years Eve Description
      state: "{{ now() }}"
      attributes:
        message: "{{ iif('text' in output, output['text'], 'Error Generating Response') }}"
#

oops sorry, template: starts it off

sour bronze
#

Share the whole thing correctly then ๐Ÿ˜‰

#

Help us help you

#

(don't forget you can edit posts)

deft surge
#

edited my comment. Sorry

sour bronze
#

You haven't fixed the code yet

deft surge
#

OY!

sour bronze
#

oops sorry, template: starts it off

#

Again though, - trigger: isn't valid

#

Remove that line

deft surge
#

There.. my copy and paste didn't paste the edit, it pasted the same incorrect yaml..it's fixed now.

#

I removed the 2nd trigger line item and I get invalid config again..

Configuration errors
Error loading /config/configuration.yaml: while parsing a block collection
  in "/config/configuration.yaml", line 322, column 3
expected <block end>, but found '?'
  in "/config/configuration.yaml", line 326, column 3

This is what is in my config:

template:
  - platform: homeassistant
    event: start
  - platform: time_pattern
    hours: "0"
  action:
    - action: google_generative_ai_conversation.generate_content
      data:
        prompt: Generate a funny, sarcastic descrption of New Year's Eve. Do not include the name of the holiday in the response and generate a single response only. You can use markdown formatting and emojis in the response.
      response_variable: output
  sensor:
    - name: New Years Eve Description
      state: "{{ now() }}"
      attributes:
        message: "{{ iif('text' in output, output['text'], 'Error Generating Response') }}"
sour bronze
#

What's line 322?

#

What's line 326?

deft surge
#

322:

  • platform: homeassistant
    326:
    action:
sour bronze
#

Sounds like you've got errors above

raw scaffoldBOT
#

Please use a code share site to share code or logs, for example:

Please don't use Pastebin, since it can randomly add spaces to the main view. Please also don't share text as images since it makes it harder for people to help you. Remember that others may have colour blindness, impaired vision, etc.

sour bronze
#

Please share the whole file with one of those

deft surge
#

My whole config file?? I have access codes etc. in it.

raw scaffoldBOT
#

Rather than putting sensitive information (passwords, locations, etc) into your configuration, you can store them in secrets to make sharing easier.

sour bronze
#

The problem is somewhere above line 322

deft surge
sour bronze
#

Ah... hang on

#

Your lack of YAML-fu is the problem

deft surge
#

-fu? Ya, I'm still learning.

sour bronze
#
template:
  - trigger:
      - trigger: webhook
        webhook_id: my-super-secret-webhook-id
    sensor:
#

From the docs

deft surge
#

That's what I had

sour bronze
#
template:
- trigger:
  - platform: homeassistant
    event: start
  - platform: time_pattern
    hours: "0"
  action:
    - action: google_generative_ai_conversation.generate_content
      data:
        prompt: Generate a funny, sarcastic descrption of New Year's Eve. Do not include the name of the holiday in the response and generate a single response only. You can use markdown formatting and emojis in the response.
      response_variable: output
  sensor:
    - name: New Years Eve Description
      state: "{{ now() }}"
      attributes:
        message: "{{ iif('text' in output, output['text'], 'Error Generating Response') }}"
``` quick fix (line two)
deft surge
#

with no errors

sour bronze
#

You said

template:
  - trigger:
  - platform: homeassistant
#

That's not the same

deft surge
#

No, I said I added the extra trigger line item:

template:
  - trigger:
    - trigger:
    - platform: homeassistant
      event: start
    - platform: time_pattern
      hours: "0"

And that's when you said no, I shouldn't have it. But it's okay. Glad to get this working!! I do appreciate your help though!

sour bronze
#

I can only go by what you share, not what you meant to share ๐Ÿ˜‰

deft surge
#

That gives me config errors..

sour bronze
#

Because it's not valid

deft surge
#

This is what I had when I posted about adding the second trigger, and I don't get any errors... if this is wrong, what part do I edit?

template:
  - trigger:
    - trigger:
    - platform: homeassistant
      event: start
    - platform: time_pattern
      hours: "0"
    action:
      - action: google_generative_ai_conversation.generate_content
        data:
          prompt: Generate a funny, sarcastic descrption of New Year's Eve. Do not include the name of the holiday in the response and generate a single response only. You can use markdown formatting and emojis in the response.
        response_variable: output
    sensor:
      - name: New Years Eve Description
        state: "{{ now() }}"
        attributes:
          message: "{{ iif('text' in output, output['text'], 'Error Generating Response') }}"
sour bronze
#

That isn't wrong, but that's also not what you shared before...

deft surge
#

I may not have shared the whole yaml because I didn't think it was important to the conversation because all I said was, that I added the extra "trigger" line item.

sour bronze
#

And that extra line wasn't valid, and wasn't needed

#
template:
  - trigger:
    - trigger:
    - platform: homeassistant
      event: start
``` โŒ
#
template:
  - trigger:
    - platform: homeassistant
      event: start
``` โœ…
deft surge
#

Thank you!

#

PS: I did try your suggested edit earlier at 10:22am, and received config errors, but it was because of indentation at that time. Had I indented the platform line, we wouldn't have gone down this rabbit hole. Sorry for my oversight.

deft surge
#

@light hatch In your commend back on Oct 27th, you stated:

Then in the frontend, I use this template:

{{ state_attr('sensor.new_years_eve_description', 'message') }}

How do I use this in my frontend? Do you have an example?

ripe kite
#

Pop that into a markdown card. Thats what I do.