@Didgeridrew , the template code is embedded in a templates.yaml file, which is referenced in the configuration.yaml file. I thought that adding further reference to the template: domain in the templates files would result in an error. Am I not correct in that thought. My complete “templates.yaml” file is;
###############################
# "Weatherman" Configuration #
###############################
- trigger:
- trigger: homeassistant
event: start
- trigger: time_pattern
minutes: /05 # Poll for new data at 05 minutes after the hour
- trigger: state
entity_id: sensor.motion_sensor_air_temperature
- trigger: state
entity_id: sensor.stratford_wind_chill
- trigger: state
entity_id: sensor.stratford_humidex
- trigger: state
entity_id: sensor.stratford_advisories
- trigger: state
entity_id: sensor.stratford_statements
- trigger: state
entity_id: sensor.stratford_warnings
- trigger: state
entity_id: sensor.stratford_watches
action:
- action: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.stratford_forecast
response_variable: hourly
sensor:
- name: Stratford Forecast Hourly
unique_id: stratford_forecast_hourly
state: "{{ now().isoformat() }}"
attributes:
forecast: "{{ hourly['weather.stratford_forecast'].forecast[:4] }}" # Obtain next four hours of forecasts
- trigger:
- trigger: state
entity_id: sensor.stratford_forecast_hourly
sensor:
- name: Weatherman Data
state: "OK"
attributes:
weather_condition_now: >
{% set cond_now = states('weather.stratford_forecast') %}
{% if states('sun.sun') == 'below_horizon' %}
{% if cond_now == 'sunny' %} night {% elif cond_now == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond_now }} {% endif %}
{% else %}
{{ cond_now }}
{% endif %}
weather_temperature_now: >
{{ states('sensor.motion_sensor_air_temperature') | float(0.0) }}
weather_condition_0: >
{% set cond0 = state_attr('sensor.stratford_forecast_hourly', 'forecast')[0].condition %}
{% set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
{% set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
{% set cond0_time = as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[0].datetime) %}
{% if cond0_time < next_rising and next_rising < next_setting %}
{% if cond0 == 'sunny' %} night {% elif cond0 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond0 }} {% endif %}
{% else %}
{{ cond0 }}
{% endif %}
weather_temperature_0: >
{{ state_attr('sensor.stratford_forecast_hourly', 'forecast')[0].temperature | float(0) }}
weather_timestamp_0: >
{{ as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[0].datetime) | timestamp_custom('%I') | int }} {{ as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[0].datetime) | timestamp_custom('%p') }}
weather_condition_1: >
{% set cond1 = state_attr('sensor.stratford_forecast_hourly', 'forecast')[1].condition %}
{% set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
{% set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
{% set cond1_time = as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[1].datetime) %}
{% if cond1_time < next_rising and next_rising < next_setting %}
{% if cond1 == 'sunny' %} night {% elif cond1 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond1 }} {% endif %}
{% else %}
{{ cond1 }}
{% endif %}
weather_temperature_1: >
{{ state_attr('sensor.stratford_forecast_hourly', 'forecast')[1].temperature | float(0) }}
weather_timestamp_1: >
{{ as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[1].datetime) | timestamp_custom('%I') | int }} {{ as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[1].datetime) | timestamp_custom('%p') }}
weather_condition_2: >
{% set cond2 = state_attr('sensor.stratford_forecast_hourly', 'forecast')[2].condition %}
{% set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
{% set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
{% set cond2_time = as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[2].datetime) %}
{% if cond2_time < next_rising and next_rising < next_setting %}
{% if cond2 == 'sunny' %} night {% elif cond2 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond2 }} {% endif %}
{% else %}
{{ cond2 }}
{% endif %}
weather_temperature_2: >
{{ state_attr('sensor.stratford_forecast_hourly', 'forecast')[2].temperature | float(0) }}
weather_timestamp_2: >
{{ as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[2].datetime) | timestamp_custom('%I') | int }} {{ as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[2].datetime) | timestamp_custom('%p') }}
weather_condition_3: >
{% set cond3 = state_attr('sensor.stratford_forecast_hourly', 'forecast')[3].condition %}
{% set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
{% set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
{% set cond3_time = as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[3].datetime) %}
{% if cond3_time < next_rising and next_rising < next_setting %}
{% if cond3 == 'sunny' %} night {% elif cond3 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond3 }} {% endif %}
{% else %}
{{ cond3 }}
{% endif %}
weather_temperature_3: >
{{ state_attr('sensor.stratford_forecast_hourly', 'forecast')[3].temperature | float(0) }}
weather_timestamp_3: >
{{ as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[3].datetime) | timestamp_custom('%I') | int }} {{ as_timestamp(state_attr('sensor.stratford_forecast_hourly', 'forecast')[3].datetime) | timestamp_custom('%p') }}
temperature_affective: >
{% if states('sensor.stratford_humidex')|is_number or states('sensor.stratford_wind_chill')|is_number %}
{% if states('sensor.stratford_humidex')|is_number %}
{% set temperature_affective = "Feels Like: " ~ states('sensor.stratford_humidex') | round(1) %}
{% else %}
{% set temperature_affective = "Wind Chill: " ~ states('sensor.stratford_wind_chill') | round(1) %}
{% endif %}
{% else %}
{% set temperature_affective = "" %}
{% endif %}
{{ temperature_affective }}
temperature_trend: >
{% set temperature_trend = states('binary_sensor.temperature_trend_exterior') %}
{{ temperature_trend }}
humidity: >
{{ states('sensor.stratford_humidity') | float(0) }}
barometric_pressure: >
{{ states('sensor.stratford_barometric_pressure') | float(0) }}
pressure_trend: >
{% set pressure_trend = states('sensor.stratford_tendency') %}
{{ pressure_trend }}
wind_bearing: >
{{ states('sensor.stratford_wind_bearing') | float(0) }}
wind_speed: >
{{ states('sensor.stratford_wind_speed') | float(0) }}
uv_index: >
{{ states('sensor.stratford_uv_index') | float(0.0) }}
aqhi: >
{{ states('sensor.stratford_aqhi') | float(0.0) }}
visibility: >
{{ states('sensor.stratford_visibility') | float(0.0) }}
moon_phase: >
{{ states('sensor.moon') }}
sun_position: >
{% set position_now = states('sun.sun') %}
{{ position_now }}
sunrise_time: >
{{ as_timestamp(state_attr('sun.sun', 'next_rising')) | timestamp_custom('%I:%M') }}
sunset_time: >
{{ as_timestamp(state_attr('sun.sun', 'next_setting')) | timestamp_custom('%I:%M') }}
weather_alert: >
{% set weather_alert = [states('sensor.stratford_statements'), states('sensor.stratford_advisory'), states('sensor.stratford_warnings'), states('sensor.stratford_watches')] %}
{% if weather_alert | map('int') | max != 0 %}
{% if states('sensor.stratford_watches') | int > 0 %}Watches - {{ states('sensor.stratford_watches') | int }}
{% elif states('sensor.stratford_warnings') | int > 0 %}Warnings - {{ states('sensor.stratford_warnings') | int }}
{% elif states('sensor.stratford_advisory') | int > 0 %}Advisories - {{ states('sensor.stratford_advisory') | int }}
{% else %}
Statements - {{ states('sensor.stratford_statements') | int }}
{% endif %}
{% else %}
{{""}}
{% endif %}
updated_on: >
{% set date = as_timestamp(states('sensor.stratford_observation_time'))|timestamp_custom("%a %b %Oe, %Y at %-I:%M %p") %}
{{ date }}
#########################################
# "Current Tariff Period" Configuration #
#########################################
- trigger:
- trigger: homeassistant
event: start
- trigger: state
entity_id: sensor.festival_hydro_inc_residential_electricity_rate
attribute: active_peak
action:
- choose:
- conditions:
- condition: state
entity_id: sensor.festival_hydro_inc_residential_electricity_rate
attribute: active_peak
state: off_peak
sequence:
- action: select.select_option
metadata: {}
data:
option: Off Peak
target:
entity_id:
- select.daily_energy_roof_heating
- select.yearly_energy_roof_heating
- action: input_number.set_value
data:
value: "{{ state_attr('sensor.festival_hydro_inc_residential_electricity_rate','off_peak_rate')|float(0)}}"
target:
entity_id: input_number.current_tariff_rate
- conditions:
- condition: state
entity_id: sensor.festival_hydro_inc_residential_electricity_rate
attribute: active_peak
state: mid_peak
sequence:
- action: select.select_option
metadata: {}
data:
option: Mid Peak
target:
entity_id:
- select.daily_energy_roof_heating
- select.yearly_energy_roof_heating
- action: input_number.set_value
data:
value: "{{ state_attr('sensor.festival_hydro_inc_residential_electricity_rate','mid_peak_rate')|float(0)}}"
target:
entity_id: input_number.current_tariff_rate
- conditions:
- condition: state
entity_id: sensor.festival_hydro_inc_residential_electricity_rate
attribute: active_peak
state: on_peak
sequence:
- action: select.select_option
metadata: {}
data:
option: On Peak
target:
entity_id:
- select.daily_energy_roof_heating
- select.yearly_energy_roof_heating
- action: input_number.set_value
data:
value: "{{ state_attr('sensor.festival_hydro_inc_residential_electricity_rate','on_peak_rate')|float(0)}}"
target:
entity_id: input_number.current_tariff_rate
##################################################
# "Rain Predicted Within 24 Hours" Configuration #
##################################################
- trigger:
- trigger: homeassistant
event: start
- trigger: time_pattern
minutes: /59 # Poll for new data at 59 minutes after the hour
action:
- action: weather.get_forecasts
target:
entity_id:
- weather.stratford_forecast
data:
type: hourly
response_variable: weatherforecast
- variables:
wet_conditions: "{{['rainy','pouring','lightning','lightning-rainy','hail']}}"
condition_forecast: "{{weatherforecast['weather.stratford_forecast'].forecast[:24]|map(attribute='condition')|list }}"
binary_sensor:
- name: 24-Hour Rain Outlook
unique_id: 24_hour_rain_outlook
icon: mdi:weather-rainy
state: "{{intersect(condition_forecast,wet_conditions)|count > 0}}"
device_class: moisture