179 lines
8.5 KiB
Django/Jinja
179 lines
8.5 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') %}
|
|
It is currently raining. Make sure all doors and windows are closed!
|
|
{% 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') %}
|
|
{{ [
|
|
"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 %}
|
|
{% 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 %} |