Files

231 lines
12 KiB
Django/Jinja

{% from 'formatting.jinja' import cleanup %}
{% from 'time.jinja' import ct %}
{% set ct = ct() | int %}
{% macro weatherInfo(type,method,time) %}
{% set time = time|default('day') %}
{% if method in ['text','dashboard'] %}
{% if type in ['current','full'] %}
The current weather is {{ states('weather.iron_nerd_weather_station') | lower }}. It is {{ state_attr('weather.iron_nerd_weather_station','temperature') | round }} degrees outside and feels like {{ states('sensor.home_temperature_feels_like') | round }} degrees.
{% endif %}
{% if type in ['forecast','full'] %}
{% if 14400 <= ct <= 61200 %}
The forecast high is {{ states('sensor.todays_high_temp') }}.
{% else %}
Overnight you can expect a low of {{ states('sensor.overnight_lowest_temperature') }}.
{% endif %}
{% if is_state('binary_sensor.early_night_mode','on') %}For tonight{% else %}For the rest of the day{% endif %}, the conditions are expected to be {{ state_attr('sensor.current_forecast','friendly') }}.
{% endif %}
{% if type in ['alerts','full'] %}
{% if is_state('input_boolean.tornado_alarm','on') %}
We are under a tornado warning. If you are not already in shelter, you should be. Get on it!
{% if state_attr('binary_sensor.tornado_warning','confirmed') == true %}
A tornado has been confirmed in the area. Please take shelter immediately!
{% endif %}
{% elif is_state('binary_sensor.severe_thunderstorm_warning','on') %}
We are under a severe thunderstorm warning.
{% if state_attr('binary_sensor.severe_thunderstorm_warning','tornado_possible') == true %}
The incoming storm has the potential to produce a tornado, so please pay attention and prepare to take shelter!
{% endif %}
{% if state_attr('binary_sensor.severe_thunderstorm_warning','considerable_destructive') == true %}
This storm has the potential to cause considerable damage. Please take shelter and stay safe!
{% endif %}
{% elif states('sensor.weatheralerts_active_alerts') > '0' and method != 'dashboard' %}
Current weather alerts: {{ states('sensor.weather_alert_string') }}.
{% endif %}
{% if method != 'dashboard' %}
{% if is_state('binary_sensor.lightning_warning','on') %}
{% set ltgdist = (states('sensor.blitzortung_lightning_distance') | int) / 1.609 | round %}
There is lightning in the area. Nearest strike is {{ ltgdist }} miles away.
{% endif %}
{% if is_state('binary_sensor.raining','on') %}
{% if states('sensor.home_tempest_cloud_sensors_precipitation_intensity') not in ['unavailable','unknown','no_rain'] %}
{% set intensity = states('sensor.home_tempest_cloud_sensors_precipitation_intensity') %}
{% if intensity == 'very_light' %}
There is currently a very light drizzle falling.
{% elif intensity == 'light' %}
There is currently light rain falling. Front porch windows should be okay, but other windows should be closed.
{% elif intensity == 'moderate' %}
It is raining pretty good outside, you should probably make sure all windows are closed.
{% elif intensity in ['heavy','very_heavy'] %}
There is heavy rain falling, please make sure all doors and windows are closed at this time.
{% elif intensity == 'extreme' %}
It is raining extremely hard outside. Make sure all doors and windows are closed, and I recommend staying inside until it calms down. Perhaps check for roof leaks as well.
{% endif %}
{% else %}
It is currently raining. Make sure all doors and windows are closed!
{% endif %}
{% endif %}
{% endif %}
{% if state_attr('weather.iron_nerd_weather_station','visibility') | int < 3 %}
Caution: Current outdoor visibility is {{ state_attr('weather.iron_nerd_weather_station','visibility') }} miles.
{% endif %}
{% endif %}
{% elif method == 'tts' %}
{% if type in ['alerts','full'] %}
{% set alerts = states('sensor.weather_alerts_active_corrected') %}
{% if alerts == '1' %}
{% set alertStrings = ['is','alert','It is'] %}
{% else %}
{% set alertStrings = ['are','alerts','They are'] %}
{% endif %}
{% if states('sensor.weatheralerts_active_alerts') > '0' %}
"There {{ alertStrings[0] }} {{ alerts }} weather {{ alertStrings[1] }} active. {{ alertStrings[2] }}, "
{{ states('sensor.weather_alert_string') }}.
{% endif %}
{% if is_state('input_boolean.tornado_alarm','on') %}
"We are under a tornado warning. If you are not already in shelter, you should be. Get on it! "
{% if state_attr('binary_sensor.tornado_warning','confirmed') == true %}
"A tornado has been confirmed in the area. Please take shelter immediately! "
{% endif %}
{% elif is_state('binary_sensor.severe_thunderstorm_warning','on') %}
"We are under a severe thunderstorm warning. "
{% if state_attr('binary_sensor.severe_thunderstorm_warning','tornado_possible') == true %}
"The incoming storm has the potential to produce a tornado, so please pay attention and prepare to take shelter! "
{% endif %}
{% if state_attr('binary_sensor.severe_thunderstorm_warning','considerable_destructive') == true %}
"This storm has the potential to cause considerable damage. Please take shelter and stay safe! "
{% endif %}
{% elif is_state('input_boolean.tornado_watch','on') %}
{{ [
"There is currently a tornado watch active. Please keep an eye on the sky and your local weather reports. ",
"We are currently under a tornado watch. This means the possibility exists for a tornado to form. Be prepared, and be safe! ",
"The National Weather Service has issued a tornado watch for our area. Be prepared to take shelter if a warning is issued! ",
] | random }}
{% endif %}
{% if is_state('binary_sensor.lightning_warning','on') %}
{% set ltgdist = (states('sensor.blitzortung_lightning_distance') | int) / 1.609 | round %}
{{ [
"There are reports of lightning in the area, please stay safe. ",
"My sensors detect the presence of lightning nearby, so you should prepare to take shelter if needed. ",
"A little birdy told me there is lightning nearby. His feathers were all sticking up, I have no idea why. ",
"Please exercise caution, as there is lightning in the area. ",
"That flashing in the sky is not interstellar warfare, it is simply lightning. But you should still be careful outside. ",
] | random }}
"The nearest lightning strike is {{ ltgdist }} miles away. "
{% endif %}
{% if is_state('binary_sensor.raining','on') %}
{% if states('sensor.home_tempest_cloud_sensors_precipitation_intensity') not in ['unavailable','unknown','no_rain'] %}
{% set intensity = states('sensor.home_tempest_cloud_sensors_precipitation_intensity') %}
{% if intensity == 'very_light' %}
{{ [
"There is currently a very light drizzle falling. ",
"It is drizzling outside, but it is not too bad. ",
"The sky is spitting on us. That's not very nice, but a mild inconvenience at most. "
] | random }}
{% elif intensity == 'light' %}
{{ [
"There is currently light rain falling. ",
"It is raining lightly outside, but it is not too bad. ",
"It kinda wainin outside, but just a little. "
] | random }}
"Front porch windows should be okay, but other windows should be closed. "
{% elif intensity == 'moderate' %}
{{ [
"It is raining pretty good outside, you should probably make sure all windows are closed. ",
"It is raining at a decent rate outside, please make sure all windows are closed. "
"If you look outside, you will see that it wainin. "
] | random }}
{% elif intensity in ['heavy','very_heavy'] %}
{{ [
"There is heavy rain falling, please make sure all doors and windows are closed at this time. ",
"It is raining heavily outside, please make sure all doors and windows are closed. ",
"It wainin sideways! Please make sure all doors and windows are closed. "
] | random }}
{% elif intensity == 'extreme' %}
{{ [
"It is raining extremely hard outside. ",
"There is a torrential downpour outside. ",
"Holy crap, I have never seen it rain this hard before. "
] | random }}
"Make sure all doors and windows are closed, and I recommend staying inside until it calms down. Perhaps check for roof leaks as well. "
{% endif %}
{% else %}
{{ [
"I have looked outside and determined that it is raining. ",
"If you look outside the window, you will notice, it wainin. ",
"It wainin sideways! ",
"There appears to be excessive moisture currently falling from the sky. Plan accordingly. ",
] | random }}
{% endif %}
{% endif %}
{% if (state_attr('weather.iron_nerd_weather_station','visibility') | int ) < 3 %}
{{ [
"It is foggy outside, please exercise caution when driving. ",
"The visibility outside is quite low. If you will be driving soon, please be cautious. ",
"It is pea soup outside right now, and that is just as awful to drive in as it is to eat. Be careful! ",
"Look out the window. Do you notice that you cannot see anything? Bear that in mind if you intend to drive any time soon. ",
"Be advised, it is very difficult to see outside right now. Drive safely. "
] | random }}
{% endif %}
{% endif %}
{% if type in ['current','full'] %}
{{ states('sensor.current_conditions_detail') }}
{% elif type == 'forecast' %}
{{ states('sensor.current_forecast_detail') }}
{% endif %}
{% if time in ['morning','day'] and type != 'alerts' %}
{{ [
'Just in case you were planning on going anywhere,',
'On the off chance that you planned to go outside,',
'If you were planning to go out and do something with your life,',
] | random }}
{{ states('sensor.clothing_forecast_detail') }}
{% endif %}
{% endif %}
{% endmacro %}
{% macro weatherReport(type,method,time) %}
{% macro data() %}
{{ weatherInfo(type,method,time) |
replace('clear-night','clear') |
replace('partlycloudy','partly cloudy') |
replace('snowy-rainy','a mix of rain and snow') |
replace('lightning-rainy','stormy') }}
{% endmacro %}
{{ cleanup(data()) }}
{% endmacro %}
{% macro tempConvert(temp,unitFrom,unitTo) %}
{% if unitFrom in ['F','f'] %}
{% if unitTo in ['C','c'] %}
{{ (temp - 32) * 5/9 }}
{% elif unitTo in ['K','k'] %}
{{ (temp - 32) * 5 / 9 + 273.15 }}
{% endif %}
{% elif unitFrom in ['C','c'] %}
{% if unitTo in ['F','f'] %}
{{ (temp * 9 / 5) + 32 }}
{% elif unitTo in ['K','k'] %}
{{ temp + 273.15 }}
{% endif %}
{% elif unitFrom in ['K','k'] %}
{% if unitTo in ['F','f'] %}
{{ (temp - 273.15) * 9 / 5 + 32 }}
{% elif unitTo in ['C','c'] %}
{{ temp - 273.15 }}
{% endif %}
{% endif %}
{% endmacro %}
{% macro pressureConvert(pressure,unitFrom,unitTo) %}
{% if unitFrom == 'inHg' %}
{% if unitTo == 'mbar' %}
{{ pressure * 33.864 }}
{% elif unitTo == 'psi' %}
{{ pressure / 2.036 }}
{% endif %}
{% elif unitFrom == 'mbar' %}
{% if unitTo == 'inHg' %}
{{ pressure / 33.864 }}
{% elif unitTo == 'psi' %}
{{ (pressure * 14.504) / 1000 }}
{% endif %}
{% elif unitFrom == 'psi' %}
{% if unitTo == 'inHg' %}
{{ pressure * 2.036 }}
{% elif unitTo == 'mbar' %}
{{ (pressure / 14.504) * 1000 }}
{% endif %}
{% endif %}
{% endmacro %}