Files
fresh-home/components/packages/openweathermap_templates.yaml
T
2024-04-14 14:08:56 -04:00

127 lines
5.9 KiB
YAML

# TODO
# Update to account for new get_weather_forcats BS a
template:
- binary_sensor:
- name: Precipitation Likely Soon
unique_id: templatebinarysensor.precipitation_likely_soon
icon: mdi:weather-rainy
availability: "{{ states('sensor.openweathermap_hourly_forecast_precipitation_probability') not in ['unkown', 'unavailable'] }}"
state: "{{ states('sensor.openweathermap_hourly_forecast_precipitation_probability')|float(default=0) >= 50.0 }}"
- name: Precipitation Likely
unique_id: templatebinarysensor.precipitation_likely
icon: mdi:weather-rainy
availability: "{{ states('sensor.openweathermap_daily_forecast_precipitation_probability') not in ['unkown', 'unavailable'] }}"
state: "{{ states('sensor.openweathermap_daily_forecast_precipitation_probability')|float(default=0) >= 50.0 }}"
- trigger:
- platform: time_pattern
hours: /1
- platform: event
event_type: event_template_reloaded
id: "reload"
- platform: homeassistant
event: start
action:
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.openweathermap_daily
response_variable: daily
- service: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.openweathermap_hourly
response_variable: hourly
binary_sensor:
- name: "Impending Rain"
unique_id: templatebinarysensor.impending_rain
availability: "{{ states('weather.openweathermap_hourly') not in ['unkown', 'unavailable'] }}"
icon: mdi:weather-rainy
# This looks too far into the future. Cutting it down a bit
state: >-
{%- set totalprecipitation = 0 | float -%}
{%- set upcoming_precipitation = 0 | float -%}
{%- set ns = namespace() -%}
{%- set ns.totalprecipitation = 0 -%}
{%- for daypart in range(0, 8) -%}
{%- set precipitation = hourly['weather.openweathermap_hourly'].forecast[daypart].precipitation -%}
{%- set wind_speed = hourly['weather.openweathermap_hourly'].forecast[daypart].wind_speed -%}
{%- set precipitation_probability = hourly['weather.openweathermap_hourly'].forecast[daypart].precipitation_probability %}
{% if precipitation_probability > 0 -%}
{% if wind_speed > states('input_number.wind_speed_blowing_rain') |float(default=0) %}
{%- set upcoming_precipitation = precipitation * precipitation_probability -%}
{%- endif -%}
{%- endif -%}
{%- set ns.totalprecipitation = ns.totalprecipitation + upcoming_precipitation -%}
{%- endfor %}
{{ ns.totalprecipitation / 100 | float | round(0) > 0.99 }}
sensor:
- name: "Sprinkler: Total Expected Precipitation"
unique_id: "custom_sensor.sprinkler_total_expected_precipitation"
icon: mdi:weather-pouring
unit_of_measurement: mm
availability: "{{ states('weather.openweathermap_daily') not in ['unkown', 'unavailable'] }}"
state: >
{%- set totalprecipitation = 0 | float -%}
{%- set upcoming_precipitation = 0 | float -%}
{%- set ns = namespace() -%}
{%- set ns.totalprecipitation = 0 -%}
{%- for daypart in range(0, 8) -%}
{%- set precipitation = daily['weather.openweathermap_daily'].forecast[daypart].precipitation * 25.4 -%}
{%- set precipitation_probability = daily['weather.openweathermap_daily'].forecast[daypart].precipitation_probability / 100 %}
{% if precipitation_probability >0 -%}
{%- set upcoming_precipitation = precipitation * precipitation_probability -%}
{%- endif -%}
{%- set ns.totalprecipitation = ns.totalprecipitation + upcoming_precipitation -%}
{%- endfor %}
{{ ns.totalprecipitation | float | round(0) }}
- name: "Today's Low Temperature"
unique_id: templatesensor.templow_today
unit_of_measurement: °F
availability: "{{ states('weather.openweathermap_daily') not in ['unkown', 'unavailable'] }}"
state: "{{ daily['weather.openweathermap_daily'].forecast[0].templow }}"
- name: "Today's High Temperature"
unique_id: templatesensor.temphigh_today
unit_of_measurement: °F
availability: "{{ states('weather.openweathermap_daily') not in ['unkown', 'unavailable'] }}"
state: "{{ daily['weather.openweathermap_daily'].forecast[0].temperature}}"
- name: "Today's Chance of Precipitation"
unique_id: templatesensor.precip_chance_today
icon: mdi:cloud-percent
unit_of_measurement: '%'
availability: "{{ states('weather.openweathermap_daily') not in ['unkown', 'unavailable'] }}"
state: "{{ daily['weather.openweathermap_daily'].forecast[0].precipitation_probability}}"
- name: "Tomorrow's Low Temperature"
unique_id: templatesensor.templow_tomorrow
unit_of_measurement: °F
availability: "{{ states('weather.openweathermap_daily') not in ['unkown', 'unavailable'] }}"
state: "{{ daily['weather.openweathermap_daily'].forecast[1].templow}}"
- name: "Tomorrow's High Temperature"
unique_id: templatesensor.temphigh_tomorrow
unit_of_measurement: °F
availability: "{{ states('weather.openweathermap_daily') not in ['unkown', 'unavailable'] }}"
state: "{{ daily['weather.openweathermap_daily'].forecast[1].temperature}}"
- name: "Tomorrow's Chance of Precipitation"
unique_id: templatesensor.precip_chance_tomorrow
icon: mdi:cloud-percent
unit_of_measurement: '%'
availability: "{{ states('weather.openweathermap_daily') not in ['unkown', 'unavailable'] }}"
state: "{{ daily['weather.openweathermap_daily'].forecast[1].precipitation_probability}}"