mirror of
https://github.com/CCOSTAN/Home-AssistantConfig.git
synced 2025-09-13 15:26:58 +00:00
362 lines
15 KiB
YAML
Executable File
362 lines
15 KiB
YAML
Executable File
#-------------------------------------------
|
|
# Speech Briefing Macros
|
|
# Description: Contains various macros for generating speech briefings
|
|
#
|
|
# Features:
|
|
# - Weather reports (inside and outside)
|
|
# - Responsibility reminders
|
|
# - Dark outside notification
|
|
# - Holiday and countdown announcements
|
|
# - Air quality reports
|
|
# - Inspirational quotes and facts
|
|
#
|
|
# Original Repo: https://github.com/CCOSTAN/Home-AssistantConfig
|
|
# Blog Post: https://www.vcloudinfo.com/category/home-assistant
|
|
# Follow me on https://www.vcloudinfo.com/click-here
|
|
#-------------------------------------------
|
|
|
|
|
|
>-
|
|
{%- macro dark_outside() -%}
|
|
[Because the sun has set, outside lights have been turned on]
|
|
{%- endmacro -%}
|
|
|
|
{%- macro garbage_day() -%}
|
|
{% set day_of_week = now().strftime('%a') %}
|
|
{% if day_of_week in ['Wed', 'Sun'] %}
|
|
Today is garbage day.
|
|
{% if day_of_week == 'Wed' %}
|
|
Both Recycling and regular Garbage goes out.
|
|
{% endif %}
|
|
{% endif %}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro inside_weather() -%}
|
|
Inside the house, it is {{ states.climate.downstairs.attributes['current_temperature'] }} degrees with {{ states('sensor.downstairs_thermostat_humidity') }} percent humidity. [Only mention humidity if it seems unusually high]
|
|
{%- endmacro -%}
|
|
|
|
{% macro outside_weather() %}
|
|
[Here is the current weather outside]
|
|
Air Quality: {{state_attr('sensor.bear_stone_common_air_quality_index', 'description')}}
|
|
{%- for entity in states.sensor if 'pirateweather' in entity.entity_id %}
|
|
{%- set state = entity.state %}
|
|
{%- set unit = entity.attributes.unit_of_measurement if 'unit_of_measurement' in entity.attributes else '' %}
|
|
{%- set friendly_name = ' '.join(entity.attributes.friendly_name.split(' ')[1:]) %}
|
|
{%- if state not in ['0', '0.0', 'none'] and 'UV Index' not in friendly_name %}
|
|
{%- if 'Temperature' in friendly_name -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- elif 'Minutely' in friendly_name -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- elif 'Precip' in friendly_name -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- elif 'Wind Speed' in friendly_name and state | float(0) > 15 -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- elif 'Cloud Coverage' in friendly_name and state | float(0) > 75 -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- elif 'Humidity' in friendly_name and (state | float(0) < 50 or state | float(0) > 85) -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- elif 'Nearest Storm Distance' in friendly_name and state | float(0) <= 10 -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- endif -%}
|
|
{%- endif %}
|
|
{% endfor -%}
|
|
|
|
{%- if states('sensor.nws_alerts') | int(0) > 0 -%}
|
|
{%- set alert_description = state_attr('sensor.nws_alerts', 'Alerts') %}
|
|
[Summarize the included weather alert and give overall details on any storms relevant to the residents of the home. Use the Situation Overview Section to best understand what is going on - Be sure to highlight any impacts to Seminole County or Tallahassee]
|
|
{{ alert_description }}
|
|
[END of Weather Alert]
|
|
{%- 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.
|
|
Nearest Storm Distance : {{states('sensor.pirateweather_nearest_storm_distance')}} Miles.
|
|
{%- endmacro -%}
|
|
|
|
{%- macro fridge() -%}
|
|
The internal temperature of the refrigerator is currently {{ states('sensor.blink_blink1_temperature') }} degrees. The freezer temperature is {{ states('sensor.refrigerator_freezer_temp') }} degrees and the fridge temperature is {{ states('sensor.refrigerator_fridge_temp') }} degrees. {% if is_state('binary_sensor.refrigerator_door_open', 'on') %}The fridge door is currently open.{% endif %}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro light_check() -%}
|
|
{% if states.group.all_lights.state != 'off' -%}
|
|
There are
|
|
{% for state in states.light if state.state == 'on' -%}
|
|
{%- if loop.last -%}
|
|
{{ loop.index }}
|
|
{%- endif -%}
|
|
{%- endfor %}
|
|
lights on right now.
|
|
{% set comma = joiner(', ') %}
|
|
The
|
|
{% for group in states.group|groupby('state') -%}
|
|
{%- for entity in group.list if entity.state == 'on'
|
|
and entity.name.split(' ')[1]|lower == 'lights'
|
|
and entity.name.split(' ')[0]|lower != 'all'
|
|
and entity.name.split(' ')[0]|lower != 'interior'
|
|
-%}
|
|
{{ 'and' if loop.last and not loop.first else comma() }}
|
|
{{ entity.name|replace('Lights','')}}
|
|
{%- endfor -%}
|
|
{%- endfor -%}
|
|
lights are on.
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro window_check() -%}
|
|
{% if states.group.entry_points.state != 'off' -%}
|
|
{% set comma = joiner(', ') %}
|
|
The
|
|
{% for state in states.binary_sensor if state.state == 'on' and state.attributes.device_class == 'opening' -%}
|
|
{%- endfor %}
|
|
{% for group in states.binary_sensor|groupby('state') -%}
|
|
{%- for entity in group.list if entity.state == 'on' and entity.attributes.device_class == 'opening' -%}
|
|
{{ ' and' if loop.last and not loop.first else comma() }}
|
|
{{ entity.attributes.friendly_name }}
|
|
{%- endfor -%}
|
|
{% endfor %}
|
|
need to be closed.
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro lock_check() -%}
|
|
{% if states.group.locks.state !='locked' -%}
|
|
The
|
|
{%- for state in states.lock -%}
|
|
{%- endfor %}
|
|
{% for group in states.lock|groupby('state') -%}
|
|
{%- for entity in group.list if entity.state == 'unlocked' -%}
|
|
{{ ' and' if loop.last and not loop.first }}
|
|
{{ entity.attributes.friendly_name }}
|
|
{%- endfor -%}
|
|
{%- endfor %}
|
|
needs to be locked.
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro garage_check() -%}
|
|
{% if states.group.garage_doors.state !='closed' -%}
|
|
The
|
|
{%- for state in states.cover -%}
|
|
{%- endfor %}
|
|
{% for group in states.cover|groupby('state') -%}
|
|
{%- for entity in group.list if entity.state == 'open' and entity.attributes.device_class == 'garage' -%}
|
|
{{ ' and' if loop.last and not loop.first }}
|
|
{{ entity.attributes.friendly_name }}
|
|
{%- endfor -%}
|
|
{%- endfor %}
|
|
need to be closed.
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro medicine() -%}
|
|
{% if is_state('input_boolean.medicine', 'off') -%}
|
|
It looks like Carlo has not taken his medicine yet. Please make sure Carlo takes his medicine now.
|
|
{% endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro moon() -%}
|
|
{% if (now().hour == 17) %}
|
|
Current Moon phase: {{ states('sensor.moon') }} [Give a fact and mention today's phase]
|
|
{% endif %}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro uv() -%}
|
|
{% if states.sensor.pirateweather_uv_index.state|int(9999)>= 6 %}
|
|
UV index is {{ states.sensor.pirateweather_uv_index.state }}.
|
|
{%- for entity in states.sensor if 'pirateweather' in entity.entity_id %}
|
|
{%- set state = entity.state %}
|
|
{%- set unit = entity.attributes.unit_of_measurement if 'unit_of_measurement' in entity.attributes else '' %}
|
|
{%- set friendly_name = ' '.join(entity.attributes.friendly_name.split(' ')[1:]) %}
|
|
{%- if state not in ['0', '0.0', 'none'] and 'UV Index' not in friendly_name %}
|
|
{%- if 'Temperature' in friendly_name -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- elif 'Minutely' in friendly_name -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- elif 'Cloud Coverage' in friendly_name and state | float > 75 -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- elif 'Humidity' in friendly_name and (state | float < 50 or state | float > 85) -%}
|
|
{{ friendly_name }}: {{ state }} {{ unit }}
|
|
{%- endif -%}
|
|
{%- endif %}
|
|
{% endfor -%}
|
|
[Give a helpful suggestion based on the current UV index or weather conditions]
|
|
{% endif %}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro holiday() -%}
|
|
{% if states.sensor.holiday.state != '' %}
|
|
Today is {{ states.sensor.holiday.state }}.
|
|
{% endif %}
|
|
{%- endmacro -%}
|
|
|
|
{# YOUTUBE VIDEO ********* https://www.vcloudinfo.com/2019/11/adding-days-until-sensor-to-my-home-assistant-speech-routines.html #}
|
|
{%- macro days_until() -%}
|
|
{%- if states('sensor.mothers_countdown') | int(9999)< 20 -%}
|
|
and don't forget, there is only {{ states.sensor.mothers_countdown.state }} days until Mothers day!
|
|
{%- elif states('sensor.fathers_countdown') | int(9999)< 20 -%}
|
|
and don't forget, there are {{ states.sensor.fathers_countdown.state }} days until Fathers day!
|
|
{%- elif states('sensor.easter_countdown') | int(9999)< 15 -%}
|
|
and don't forget, there are {{ states.sensor.easter_countdown.state }} colorful days until Easter Sunday!
|
|
{%- elif states('sensor.thanksgiving_day_countdown') | int(9999)< 10 and states('sensor.thanksgiving_day_countdown') | int(9999)> 0 -%}
|
|
and don't forget, there are {{ states.sensor.thanksgiving_day_countdown.state }} thankful days until Thanksgiving
|
|
{%- elif states('sensor.thanksgiving_day_countdown') | int(9999)< 1 -%}
|
|
and don't forget, Thanksgiving is tomorrow!
|
|
{%- elif states('sensor.halloween_countdown') | int(9999)< 30 and states('sensor.halloween_countdown') | int(9999)> 0 -%}
|
|
and don't forget, there are {{ states.sensor.halloween_countdown.state }} Spooky days until Halloween!
|
|
{%- elif states('sensor.halloween_countdown') | int(9999)< 1 -%}
|
|
and don't forget, Tomorrow is Halloween!
|
|
{%- elif states('sensor.chanukkah_countdown') | int(9999)< 15 -%}
|
|
and don't forget, there are {{ states.sensor.chanukkah_countdown.state }} days until Chanukkah!
|
|
{%- elif states('sensor.christmas_countdown') | int(9999)< 30 and states('sensor.christmas_countdown') | int(9999)> 0 -%}
|
|
and don't forget, there are {{ states.sensor.christmas_countdown.state }} Merry days until Christmas!
|
|
{%- elif states('sensor.christmas_countdown') | int(9999)< 1 -%}
|
|
and don't forget, Santa Claus is coming tomorrow!
|
|
{% endif %}
|
|
{%- endmacro -%}
|
|
|
|
{% macro air_quality() %}
|
|
{{states('sensor.bear_stone_common_air_quality_index')}}
|
|
{{state_attr('sensor.bear_stone_common_air_quality_index', 'description')}}
|
|
{% endmacro %}
|
|
|
|
{% macro fact_of_the_day() %}
|
|
[incorporate into the message a relevant fact about something that happened in the past on this day]
|
|
{% endmacro %}
|
|
|
|
{# a macro that removes all newline characters, empty spaces, and returns formatted text and replaces underscores with spaces #}
|
|
{%- macro cleanup(data) -%}
|
|
{%- for item in data.split("\n") if item | trim != "" -%}
|
|
{{ item | trim | replace("_", " ") }} {% endfor -%}
|
|
{%- endmacro -%}
|
|
|
|
{# ********************************************* #}
|
|
{# ******** Start the Speech routines ******** #}
|
|
{# ********************************************* #}
|
|
|
|
{# 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 }}]
|
|
|
|
[Resident: Location:
|
|
- Carlo:
|
|
{%- if states('sensor.carlo_place') != 'unknown' %}
|
|
{{ states('sensor.carlo_place') }}
|
|
{% else -%}
|
|
Away
|
|
{% endif -%}
|
|
- Stacey:
|
|
{%- if states('sensor.stacey_place') != 'unknown' %}
|
|
{{ states('sensor.stacey_place') }}
|
|
{% else -%}
|
|
Away
|
|
{% endif -%}
|
|
- Justin:
|
|
{%- if states('sensor.justin_place') != 'unknown' %}
|
|
{{ states('sensor.justin_place') }}
|
|
{% else -%}
|
|
Away
|
|
{% endif -%}
|
|
- Paige:
|
|
{%- if states('sensor.paige_place') != 'unknown' %}
|
|
{{ states('sensor.paige_place') }}
|
|
{% else -%}
|
|
Away
|
|
{% endif -%}
|
|
{% if range(1, 100) | random <= 25 %}
|
|
Cat Molly: Always home.
|
|
{% endif %}
|
|
]
|
|
[Sensor Data:
|
|
{% if call_no_announcement != 1 %}
|
|
{% if now().strftime('%H')|int(9999)< 12 and now().strftime('%H')|int(9999)> 6 %}
|
|
Good morning. [if there is only one person home, address them specifically]
|
|
{% elif now().strftime('%H')|int(9999)>= 12 and now().strftime('%H')|int(9999)< 17 %}
|
|
Good afternoon. [if there is only one person home, address them specifically]
|
|
{% else %}
|
|
Good evening. [if there is only one person home, address them specifically]
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
{# Called from Annoucenments #}
|
|
{{ personarriving | default }}
|
|
|
|
{# Called from Nest when thermostats turn on #}
|
|
{{ NestStatus | default }}
|
|
|
|
{% if call_inside_weather == 1 %}
|
|
{{ inside_weather() }}
|
|
{% endif %}
|
|
|
|
{% if call_outside_weather == 1 and is_state('sun.sun', 'above_horizon') %}
|
|
{{ outside_weather() }}
|
|
{% endif %}
|
|
|
|
{% if (states('sensor.bear_stone_common_air_quality_index')|int(0)) > 50 %}
|
|
{{ air_quality() }}
|
|
{% endif %}
|
|
|
|
{% if (states('sensor.blitzortung_lightning_counter')|int(0)) > 0 %}
|
|
{{ lightning() }}
|
|
{% endif %}
|
|
|
|
{% if (states('sensor.blink_blink1_temperature')|int(0) > 55 or states('sensor.refrigerator_freezer_temp')|float > 5 or states('sensor.refrigerator_fridge_temp')|float > 50 or is_state('binary_sensor.refrigerator_door_open', 'on')) and no_fridge != 1 %}
|
|
{{ fridge() }}
|
|
{% endif %}
|
|
|
|
{{ DoorOpened | default }}
|
|
{{ DoorClosed | default }}
|
|
|
|
{{ lock_check() }}
|
|
{# These two lock statements are sent directly from automations. #}
|
|
{{ DoorLocked | default }}
|
|
{{ DoorUnLocked | default }}
|
|
|
|
{% if call_dark_outside == 1 %}
|
|
{{ dark_outside() }}
|
|
{% endif %}
|
|
|
|
{% if call_garage_check == 1 or is_state('sun.sun', 'below_horizon') %}
|
|
{{ garage_check() }}
|
|
{% endif %}
|
|
|
|
{% if (call_window_check == 1 or is_state('sun.sun', 'below_horizon')) or is_state('group.entry_points', 'on') %}
|
|
{{ window_check() }}
|
|
{% endif %}
|
|
|
|
{{ NewDevice | default }}
|
|
|
|
{% if call_light_check == 1 %}
|
|
{{ light_check() }}
|
|
{% endif %}
|
|
|
|
{% if call_garbage_day == 1 %}
|
|
{{ garbage_day() }}
|
|
{% endif %}
|
|
|
|
{% if now().strftime('%H')|int(0) > 21 %}
|
|
{{ medicine() }}
|
|
{% endif %}
|
|
|
|
{% if value1 is not none %}
|
|
{{ value1 | default }}
|
|
{% endif %}
|
|
|
|
{# call a Random fact about the house or inspiration quote #}
|
|
{{ ([moon, uv, holiday, days_until, outside_weather, outside_weather, fact_of_the_day]|random)() }}
|
|
]
|
|
[Previous broadcast: "{{ state_attr('sensor.openai_response', 'response') }}" ]
|
|
|
|
{%- endmacro -%}
|
|
{{- cleanup(mother_of_all_macros()) -}}
|