Skip to content

Commit

Permalink
Lots of troubleshooting and stuff related to OpenAI #1368
Browse files Browse the repository at this point in the history
  • Loading branch information
CCOSTAN committed Jul 24, 2024
1 parent 6a1c81c commit ca3b3b3
Show file tree
Hide file tree
Showing 12 changed files with 5,608 additions and 107 deletions.
2 changes: 1 addition & 1 deletion config/.HA_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024.8.0.dev202407020219
2024.8.0.dev202407200219
2 changes: 1 addition & 1 deletion config/automation/Speech/announcements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
personarriving: >
{% set person = expand('group.arriving')|map(attribute='name')|join(' and ') %}
{%- macro greeting_sentence(person) -%}
{{ ["[Welcome " ~ person + " home]"] }}
{{"[Welcome " + person + " home]" }}
{%- endmacro -%}
{{greeting_sentence(person)}}
Expand Down
2 changes: 1 addition & 1 deletion config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ group: !include_dir_merge_named group
sensor: !include_dir_merge_list sensor
automation: !include_dir_merge_list automation
scene: !include_dir_merge_list scene
switch: !include_dir_merge_list switch
# switch: !include_dir_merge_list switch
script: !include_dir_merge_named script
input_boolean: !include_dir_merge_named input_boolean
shell_command: !include_dir_merge_named shell_command
39 changes: 0 additions & 39 deletions config/packages/speech_helper_sensors.yaml.disabled

This file was deleted.

34 changes: 23 additions & 11 deletions config/packages/triggers/last_message.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,34 @@ homeassistant:
input_boolean.lastmsg:
friendly_name: 'Repeat Message'
icon: mdi:repeat-once



#-------------------------------------------
input_boolean:
lastmsg:
name: Last Message
initial: off
#-------------------------------------------
mqtt:
sensor:
- state_topic: "polly/lastmsg"
name: "Last Message"

- state_topic: "polly/lastmsg_openai"
name: "Last AI Message"


template:
- trigger:
platform: event
event_type: openai_instructions_sent
sensor:
- name: "OpenAI"
state: "{{now()}}"
attributes:
instructions: "{{ trigger.event.data.instructions }}"

- trigger:
platform: event
event_type: openai_response
sensor:
- name: "OpenAI"
state: "{{now()}}"
attributes:
response: "{{ trigger.event.data.response }}"


##############################################################################
### Automations -
##############################################################################
Expand All @@ -46,7 +58,7 @@ automation:
options:
voice: JennyNeural
message: >-
{{states.sensor.last_ai_message.state}}
"{{ state_attr('sensor.openai', 'response') }}"
cache: false

- service: input_boolean.turn_off
Expand Down
38 changes: 17 additions & 21 deletions config/packages/neato.yaml → config/packages/vacuum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,61 @@
# @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# Neato Support for D7 Connected Botvac - control my [Neato Vacuum](https://amzn.to/2kqnnqu) with Home Assistant.
# Switched from Neato to Dreame Vacuum - https://amzn.to/4f7NpFP
#-------------------------------------------

##############################################################################
### Configuration - Authentication via the DEVELOPER Portal
### HACS - https://github.com/Tasshack/dreame-vacuum
##############################################################################

# neato:
# client_id: !secret neato_client_id
# client_secret: !secret neato_client_secret


automation:

##############################################################################
### Automations - Help Neato!
### https://www.vcloudinfo.com/2020/05/home-assistant-neato-vacuum-automation.html
##############################################################################

- alias: 'Help Neato'
- alias: 'Help Vacuum'
id: 6548de52-a4a4-4df2-9d66-9c2c15577a7e
trigger:
- platform: state
entity_id: vacuum.neato_vac
to: 'error'
entity_id: sensor.l10s_vacuum_error
from: 'No error'
- platform: event
event_type: event_did_someone_help_neato_loop
event_type: event_did_someone_help_vacuum_loop

condition:
- condition: state
entity_id: vacuum.neato_vac
state: 'error'
- condition: template
value_template: "{{ states('sensor.l10s_vacuum_error') != 'No error' }}"

action:
- wait_template: "{{ states.group.family.state == 'home' }}"
- wait_template: "{{ is_state('group.bed', 'off') }}"
- delay: 00:05:00

- service: vacuum.locate
entity_id: vacuum.neato_vac
entity_id: vacuum.l10s_vacuum

- service: script.speech_engine
data:
value1: >
{% set error = states.vacuum.neato_vac.attributes['status'] %}
{{ "Neato Vacuum is complaining about " ~ error ~ " [ask Residents to help]" }}
value1: >
{% set error_description = state_attr('sensor.l10s_vacuum_error', 'description') %}
{{ "Vacuum is complaining: " ~ error_description ~ " [ask Residents to help]" }}
- service: script.notify_engine
data:
title: 'Help Neato'
value1: "{{ states.vacuum.neato_vac.attributes['status'] }}"
title: 'Help vacuum'
value1: "{{ state_attr('sensor.l10s_vacuum_error', 'description') }}"
who: 'family'
ios_category: 'camera'
camera_entity: 'camera.neato_vac_cleaning_map'
camera_entity: 'camera.l10s_vacuum_map'
content_type: 'jpeg'
group: 'information'

- delay: 00:01:00
- service: vacuum.locate
entity_id: vacuum.neato_vac
entity_id: vacuum.l10s_vacuum

- delay: 00:20:00
- event: event_did_someone_help_neato_loop
- event: event_did_someone_help_vacuum_loop
30 changes: 7 additions & 23 deletions config/script/speech_processing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
speech_processing:
mode: queued
sequence:
- service: mqtt.publish
data:
topic: 'polly/lastmsg'
payload: "Message: {{ now().strftime('%-I') }}:{{ now().strftime('%M') }} {{ now().strftime('%p') }}. {{ speech_message | striptags | truncate(220)}}"
retain: true

- event: openai_instructions_sent
event_data:
instructions: "{{ speech_message | striptags }}"

- condition: and
conditions:
- condition: or
Expand Down Expand Up @@ -60,23 +59,10 @@ speech_processing:
0.2
{% endif %}
# - service: tts.amazon_polly_say
# data:
# entity_id: media_player.livingroomCC
# message: >-
# <speak>
# <amazon:auto-breaths>
# {{ speech_message }}
# </amazon:auto-breaths>
# </speak>
# cache: true

- service: conversation.process
data:
agent_id: conversation.openai_conversation
text: >-
Take the following system generated information and review and relay the information as yourself.
Here is the information:
{{ speech_message }}
response_variable: agent

Expand All @@ -89,11 +75,9 @@ speech_processing:
{{ agent.response.speech.plain.speech }}
cache: true

- service: mqtt.publish
data:
topic: 'polly/lastmsg_openai'
payload: "Message: {{ now().strftime('%-I') }}:{{ now().strftime('%M') }} {{ now().strftime('%p') }}. {{ agent.response.speech.plain.speech | striptags | truncate(220)}}"
retain: true
- event: openai_iresponse
event_data:
response: "{{ now().strftime('%B %d,%Y %-I:%M %p') }} {{ now().strftime('%p') }}. {{ agent.response.speech.plain.speech | striptags}}"

- service: input_boolean.turn_off
data:
Expand Down
36 changes: 26 additions & 10 deletions config/templates/speech/briefing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
{%- macro responsibilities() -%}
{% set day_of_week = now().strftime('%a') %}
{% if day_of_week in ['Wed', 'Sun'] %}
Today is {{ now().strftime('%A') }} and {{ now().strftime('%A') }} is garbage day.
Today is garbage day.
{% if day_of_week == 'Wed' %}
Both Recycling and regular Garbage goes out.
{% endif %}
{% endif %}
{% set day_of_year = now().strftime('%j')|int(9999) %}
{% if day_of_year % 2 != 0 %}
Today is Justin's day to do the chores.
{% else %}
Today is Paige's day to do the chores.
{% endif %}
{%- endmacro -%}

{%- macro inside_weather() -%}
Expand Down Expand Up @@ -51,10 +45,16 @@
{%- endif -%}
{%- endif %}
{% endfor -%}

{%- if states('sensor.pirateweather_alerts') == '1' -%}
{%- set alert_description = state_attr('sensor.pirateweather_alerts', 'description') %}
[WEATHER ALERT: Summarize the WHAT, WHEN and IMPACTS.] {{ alert_description }}
{%- endif %}
{%- endmacro -%}

{%- macro lightning() -%}
There have been {{ states('sensor.blitzortung_lightning_counter') }} lightning strikes detected within {{(states('sensor.blitzortung_lightning_distance') | int(9999)/ 1.69) | round (1, 'floor')}} Miles of our House. Please make sure everyone is inside the house.
There have been {{ states('sensor.blitzortung_lightning_counter') }} lightning strikes detected within {{(states('sensor.blitzortung_lightning_distance') | int(9999)/ 1.69) | round (1, 'floor')}} Miles of our House.
Nearest Storm Distance : {{states('sensor.pirateweather_nearest_storm_distance')}} Miles.
{%- endmacro -%}

{%- macro fridge() -%}
Expand Down Expand Up @@ -215,11 +215,27 @@

{# a macro to call all macros :) #}
{%- macro mother_of_all_macros() -%}


{# Augmenting the System Prompt for OpenAI #}
{% set current_date = now() %}
{% set month = current_date.strftime('%B') %}
{% set day_of_week = now().strftime('%a') %}
{% set hour = now().hour %}
{% set minute = now().minute %}

{% set day = current_date.strftime('%d') %}
{% set year = current_date.strftime('%Y') %}
{% set time = current_date.strftime('%I:%M %p') %}
Current date time: {{ month }} {{ day }}, {{ year }} {{ time }}
Residents:
- Carlo (Dad): {{ states('person.carlo') }}
- Stacey (Mom): {{ states('person.stacey') }}
- Justin (Son): {{ states('person.justin') }}
- Paige (Daughter): {{ states('person.paige') }}
and our cat Molly: Always home.
[Avoid repeating information from the last broadcast if it was recently broadcasted]
Last broadcast: {{states('input_text.lastmsg_openai')}}

New Information:
{% if call_no_announcement != 1 %}
{% if now().strftime('%H')|int(9999)< 12 and now().strftime('%H')|int(9999)> 6 %}
Good morning.
Expand Down
3,834 changes: 3,834 additions & 0 deletions config/www/community/lovelace-mushroom/mushroom.js

Large diffs are not rendered by default.

Binary file not shown.
Loading

0 comments on commit ca3b3b3

Please sign in to comment.