danVnest-home-assistant/configuration/climate/weather.yaml

74 lines
3.8 KiB
YAML

template:
- sensor:
- name: Extreme forecast
state: >
{%- set forecasts = (
states('sensor.outside_apparent_temperature_2h_forecast')|float,
states('sensor.outside_apparent_temperature_4h_forecast')|float,
states('sensor.outside_apparent_temperature_6h_forecast')|float,
states('sensor.outside_apparent_temperature_8h_forecast')|float,
states('sensor.outside_apparent_temperature_10h_forecast')|float,
) -%}
{%- set max_forecast = forecasts|max -%}
{%- if max_forecast >= states('input_number.high_temperature_aircon_trigger')|float -%}
{{- max_forecast -}}
{%- else -%}
{%- set min_forecast = forecasts|min -%}
{%- if min_forecast <= states('input_number.low_temperature_aircon_trigger')|float -%}
{{- min_forecast -}}
{%- else -%}
None
{%- endif -%}
{%- endif -%}
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
icon: mdi:sun-thermometer-outline
availability: >
{{
has_value('sensor.outside_apparent_temperature_2h_forecast') and
has_value('sensor.outside_apparent_temperature_4h_forecast') and
has_value('sensor.outside_apparent_temperature_6h_forecast') and
has_value('sensor.outside_apparent_temperature_8h_forecast') and
has_value('sensor.outside_apparent_temperature_10h_forecast') and
has_value('input_number.high_temperature_aircon_trigger') and
has_value('input_number.low_temperature_aircon_trigger')
}}
- name: Extreme forecast text
state: >
{% set extreme = states('sensor.extreme_forecast') -%}
{%- if has_value('sensor.extreme_forecast') -%}
{%- for hour in ['2','4','6','8','10'] -%}
{%- if states('sensor.outside_apparent_temperature_' + hour + 'h_forecast') == extreme -%}
{{- extreme|round(1)|string + " °C in " + hour + " hours" -}}
{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- elif extreme is none -%}
nice for 10 hours
{%- else -%}
extreme forecast unavailable
{%- endif -%}
icon: mdi:sun-thermometer-outline
- name: Next rain forecast text
state: >
{%- if states('sensor.weather_station_precipitation_intensity')|float(0) > 0.1 -%}
raining now
{%- else -%}
{%- set hours = ['1h','2h','3h','4h','5h','6h','7h','8h','9h','10h','11h','12h','13h','14h','15h','16h','17h','18h','19h','20h','21h','22h', '23h'] -%}
{%- set days = ['1d','2d','3d','4d','5d','6d','7d'] -%}
{%- set var = namespace(rain_in = 'no rain for 7 days') -%}
{%- for time in hours + days -%}
{%- set probability_sensor = 'sensor.pirateweather_precip_probability_' + time -%}
{%- set intensity_sensor = 'sensor.pirateweather_precip_intensity_' + time -%}
{%- if not (has_value(probability_sensor) and has_value(intensity_sensor)) -%}
{%- set var.rain_in = "rain forecast unavailable" -%}
{%- break -%}
{%- elif states(probability_sensor)|float > 0 and states(intensity_sensor)|float > 0.1 -%}
{%- set var.rain_in = "rain in " + time[:-1] + (" hour" if time[-1] == 'h' else " day") + ("s" if time[:-1] != "1" else "") -%}
{%- break -%}
{%- endif -%}
{%- endfor -%}
{{- var.rain_in -}}
{%- endif -%}
icon: "{{ 'mdi:weather-rainy' if states('sensor.next_rain_forecast_text') != 'no rain for 7 days' else 'mdi:weather-sunny' }}"