Morning briefing

Hello all I have been looking for better ways to create a new morning briefing that will have alexa read off the current sensors in my home and services such as weather (AccuWeather). I know this can be done with templates but that is a topic I am still learning on. Would any one of you have a guide or wiki on how to do this? Any help is appreciated.

Thanks,

Drezin

Hi look here, thejeffreystone, it should point you in the right direction.

1 Like

Thank you so much @dogo_uk , I was able to get a template up and running:

image

here is my template:

Good Morning,

Today is {{ now().strftime( ‘%B %d, %Y’) }}{{ “\n” }}
The current temperature is {{states(‘sensor.openweathermap_temperature’ | round(2))}} degrees Fahrenheit with {{states(‘sensor.openweathermap_forecast_condition’)}} skies.{{ “\n” }}{{ “\n” }}
The current UV danger is {{states(‘sensor.current_uv_level’)}} and the protection widow is {{states(‘binary_sensor.protection_window’)}}
Today’s forecast is a high of {{states(‘sensor.openweathermap_forecast_temperature’)}} degrees and a low of {{states(‘sensor.openweathermap_forecast_temperature_low’)}}{{ “\n” }}degrees.
Today in Regina it will be {{states(‘sensor.regina_high_temperature’)}} degrees with {{states(‘sensor.regina_current_condition’)}} skies.
The home is currently producing {{states(‘sensor.envoy_202132045070_current_power_production’)}}Wh and consuming {{states(‘sensor.envoy_202132045070_current_power_consumption’)}}Wh`

Just a couple more questions:

  1. How do i add a Round so it shows the temp without decimals (you can see I tried one but did not work)?
  2. How would I multiply a my wattage to show Kwh? (*.001) but how would I put that in the script
  3. Most importantly how do i add this to a automation for alexa to read out. The formatting of the yaml code seems to elude me.

Again thank you all for your help.

Drezin

Here is a more complex one which may help you with some ideas. The delay at the end calculates the spoken text time and sets the delay before Sonos rejoins the other speakers.

  - service: tts.google_cloud_say
    data_template:
      entity_id: "{{ (state_attr('variable.v_sonos_speaker_group', 'master')) }}"
      message: >-
        {# ======================================================================================================== #}
        {#   Preamble   #}
        Your daily briefing is about to start.
        {# ======================================================================================================== #}
        {#   Salutation   #}
        {% if states('sensor.time_of_day') != '' %}
        Good {{states('sensor.time_of_day')}} {{ var_person_name }}.
        {% endif %}
        {# ======================================================================================================== #}
        {#   Time   #}
        {% if states.sensor.readable_time.state.lstrip('0') != '' %}
        The time is {{ now().strftime('%-I:%M %p') }}.
        {% endif %}
        {# ======================================================================================================== #}
        {#   Day/Date   #}
        Today is a
        {% if (states('sensor.payday') == 'True') and (states('sensor.day_of_the_week') == 'Friday') %}
        payday
        {% endif %}
        {{states('sensor.day_of_the_week')}}
        and the date is the {{states('sensor.day_of_the_month')}} of {{states('sensor.month_name')}}.
        {# ======================================================================================================== #}
        {#   Special Events   #}
        {% if states('sensor.special_events') != 'NoEvents' %}
        {% if states('sensor.special_events') != '' %}
        {{states('sensor.special_events')}}
        {% endif %}
        {% endif %}
        {# ======================================================================================================== #}
        {#   Birthday/Holiday All   #}
        {% if states('sensor.todays_events') != 'NoEvents' %}
        {% if states('sensor.todays_events') != '' %}
        {% if states('sensor.todays_events')|replace("\'","") == 'Arts Birthday' %}
        Happy Birthday Art.
        {% endif %}
        {% if states('sensor.todays_events')|replace("\'","") == 'Steffs Birthday' %}
        Happy Birthday Steff.
        {% endif %}
        Don't forget, it's {{states('sensor.todays_events')}} today.
        {% endif %}
        {% endif %}
        {# ======================================================================================================== #}
        {#   Holiday Lighting   #}
        {% if (states('sensor.season') != (states('input_select.season_holiday'))|lower()) %}
        Remember to look for the {{ states('input_select.season_holiday') }} lighting theme later tonight.
        {% endif %}
        {# ======================================================================================================== #}
        {#   Birds   #}
        {% if states('sensor.weigh_birds') == 'True' %}
        It's time to weigh the birds again.
        {% endif %}
        {# ======================================================================================================== #}
        {#   Weather   #}
        It's currently {{states('sensor.dark_sky_summary')}} and {{states('sensor.dark_sky_temperature')}} degrees at home.
        Today will be {{states('sensor.dark_sky_hourly_summary')|replace('.','')}}, with a high of {{states('sensor.dark_sky_daytime_high_temperature_0d')|round(0)}} degrees and a low of {{states('sensor.dark_sky_overnight_low_temperature_0d')|round(0)}} degrees.
        {% if states('sensor.dark_sky_precip_intensity_0d') | float(default=0) > 0.1 %}
        We may see {{states('sensor.dark_sky_precip_intensity_0d')}} inches of rain today.
        {% endif %}
        {# ======================================================================================================== #}
        {#   Winds   #}
        {% if states.sensor.dark_sky_daily_summary.state != '' %}
        Current winds are
        {% set winbearing = ((states('sensor.tidewater_wind_dir_avg_10m')|float(default=0)+22.5)/45)|int|round %}
        {% if winbearing > 7 %}{%  set winbearing = 0 %}{% endif %}
        {% set winddir = ['North', 'North East','East','South East','South','South West','West','North West'] %}
        {{ winddir[winbearing]}} averaging {{(states('sensor.dark_sky_wind_speed_0d')|int)|round}} miles per hour
        {% if states('sensor.dark_sky_wind_gust_0d') | float(default=0) > 0 %}
        with gusts up to {{(states('sensor.dark_sky_wind_gust_0d')|int)|round}}
        {% endif %}
        miles per hour.
        {% endif %}
        {# ======================================================================================================== #}
        {#   NWS Warnings   #}
        {% if states('sensor.coastal_duval') | int > 0 %}
        {% if states.sensor.coastal_duval.attributes.alerts[0].title | lower() != 'none' %}
        {% if states.sensor.coastal_duval.attributes.alerts[0].title | lower() != 'unknown' %}
        {% if states.sensor.coastal_duval.attributes.alerts[0].title | lower() != 'unavailable' %}
        The National weather service has issued the following alert for {{ state_attr('sensor.coastal_duval', 'friendly_name') }}. {{ states.sensor.coastal_duval.attributes.alerts[0].title }}, {{ state_attr("sensor.coastal_duval_alert_1","alert_NWSheadline") }}.
        {% endif %}
        {% endif %}
        {% endif %}
        {% endif %}
        {# ======================================================================================================== #}
        {#   UV Index   #}
        {% if states('sensor.dark_sky_uv_index')|int >= 6 and states('sensor.dark_sky_uv_index')|int <= 7.9 %}
        Today's UV index is {{ states('sensor.dark_sky_uv_index') }}. This is high. Be sure wear sunscreen.
        {% elif states('sensor.dark_sky_uv_index')|int >= 8 and states('sensor.dark_sky_uv_index')|int <=10.9 %}
        Today's UV index is {{ states('sensor.dark_sky_uv_index') }}. This is very high. Be sure wear sunscreen and re-apply.
        {% elif states('sensor.dark_sky_uv_index')|int >= 11 %}
        Today's UV index is {{ states('sensor.dark_sky_uv_index') }}. This is EXTREME. You should use caution when going outside.
        {% endif %}
        {# ======================================================================================================== #}
        {#   Fog Warnings   #}
        {% if states('sensor.pirate_weather_visibility') != '' %}
        {% if states('sensor.pirate_weather_visibility')|int(default=0) < 2 %}
        {% if states('sensor.pirate_weather_visibility') != 0 %}
        Current visibility is only {{states('sensor.pirate_weather_visibility')}} miles. Use caution!
        {% endif %}
        {% endif %}
        {% endif %}
        {# ======================================================================================================== #}
        {#   Sunrise/Sunset   #}
        {% if states('sensor.next_rising') != '' %}
        {% if states('sensor.next_setting') != '' %}
        Sunrise
        {% if states('sun.sun') == 'above_horizon' %}
        was at
        {% else %}
        is at
        {% endif %}
        {{states('sensor.next_rising')|replace(':',' ')}}
        and sunset will be at
        {{states('sensor.next_setting')|replace(':',' ')}}.
        {% endif %}
        {% endif %}
        {# ======================================================================================================== #}
        {#   Moon   #}
        {% if states('sensor.moonphase') == 'Full Moon' or (states('sensor.dark_sky_moon_phase_0d')|float(default=0) > 0.45 and states('sensor.dark_sky_moon_phase_0d')|float(default=0) < 0.55) %}
        There will be a Full Moon tonight.
        {% endif %}
        {# ======================================================================================================== #}
        {#   Tides   #}
        {% if states('sensor.next_tide') != 'unknown' %}
        {% if states('sensor.next_tide') != '' %}
        {% if is_state_attr('sensor.dames_point_tides', 'next_tide_type', 'High') %}
        The next High tide is at {{state_attr('sensor.dames_point_tides', 'next_tide_time')}}.
        {#   ====  High Tide Warnings  ===================== #}
        {% if states('sensor.high_tide_height')|float(default=0) > states('variable.v_max_high_tide')|float(default=0) * 0.90 %}
        It will be higher than average at {{states('sensor.high_tide_height')|float(default=0)|round(2)}} feet above sea level.
        {% endif %}
        {#   =============================================== #}
        The last Low tide was at {{state_attr('sensor.dames_point_tides', 'last_tide_time')}}.
        {% else %}
        The next Low tide is at {{state_attr('sensor.dames_point_tides', 'next_tide_time')}}.
        The last High tide was at {{state_attr('sensor.dames_point_tides', 'last_tide_time')}}.
        {% endif %}
        {% endif %}
        {% endif %}
        {# ======================================================================================================== #}
        {#   Arts Location   #}
        {% if var_person_name == 'Steff' %}
        {% if states('device_tracker.arts_iphone_11') != 'home' %}
        Art is
        {% if states('device_tracker.arts_iphone_11') == 'S*****' %} currently at S***** Hospital.
        {% elif states('device_tracker.arts_iphone_11') == 'B*****' %} currently at B***** Hospital.
        {% elif states('device_tracker.arts_iphone_11') == 'F*****r' %} currently at F***** Hospital.
        {% elif states('device_tracker.arts_iphone_11') == 'M*****' %} currently at the M***** Clinic.
        {% elif states('device_tracker.arts_iphone_11') == 'M*****' %} currently at M*****l Hospital.
        {% elif states('device_tracker.arts_iphone_11') == 'St V****' %} currently at St V***** Hospital.
        {% else %}
        away from home.
        {% endif %}
        {% endif %}
        {% endif %}
        {# ======================================================================================================== #}
        {#   Trash Day   #}
        {% if states('sensor.day_of_the_week') == 'Wednesday' %}
        Today is Wednesday. The trash bin needs to be out to the road.
        {% endif %}
        {# ======================================================================================================== #}
        {#   Recycling Day   #}
        {% if states('sensor.date') == states('input_datetime.recycle_pickup_date') %}
        Today is Monday. The recycling bin needs to be out to the road.
        {% endif %}
        {# ======================================================================================================== #}
        {#   First Saturday   #}
        {% if (states('sensor.day_of_the_week') == 'Saturday') and (states('sensor.day_num_of_the_month') | int < 8) %}
        It's the first Saturday of the month. Please remember to change the furnace filters and top off the golf cart batteries.
        {% endif %}
        {# ======================================================================================================== #}
        {#   Reminders Art   #}
        {% if var_person_name == 'Art' %}
        {% if states('sensor.submit_expenses') == 'True' %}
        {% if states('input_boolean.remind_expenses') == 'on' %}
        Remember to submit your expense report today.
        {% endif %}
        {% endif %}
        {% if states('sensor.submit_mileage') == 'True' %}
        {% if states('input_boolean.remind_mileage') == 'on' %}
        Remember to submit your mileage today. You have {{state_attr('sensor.submit_mileage', 'days_remaining')}} days remaining.
        {% endif %}
        {% endif %}
        {% endif %}
        {# ======================================================================================================== #}
        {#   Appointments Art   #}
        {% if var_person_name == 'Art' %}
        {% if states('sensor.arts_next_appointment') != '' %}
        {% if state_attr('sensor.arts_next_appointment','appointment_date') == states('sensor.date') %}
        {% if states('binary_sensor.workday_today') == 'on' %}
        Your next scheduled case starts at {{states('sensor.arts_next_appointment')}} at {{states('sensor.arts_next_appointment_location')}}, {{ state_attr('sensor.arts_next_appointment','appointment_title')|replace(states('sensor.arts_next_appointment_location')|lower,"") }}.
        {% if is_number(states('sensor.to_'+states('sensor.arts_next_appointment_location')|lower))%}
        {% set traveltime = states('sensor.to_'+states('sensor.arts_next_appointment_location')|lower) %}
        {% set travelseconds = ((traveltime|int)*60) %}
        Travel time to {{states('sensor.arts_next_appointment_location')}} is {{states('sensor.to_'+states('sensor.arts_next_appointment_location')|lower)}} minutes.
        {% set nxtapp = (states('sensor.arts_next_appointment')) %}
        {% set apdate = (state_attr('sensor.arts_next_appointment','appointment_date')) %}
        {% set todest = (states('sensor.to_'+states('sensor.arts_next_appointment_location')|lower)) %}
        {% set ttsecs = todest|int*60 %}  {#  travel time in seconds  #}
        {% set app_ts = as_timestamp(apdate + ' ' + nxtapp) %}  {#  appointment timestamp  #}
        {% set gotime = app_ts - ttsecs %}
        You will need to leave no later than {{ gotime | timestamp_custom('%H:%M') }} to arrive on time.
        {% endif %}
        {% endif %}
        {% endif %}
        {% endif %}
        {% endif %}
        {# ======================================================================================================== #}
        {#   Space Launches   #}
        {% if (states('binary_sensor.launch_within_24_hours') == 'on') %}
        There is a planned rocket launch of the {{states('sensor.next_launch_rocket')}} {{states('sensor.next_launch_mission')}} mission. Liftoff is scheduled for {{ states('sensor.next_confirmed_launch_time') }} on {{ states('sensor.next_launch_day') }}.
        {% endif %}
        {# ======================================================================================================== #}
        {#   Closing Statement   #}
        {% if var_person_name == 'Art' %}
        Have a{{ [' pleasant', ' nice', ' great', ' good', ' cheerful', ' delightful', 'n enjoyable', ' super', ' wonderful', ' satisfying'] | random }} day!
        {% else %}
        Have a{{ [' pleasant', ' nice', 'n amiable', ' happy', ' cheerful', ' delightful', 'n enjoyable', ' lovely', ' pleasing', ' good'] | random }} day!
        {% endif %}
  - delay: >-
      {% set duration = (states.media_player.kitchen_white.attributes.media_duration) %}
      {% if duration < 2 %}
        {% set duration = 2 %}
      {% endif %}
      {% set seconds = duration % 60 %}
      {% set minutes = (duration / 60)|int % 60 %}
      {% set hours = (duration / 3600)|int %}
      {{ [hours, minutes, seconds]|join(':') }}
2 Likes

Wow Thank you @kartcon . I do not think I even have enough sensors for all of this. I do Love it though, I Tried to use some of what you have and save it to a file in my config directory. Then I created a script with the messaged referenced in the file. I tried to play it in Google TTS but it did not work. Here is my script:

talias: 'Morning Briefing '
sequence:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.kitchen_speaker
      message: '!include ....briefing.yaml'
      cache: true
      language: en-GB
      options:
        gender: male
mode: singleype or paste code here

PS…
I would rather do this in Alexa but I don’t know how to set it up with the notify send message to…

Any Help is appreciated.

Thanks
Drezin

Here is my automation and scripts to call the morning briefing. You can remove the items which do not apply, but the trigger and action to call the script must remain.

#############################################################
##  Art Weekdays Briefing Automation
#############################################################
- id: art_weekday_briefing
  alias: Art Weekday Briefing
  initial_state: true
  mode: restart
  trigger:
  - platform: state
    entity_id: binary_sensor.lr_motion_sensor_67
    to: 'on'
  - platform: state
    entity_id: binary_sensor.kit_motion_sensor_81
    to: 'on'
  condition:
  - condition: state
    entity_id: input_boolean.tts_arts_daily_briefing
    state: 'on'
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  - condition: time
    after: '05:30'
    before: '09:00'
  - condition: state
    entity_id: binary_sensor.sleepnumber_controller_art_is_in_bed
    state: 'off'
  - condition: template
    # Only run if more than 6 hours (21,600 sec) since it last ran
    value_template: '{{(as_timestamp(now()) - as_timestamp(state_attr("automation.art_weekday_briefing", "last_triggered") | default(0)) | int > 21600 )}}'
  action:
  - service: variable.set_variable
    data:
      variable: v_sonos_speaker_group
      value: 2
      attributes:
        master: "media_player.kitchen_white"
  - service: input_select.select_option
    target:
      entity_id: input_select.briefing_recipient
    data:
      option: "Art"
  - service: script.turn_on
    entity_id: script.morning_briefing
    data:
      variables:
        var_person_name: 'Art'
#

#################################################################
# Morning Briefing Script
# Called from [Art/Steff week[day/end] briefing]
# In file: [automations/user_briefings.yaml]
#################################################################
morning_briefing:
  alias: Morning Briefing
  mode: queued
  sequence:
  - service: script.turn_on
    entity_id: script.sonos_select_speaker_group
  - service: input_boolean.turn_on
    entity_id: input_boolean.tts_speaking
  - service: script.turn_on
    entity_id: script.update_all_travel_times
  - service: media_player.volume_set
    data:
      volume_level: >-
        {% set current_hour = strptime(states('sensor.time'), "%H:%M").hour | int %}
        {% if current_hour >= 5 and current_hour < 8 %}
          0.23
        {% elif current_hour >= 8 and current_hour <= 14 %}
          0.36
        {% elif current_hour > 15 and current_hour <= 20 %}
          0.50
        {% else %}
          0.45
        {% endif %}
    target:
      entity_id:
        - group.all_sonos_devices
  - delay: '00:00:02'
    # allows time for speakers to receive volume settings
  - wait_template: "{{ is_state('script.sonos_say', 'off') }}"
  # Read Briefing
  - service: tts.google_cloud_say
    data_template:
      entity_id: "{{ (state_attr('variable.v_sonos_speaker_group', 'master')) }}"
      message: >- THIS PICKS UP FROM THE SCRIPT IN MY ORIGINAL RELPY

For simplicity’s sake I would suggest you replace most of the variables with hard coded data, such as the volume settings until you get the code working. Once you understand how it works, you can add back in the things that are important to you. I try to code in blocks or sections that are reusable in other places in my code, so following the logic can sometimes get a bit confusing, especially when a variable value changes unexpectedly.
With both the automation and the script, you now have the complete code to make your script work with a little bit of replacing sensor names as necessary. Remember to code as simple as possible to PROVE it works then build up from there.

Art aka kartcon

4 Likes

Sorry for reviving this old topic, but I just wanted to say thanks @kartcon.

Fantastic script and great input for my morning routine, but also a bit strange that this is not more popular.

Anyway, thanks for sharing!

1 Like

Just stumbled on this thread… my briefing is made possible by template sensors and a Node-RED flow. The briefing has the following elements (each is the name of a template sensor):

  • TTS Time of Day
  • TTS Weather Current
  • TTS Weather Forecast
  • TTS Weather Wind
  • TTS Weather Precipitation
  • TTS Sun
  • TTS Weather Comment
  • TTS Moon
  • TTS Solstice
  • TTS Mail and Packages
  • TTS Special Day
  • TTS Calendar Events

Mail and Packages will tell me if anything is coming via the Mail and Packages integration. Special Day announces stuff like birthdays and holidays. Calendar Events alerts me to important events on the calendar for the day.

Here are some examples:

  - sensor:
    - unique_id: tts_time_of_day
      name: TTS Time of Day
      state: >
        {% set day = now().strftime('%A') %}
        {% set month = now().strftime('%B') %}
        {% set date = now().strftime('%d') %}
        {% set hour = now().strftime('%-H')|int %}
        {% set minute = now().strftime('%M') %}
        {% if (hour < 12) %} Good morning. It is {{hour}}:{{minute}} on {{day}}, {{month}} {{date}}.
        {% elif ((hour >=12) and (hour <=16)) %} Good afternoon. It is {{hour}}:{{minute}}.
        {% else %} Good evening. It is {{hour}}:{{minute}}.
        {% endif %}
  - sensor:
    - unique_id: tts_weather_comment
      name: TTS Weather Comment
      state: >
        {% set hour = now().strftime('%-H')|int %}
        {% set accum = (states.sensor.pirate_weather_precip_accumulation_0d.state|float) %}
        {% set temphigh = (states.sensor.pirate_weather_daytime_high_apparent_temperature_0d.state|int) %}
        {% set condlater = (states.sensor.pirate_weather_daily_summary.state) %}
        {% set precip = (states.sensor.pirate_weather_precip_0d.state) %}
        {% set precipchance = (states.sensor.pirate_weather_precip_probability_0d.state)|int %}
        {% if accum > 0.8 %} Be careful on the roads today.
        {% elif (precip == "rain") and (precipchance > 40) and (hour < 15) %} Bring an umbrella!
        {% elif (temphigh > 60) and (temphigh < 80) and (condlater == "Clear") and (hour < 15) %} It's going to be a beautiful day!
        {% elif (temphigh > 95) and (hour < 15) %} It's going to be a hot one!
        {% elif (temphigh < 20) and (hour < 15) %} You'd better bundle up today.
        {% endif %}

I have a Node-RED flow that assembles all of the sensors into a single script, and then it automatically announces the script based on time range and detected motion in the morning. It can also be called up manually at any time with a Companion app Quick Action that runs a script and calls the flow.