Enhance UV index reporting by adding weather-related tips and improving sensor data display

This commit is contained in:
Carlo Costanzo 2025-06-11 14:44:55 -04:00
parent 571b964dd3
commit c5ab958dbf

View File

@ -162,12 +162,25 @@
{%- endmacro -%}
{%- macro uv() -%}
{% if states.sensor.pirateweather_uv_index.state|int(9999)>= 6 and states.sensor.pirateweather_uv_index.state|int(9999)<= 7.9 %}
Today's UV index is {{ states.sensor.pirateweather_uv_index.state }}. You should wear sunscreen if going outside.
{% elif states.sensor.pirateweather_uv_index.state|int(9999)>= 8 and states.sensor.pirateweather_uv_index.state|int(9999)<=10.9 %}
Today's UV index is {{ states.sensor.pirateweather_uv_index.state }}. This is VERY HIGH. Be sure wear sunscreen and re-apply.
{% elif states.sensor.pirateweather_uv_index.state|int(9999)>= 11 %}
Today's UV index is {{ states.sensor.pirateweather_uv_index.state }}. This is EXTREME. You should be very cautious going outside.
{% if states.sensor.pirateweather_uv_index.state|int(9999)>= 6 %}
Today's 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 helpful tip based on the current UV index and weather conditions]
{% endif %}
{%- endmacro -%}