#required key not provided

1 messages · Page 1 of 1 (latest)

vivid sundial
#

Im trying to create an automation that records all persistent notifications to a .txt file, but i get the following error:
Triggers: required key not provided @ data[0]['trigger']
and i have no idea what it means.
code:

alias: Record every persistent notification to .txt file
triggers:
  - update_type: null
    update_typ: added
actions:
  - data:
      entity_id: notify.save_persistent_to_txt
    data_template:
      message: >-
        {{ now().strftime('%Y-%m-%d %H:%M:%S') }} {{ trigger.notification.title
        }} / {{ trigger.notification.message }}
    action: notify.send_message
sly fractal
#

Did you try running it manually?

#

Because that bypasses the triggers so really messes up any automation that depends on the trigger variable

vivid sundial
#

no, i did not, i can't even save it because of the error

marble ridge
#

Where did you get that triggers block from?

#
  - update_type: null
    update_typ: added
``` is gibberish
vivid sundial
#

Someone else helped me make it

marble ridge
#

Someone being ChatGPT?

vivid sundial
#

No hahaha but could be

#

I changed the gibberish but now it throws a new error

sly fractal
#

message: "{{ now().strftime('%Y-%m-%d %H:%M:%S ') ~ trigger.notification.title ~ ' / ' ~ trigger.notification.message }}"

marble ridge
#

Dude

#

Did you even read what was posted?

sly fractal
#

you also need to set the trigger type to be persistent_notification like the example @marble ridge gave you

marble ridge
#
  - triggers:
      - trigger: persistent_notification
                 ^^^^^^^^^^^^^^^^^^^^^^^
#

That part ain't optional

vivid sundial
#

oh snap, sorry.
So, something like this:

alias: Record every persistent notification to .txt file
- triggers:
    - trigger: persistent_notification
      platform: event
      event_type: persistent_notifications_updated
      event_data:
        update_type:
          - added
          - removed
actions:
  - data:
      entity_id: notify.save_persistent_to_txt
    data_template:
      message: >
        {{ now().strftime('%Y-%m-%d %H:%M:%S') }} - {{ trigger.event.data.title }} / {{ trigger.event.data.message }}
  - service: notify.send_message
marble ridge
#

Please step away from ChatGPT

#

Why are you not using the example from the docs?

#

Why are you randomly throwing shit into the trigger?

#

All ChatGPT is doing is feeding you crap

vivid sundial
#

I'm not using chatGPT, that's why im asking here

marble ridge
#

Then where the hell are you getting that from? Because it's not us or the docs

vivid sundial
#
sterile kindle
#
- trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: persistent_notification
      service: create
vivid sundial
#
alias: Record every persistent notification to .txt file
- triggers:
    - trigger: persistent_notification
      update_type:
        - added
        - removed
actions:
  - data:
      entity_id: notify.save_persistent_to_txt
    data_template:
      message: >
        {{ now().strftime('%Y-%m-%d %H:%M:%S') }} - {{ trigger.event.data.title }} / {{ trigger.event.data.message }}
  - service: notify.send_message

What about this? Now i used the example from the docs

marble ridge
#

Try it

marble ridge
vivid sundial
#

I dont remember exactly, i've tried some different approaches to make it work, but probably

sterile kindle
#

Just FYI... that syntax never works for me (hasn't for a while now). The one I posted is what I use in a lot of my template sensors triggers and does capture the persistent notification being created properly..

vivid sundial
#
alias: Record every persistent notification to .txt file
  - trigger: persistent_notification
    - platform: event
      event_type: call_service
      event_data:
        domain: persistent_notification
        service: create
actions:
  - data:
      entity_id: notify.save_persistent_to_txt
    data_template:
      message: >
        {{ now().strftime('%Y-%m-%d %H:%M:%S') }} - {{ trigger.event.data.title }} / {{ trigger.event.data.message }}
  - service: notify.send_message

something like this?

sterile kindle
#

trigger.event.data.service_data.title and trigger.event.data.service_data.message.

#

This is how I do it in my template trigger:

- trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: persistent_notification
      service: create
  sensor:
    - name: Bill Sleep Report
      state: "{{ now() }}"
      attributes:
        title: >-
          {% if trigger.event.data.service_data.notification_id|default(0) == 'bill_sleep_report' %}
          {{ trigger.event.data.service_data.title }}
          {% else %}
          {{ this.attributes.title | default("") }}
          {% endif %}
        message: >-
          {% if trigger.event.data.service_data.notification_id|default(0) == 'bill_sleep_report' %}
          {{ trigger.event.data.service_data.message }}
          {% else %}
          {{ this.attributes.message | default("") }}
          {% endif %}
        notification_id: >-
          {{ trigger.event.data.service_data.notification_id }}
#

(Could be cleaner, but I was in a hurry)

vivid sundial
#

i'm sorry but i'm not sure how to proceed with this

sterile kindle
#

Are you doing this in the UI or YAML?

vivid sundial
#

UI

sterile kindle
#
description: ""
alias: Record every persistent notification to .txt file
mode: single
triggers:
  - trigger: event
    event_type: call_service
    event_data:
      domain: persistent_notification
      service: create
conditions: []
actions:
  - action: notify.send_message
    metadata: {}
    data:
      message: >-
        {{ now().strftime('%Y-%m-%d %H:%M:%S') }} - {{
        trigger.event.data.service_data.title }} / {{
        trigger.event.data.service_data.message }}
    target:
      entity_id: notify.save_persistent_to_txt
#

Paste that into your automation and you should be good.

vivid sundial
#

nice, thank you so much!
Why did you ask me whether it was UI or YAML? I mean, it's YAML regardless right? So what's the difference?

sterile kindle
#

Because a lot of people will say that it can't be done in the UI. So, I try to match what they are using in case they ask "how". 🙂