renemarc/home-assistant-config

View on GitHub
automations/notifications/daily_greeting.yaml

Summary

Maintainability
Test Coverage
#
# Greet the day with a daily briefing
#
# @subscribe input_boolean.nap_mode
# @subscribe input_boolean.night_mode
#
- id: daily_greeting
  alias: "Daily Greeting"

  trigger:
    # When night mode is disabled.
    - platform: state
      entity_id: input_boolean.night_mode
      to: 'off'
      for:
        seconds: 5

  condition:
    # If nap mode is disabled.
    - condition: state
      entity_id: input_boolean.nap_mode
      state: 'off'

  action:
    # Sound the day.
    - service: notify.sound
      data:
        message: 'doorbell'
        data:
          method: 'alarm'
    - delay:
        seconds: 2

    # Greet the day.
    - service: notify.speech
      data_template:
        message: >-
          {% set temperature = states('sensor.outside_temperature') | int %}
          {% set apparent = states('sensor.dark_sky_apparent_temperature') | round(0) %}
          {% set summary = states('sensor.dark_sky_summary') | lower | regex_replace('(\d)[–-](\d)', '\\1 to \\2') %}
          {% set minutely = states('sensor.dark_sky_minutely_summary') | lower | regex_replace('(\d)[–-](\d)', '\\1 to \\2') %}
          {% set hourly = states('sensor.dark_sky_hourly_summary') | lower | regex_replace('(\d)[–-](\d)', '\\1 to \\2') %}
          {% set windspeed = (states('sensor.dark_sky_wind_speed')|float * 3600 / 1000) | round(1) %}
          {% set hour = states('sensor.time').split(':')[0] | int %}

          {%- if hour >= 4 and hour < 12 -%}
            Good morning beautiful people!
          {%- elif hour >= 12 and hour < 18 -%}
            Good afternoon productive people!
          {%- elif hour >= 18 and hour < 22 -%}
            Good evening friendly people!
          {%- else -%}
            Good night sleepy people!
          {% endif %}

          We are {{ states('sensor.date_long') }} and it is {{ states('sensor.time_long') }}.

          Outside temperature is {{ temperature }}˚
          {%- if apparent != temperature
           %} but feels like {{ apparent }}
          {%- endif -%}
          .

          {% if minutely != 'unknown' -%}
            It will be {{ minutely.rstrip('.') }}
          {%- else -%}
            It is currently {{ summary }}
          {%- endif -%}
          {%- if hourly != 'unknown'
            %} and will be {{ hourly.rstrip('.') }}
          {%- endif -%}
          .

          {% if 40 <= windspeed -%}
            It is windy. {%
          endif -%}
          A {{ states('sensor.wind_scale_friendly') | lower }} is blowing from the {{ states('sensor.wind_bearing_cardinal_friendly') }}.

          Air quality is {{ states('sensor.aqi_friendly') | lower }}
          {%- if is_state('sun.sun', 'above_horizon') -%}
            , UV index is {{ states('sensor.uv_friendly') | lower }}
          {%- endif %} and {{ states('sensor.sun_state_friendly') }}

          Have a nice day!

          {{ states('sensor.good_vibes') }}