Refactor speech briefing macros for improved clarity and functionality. Updated documentation, enhanced weather reporting with air quality and UV index checks, and streamlined location reporting using a new helper macro. Removed deprecated air quality macro.
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]
{% set temp = state_attr('climate.downstairs', 'current_temperature') | default('unknown') %}
{% set humidity = states('sensor.downstairs_thermostat_humidity') %}
Inside the house, it is {{ temp }} degrees{% if humidity not in ['unknown','unavailable','none'] %} with {{ humidity }} percent humidity{% endif %}. [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 -%}
{% set aq_description = state_attr('sensor.bear_stone_common_air_quality_index', 'description') | default('') %}
{% set aq_index = states('sensor.bear_stone_common_air_quality_index') | int(0) %}
{% if aq_description %}
Air Quality:{{aq_description }}
{% endif %}
{% if aq_index >= 150 %}
[Air quality is unhealthy; limit outdoor activity]
{% set unit = entity.attributes.unit_of_measurement | default('') %}
{% set base_name = entity.attributes.friendly_name | default(entity.entity_id) %}
{% set friendly_name = ' '.join(base_name.split(' ')[1:]) or base_name %}
{% set numeric = value | float(0) %}
{% set include = (
'Temperature'in friendly_name
or 'Minutely' in friendly_name
or 'Precip' in friendly_name
or ('Wind Speed' in friendly_name and numeric > 15)
or ('Cloud Coverage' in friendly_name and numeric > 75)
or ('Humidity' in friendly_name and (numeric < 50 or numeric > 85))
or ('Nearest Storm Distance' in friendly_name and numeric <= 10)
) %}
{% if include and 'UV Index' not in friendly_name %}
{{friendly_name }}:{{value }} {{ unit }}
{% endif %}
{%- endfor %}
{% set uv_index = states('sensor.pirateweather_uv_index') | float(0) %}
{% if uv_index >= 6 %}
UV index is {{ uv_index }}.
[Give a helpful suggestion based on the current UV index or weather conditions]
{% endif %}
{%- if states('sensor.nws_alerts') | int(0) > 0 -%}
{%- set alert_description = state_attr('sensor.nws_alerts', 'Alerts') %}
{%- set alert_description = state_attr('sensor.nws_alerts', 'Alerts') | default('') %}
[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]
@ -162,26 +172,7 @@
{%- 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 %}
{# UV details are now included in outside_weather with a threshold gate #}