Mastering Home Automation: Process and Notify

· 3 min read
Mastering Home Automation: Process and Notify
Photo by Solen Feyissa / Unsplash

Today, we're diving deep into an intriguing automation that leverages OpenAI's Conversation service to process and notify users about specific events. Let's break down this automation step by step, exploring its components, dependencies, and the clever intricacies that make it work seamlessly.

Automation Overview: Process and Notify

This automation is designed to process incoming messages through OpenAI's Conversation service and then notify all connected iPhones with the response. Here's the full YAML code for the automation:

action:
- data:
    agent_id: conversation.chatgpt_butler
    language: german
    text: 'Briefly tell me that my {{ trigger.event.data.service_data.message }}.
      Always make sure that the message fits into 2 sentences.'
  metadata: {}
  response_variable: generated_response
  service: conversation.process
- else:
  - data:
      message: '{{ generated_response.response.speech.plain.speech }}'
      title: '{{ trigger.event.data.service_data.title }}'
    metadata: {}
    service: notify.all_iphones
  if:
  - condition: template
    value_template: '{{ trigger.event.data.service_data.data.actions != null }}'
  then:
  - data:
      data:
        actions: '{{ trigger.event.data.service_data.data.actions }}'
      message: '{{ generated_response.response.speech.plain.speech }}'
      title: '{{ trigger.event.data.service_data.title }}'
    metadata: {}
    service: notify.all_iphones
alias: Process and Notify
condition: []
description: ''
id: '1718614598599'
mode: single
trigger:
- event_data:
    domain: notify
    service: home_ai
  event_type: call_service
  platform: event

Breaking Down the Automation

Trigger

The automation is triggered by an event in Home Assistant. Specifically, it listens for a call to the home_ai service in the notify domain. This means that whenever a message is sent through this service, the automation kicks into action.

Actions

The actions section is where the magic happens. It consists of several steps:

  1. Processing with OpenAI's Conversation Service
- data:
    agent_id: conversation.chatgpt_butler
    language: german
    text: 'Briefly tell me that my {{ trigger.event.data.service_data.message }}.
      Always make sure that the message fits into 2 sentences.'
  metadata: {}
  response_variable: generated_response
  service: conversation.process
  • Here, the automation sends the incoming message to OpenAI's Conversation service using the conversation.chatgpt_butler agent. The message is in German, and the service is instructed to generate a brief, two-sentence response. The response is stored in the generated_response variable.
  • Condition and Notification After the response is generated, the automation decides how to notify the users based on whether additional actions are required.Basic Notification
- else:
  - data:
      message: '{{ generated_response.response.speech.plain.speech }}'
      title: '{{ trigger.event.data.service_data.title }}'
    metadata: {}
    service: notify.all_iphones
  • If no additional actions are needed, the automation sends a notification to all connected iPhones with the response from OpenAI and the title from the event data.
  • Conditional Notification with Actions
if:
- condition: template
  value_template: '{{ trigger.event.data.service_data.data.actions != null }}'
then:
- data:
    data:
      actions: '{{ trigger.event.data.service_data.data.actions }}'
    message: '{{ generated_response.response.speech.plain.speech }}'
    title: '{{ trigger.event.data.service_data.title }}'
  metadata: {}
  service: notify.all_iphones

Dependencies

OpenAI Conversation

This automation relies on OpenAI's Conversation service to process the incoming messages and generate responses. The service is invoked using the conversation.process service call with the specific agent ID conversation.chatgpt_butler.

Why This Automation is Awesome

  1. Efficiency: By using OpenAI to process messages, this automation ensures that responses are concise and to the point.
  2. Dynamic Notifications: Depending on the content of the incoming message, notifications can be simple or interactive, enhancing user engagement.
  3. Multilingual Capabilities: The automation is configured to handle German, but it can be easily adapted for other languages, making it versatile for different users.
  4. Humor Factor: Imagine receiving a witty, AI-generated response to your notifications. It adds a touch of fun to the daily routine!

This automation showcases the power of combining Home Assistant with AI services to create smart, efficient, and interactive notifications. Whether you're a tech enthusiast or just someone looking to add a bit of intelligence to your smart home, this automation is a perfect example of how AI can enhance your Home Assistant experience.

Stay tuned for more insights and tutorials on making your home smarter, one automation at a time. And remember, a little humor can go a long way in making technology more enjoyable!

Happy automating!