I looked the script over, and didn’t see any obvious errors. All the inequality signs are correct. I even took out the <= and replaced with < (i.e., entity <= 2 changed to < 3). Then it complained about TemplateSyntaxError: unexpected '<'
. Here is the complete code. Sorry, it’s pretty long.
>-
{# Daily Briefing #}
{%- macro getGreeting() -%}
{% if now().strftime('%H')|int < 12 %}
Good morning.
{% elif now().strftime('%H')|int >= 12 and now().strftime('%H')|int < 17 %}
Good afternoon.
{% elif now().strftime('%H')|int >= 12 and now().strftime('%H')|int < 20 %}
Good evening.
{% else %}
Ugh. I'd ask my grandfather, Dr. Sbaitso, to take over for me; but he's asleep and drooling in his rocker. It's best to let him be.
{% endif %}
{% if when == 'morning' %}
Today is {{states.sensor.today_is.state }}, {{ as_timestamp(now()) | timestamp_custom('%B %d %Y') }}.
{% else %}
It is {{ now().strftime("%I:%M %p") }}.
{% endif %}
{%- endmacro -%}
{%- macro getWeather() -%}
The weather in town is {{states('sensor.openweathermap_temperature')|round}} degrees
{% if is_state('weather.openweathermap', 'rainy') %}
{{ [
'with rain.',
'with showers.'
] | random }}
{% elif is_state('weather.openweathermap', 'cloudy') %}
{{ [
'with clouds.',
'with cloudy skies.'
] | random }}
{% elif is_state('weather.openweathermap', 'partlycloudy') %}
{{ [
'with some clouds.',
'with partly cloudy skies.',
'with scattered clouds'
] | random }}
{% elif is_state('weather.openweathermap', 'sunny') %}
{% if is_state('sun.sun', 'above_horizon') %}
{{ [
'and sunny.',
'with sun.'
] | random }}
{% else %}
{{ [
'and clear.',
'with clear skies.'
] | random }}
{% endif %}
{% else %}
and {{ states.weather.openweathermap.state }}
{% endif %}
{%- endmacro -%}
{%- macro getUVIndex() -%}
Currently, the UV Index is {{states('sensor.openweathermap_uv_index')}}
{% if is_number ('sensor.openweathermap_uv_index', <= 2) %}
{{ [
'which is low. No protection is needed.',
'which is minimal. No protection is needed.'
] | random }}
{% elif is_number ('sensor.openweathermap_uv_index', > 3 && <= 5) %}
{{ [
'which is moderate. Protection may be needed.',
'which is moderate. Seek shade during the late morning through mid-afternoon.'
] | random }}
{% elif is_number ('sensor.openweathermap_uv_index', > 6 && <= 7) %}
{{ [
'which is high. Protection is needed.',
'which is high. Seek shade during the late morning through mid-afternoon. When outside, generously apply broad-spectrum SPF-15 or higher sunscreen on exposed skin, and wear protective clothing'
] | random }}
{% elif is_number ('sensor.openweathermap_uv_index', > 8 && <= 10) %}
{{ [
'which is very high. Extra protection is needed.',
'which is very high. Be careful outside, especially during late morning through mid-afternoon. If your shadow is shorter than you, seek shade and wear protective clothing. Generously apply a minimum of SPF-50, broad-spectrum sunscreen on exposed skin.'
] | random }}
{% else %}
{{ [
'which is extreme. Take an abundance of caution when going outside. Please, stay indoors, close all blinds and curtains, and monitor the inside temperature closely.',
'which is extreme. Avoid going outside if at all possible, especially during late morning through mid-afternoon. If your shadow is shorter than you, seek shade and wear protective clothing, a wide-brimmed hat, and sunglasses, and generously apply a minimum of SPF-50, broad-spectrum sunscreen on exposed skin.'
] | random }}
{% endif %}
{%- endmacro -%}
{%- macro getWeatherAlerts() -%}
{% if when == 'evening' %}
The overnight forecast says we can expect {{ states.weather.openweathermap.state }}.
{% else %}
The current forecast says we should expect {{ states.weather.openweathermap.state }}.
{% if is_state('input_boolean.freeze_warning','on') %}
And based on the forecasted low, It will be near or below freezing.
{{ [ 'So, Someone might want to bring the lemon tree in. ',
'Like, the turn water solid kind of cold. Do not leave the lemon tree out to die.',
'I suggest bringing in the plants, otherwise the temperature might kill them. And that will be on you, dawg.',
'I would say winter is coming. But, based on the weather forecast it appears to be here.',
'I would bring in the plants but I lack legs. And Arms. So I am forced to rely on you. Do not let me down.'
] | random }}
{% endif %}
{% endif %}
{%- endmacro -%}
{%- macro getSun() -%}
{% if is_state('sun.sun', 'below_horizon') %}
You have
{% set seconds = as_timestamp(states.sun.sun.attributes.next_rising)-now().timestamp() %}
{% set hours = seconds / 60 %}
{% if seconds / ( 60 * 60 ) > 1 %}
{{ (seconds // ( 60 * 60 )) | int }} hours
{% else %}
{{ (seconds // 60) | int }} minutes
{% endif %}
{{ [
'until the sun rises.',
'until the sun is up.',
'before the sun officially rises. '
]|random }}
{% else %}
You have
{% set seconds = as_timestamp(states.sun.sun.attributes.next_setting)-now().timestamp() %}
{% set hours = seconds / 60 %}
{% if seconds / ( 60 * 60 ) > 1 %}
{{ (seconds // ( 60 * 60 )) | int }} hours
{% else %}
{{ (seconds // 60) | int }} minutes
{% endif %}
{{ [
'until the sun sets for the day.',
'until the sun slips below the horizon.',
'before the sun officially sets. '
]|random }}
{% endif %}
{%- endmacro -%}
{%- macro getClimate() -%}
{%- if is_state('climate.living_room','off') %}
The heat is off. The temperature inside is {{ states.climate.living_room.attributes.current_temperature }} degrees.
{%- elif is_state('climate.living_room','heat_cool') %}
The air conditioning will try to keep the temperature between {{ states.climate.living_room.attributes.target_temp_low }} and {{ states.climate.living_room.attributes.target_temp_high }}.
{% else %}
The heat is set to {{ states.climate.living_room.state }} with a current temperature of {{ states.climate.living_room.attributes.current_temperature }} which is
{%- if states.climate.living_room.attributes.current_temperature | int - states.climate.living_room.attributes.temperature | int |round > 0 %}
{{ states.climate.living_room.attributes.current_temperature | int - states.climate.living_room.attributes.temperature | int }} degrees above
{%- elif states.climate.living_room.attributes.current_temperature | int - states.climate.living_room.attributes.temperature | int |round < 0 %}
{{ (states.climate.living_room.attributes.current_temperature | int - states.climate.living_room.attributes.temperature | int) | abs }} degrees below
{% else %}
right at
{% endif %}
the set point of {{ states.climate.living_room.attributes.temperature }}
degrees.
{%- endif -%}
And The internal humidity is currently {{ states.climate.living_room.attributes.current_humidity }} percent.
{%- endmacro -%}
{%- macro getWazeTime() -%}
{%- if is_state('binary_sensor.workday_sensor','on') %}
As of {{states.sensor.time.state}} the current drive time downtown is {{ states('sensor.waze_travel_time') }} minutes.
The ideal route is {{ state_attr("sensor.waze_travel_time","route") }}
{% else %}
Today is either a weekend day or a holiday, so you may not be driving to work. I'm skipping the travel time report for this morning. If I am incorrect, please correct my code.
{%- endif -%}
{%- endmacro -%}
{# a macro that removes all newline characters, empty spaces, and returns formatted text #}
{%- macro cleanup(data) -%}
{%- for item in data.split("\n") if item | trim != "" -%}
{{ item | trim }} {% endfor -%}
{%- endmacro -%}
{# a macro to call all macros :) IF NEW MACROS ARE CREATED, ENTER THEM BELOW INCLUDING PARENS! #}
{%- macro mother_of_all_macros() -%}
{{ getGreeting() }}
{{ getEvents() }}
{{ getWeather() }}
{{ getUVIndex() }}
{{ getWeatherAlerts() }}
{{ getClimate() }}
{{ getSun() }}
{{ getWazeTime() }}
{%- endmacro -%}
{# Call the macro #}
{{- cleanup(mother_of_all_macros()) -}}