Zum Inhalt

Beispiele und Anwendungsfälle

Alle Beispiele stammen aus dem Ordner examples/. Jede Karte unten wird in ein echtes Home Assistant geladen und automatisch fotografiert, jede Automation wird geladen und geprüft, Code und Bild passen also immer zusammen. Die Beispiele verwenden die Entitäts-IDs einer englischen Systemsprache, z. B. sensor.ai_briefing_bedroom.

Anwendungsfälle

Anwendungsfall Umsetzung
Wanddisplay oder Tablet im Flur oder in der Küche Eine Markdown-Karte mit dem Attribut markdown, siehe Dashboard. Ein Intervall von 30 oder 60 Minuten hält es aktuell; unveränderte Daten rufen die KI nicht auf.
TTS nach dem Wecker Eine Automation ruft ai_briefing.generate auf und gibt briefing.plain_text an tts.speak weiter, siehe Vorlesen.
Push-Nachricht aufs Handy Eine Automation schickt plain_text über die Companion-App, siehe Push-Nachricht.

Dashboard

Briefing mit Uhrzeit der Erzeugung

Briefing mit Uhrzeit Briefing mit Uhrzeit

# Briefing with the time it was generated
type: markdown
content: >-
  {{ state_attr('sensor.ai_briefing_bedroom', 'markdown') }}

  <font size="1" color="gray">{{ as_timestamp(state_attr('sensor.ai_briefing_bedroom', 'generated_at')) | timestamp_custom('%H:%M') }}</font>

Briefing mit Button zum erneuten Erzeugen

Briefing mit Button Briefing mit Button

# Briefing plus a button to generate it again
type: vertical-stack
cards:
  - type: markdown
    content: "{{ state_attr('sensor.ai_briefing_linda', 'markdown') }}"
  - type: button
    entity: button.ai_briefing_linda_generate
    name: Generate again
    show_state: false
    tap_action:
      action: toggle

Reiner Text ohne Kartenrahmen

Eine Begrüßung oben auf einem Wanddisplay:

Reiner Text Reiner Text

# Plain variant without a card frame, e.g. as a greeting at the top of a dashboard
type: markdown
text_only: true
content: "{{ state_attr('sensor.ai_briefing_bedroom', 'markdown') }}"

Mit text_only: true blendet die Karte Rahmen und Hintergrund aus, sodass Überschrift und Fließtext frei oben auf dem Dashboard stehen.

Diagnose: Datenblock und Prompt

Diagnose Diagnose

# Diagnostics: read the data block and the prompt
# "Check data block" rebuilds both without calling the AI. Enable the button
# and the prompt sensor first, they are disabled by default.
type: vertical-stack
cards:
  - type: entities
    entities:
      - button.ai_briefing_bedroom_check_data_block
      - sensor.ai_briefing_bedroom_last_run
  - type: markdown
    title: Data block
    content: >-
      ```text

      {{ state_attr('sensor.ai_briefing_bedroom_prompt', 'data_block') }}

      ```
  - type: markdown
    title: Full prompt
    content: >-
      ```text

      {{ state_attr('sensor.ai_briefing_bedroom_prompt', 'prompt') }}

      ```

Automationen

Vorlesen

Das Briefing an Wochentagen morgens erzeugen und vorlesen:

# Generate the briefing every weekday morning and read it out loud
- alias: Read morning briefing aloud
  triggers:
    - trigger: time
      at: "07:00:00"
  conditions:
    - condition: time
      weekday: [mon, tue, wed, thu, fri]
  actions:
    - action: ai_briefing.generate
      target:
        entity_id: sensor.ai_briefing_bedroom
      response_variable: briefing
    - action: tts.speak
      target:
        entity_id: tts.home_assistant_cloud
      data:
        media_player_entity_id: media_player.bedroom_speaker
        # plain_text has no Markdown or emojis, ready for text-to-speech
        message: "{{ briefing.plain_text }}"

Oder fünf Minuten nach dem Wecker eines Handys mit der Home-Assistant-Companion-App (Android liefert den Sensor für den nächsten Wecker):

# Read Linda's briefing aloud five minutes after the alarm of her phone
# (next alarm sensor of the Home Assistant Companion app)
- alias: Read Linda's briefing after the alarm
  triggers:
    - trigger: time
      at:
        entity_id: sensor.lindas_phone_next_alarm
        offset: "00:05:00"
  actions:
    - action: ai_briefing.generate
      target:
        entity_id: sensor.ai_briefing_linda
      response_variable: briefing
    - action: tts.speak
      target:
        entity_id: tts.home_assistant_cloud
      data:
        media_player_entity_id: media_player.bedroom_speaker
        message: "{{ briefing.plain_text }}"

Beide nutzen briefing.plain_text, damit Überschriften-Rauten, Fettdruck-Sternchen und Emojis nicht mit vorgelesen werden. Erzeugen auf Abruf ruft die KI immer auf; um Aufrufe zu sparen, lies stattdessen den vorhandenen Text mit state_attr('sensor.ai_briefing_bedroom', 'plain_text').

Push-Nachricht

Jeden neuen Text aufs Handy schicken:

# Send every new briefing for Linda as a push notification
- alias: Send Linda's briefing to her phone
  triggers:
    # "to: null" ignores changes of attributes only, e.g. a new last_error
    - trigger: state
      entity_id: sensor.ai_briefing_linda
      to: null
  conditions:
    # No notification when the text is restored after a restart
    - condition: template
      value_template: >-
        {{ trigger.from_state is not none
           and trigger.from_state.state not in ['unknown', 'unavailable']
           and trigger.to_state.state not in ['unknown', 'unavailable'] }}
  actions:
    - action: notify.mobile_app_lindas_phone
      data:
        title: AI Briefing
        message: "{{ trigger.to_state.attributes.plain_text }}"