[WIP] Morning Briefing

This is a Work In Progress (WIP) but I figured I would share this now and update it as I develop it more.

Part One:

Initial automation is for a morning briefing. Currently it is an automation that sends me the current date and the weather currently and later for the current day.

  - alias: "Morning Briefing"
    trigger:
      platform: time
      at: '06:00'
    condition:
      condition: state
      entity_id: device_tracker.adamsiphone
      state: 'home'
    action:
      - service: notify.home_assistant
        data_template:
          title: "Moring Briefing"
          message: >
                    Today is {{ now().strftime( '%B %d, %Y') }}{{ "\n" }}
                    {{ "\n" }}
                    The current temperature is {{states('sensor.pws_temp_f')}} degrees Fahrenheit with {{states('sensor.pws_weather')}} skies.{{ "\n" }}
                    {{ "\n" }}
                    Today's forecast is {{states('sensor.pws_weather_1d')}}{{ "\n" }}
                    {{ "\n" }}
                    Tonight's forecast is {{states('sensor.pws_weather_1n')}}

So this morning I got an e-mail that said…

Today is March 01, 2018

The current temperature is 38.5 degrees Fahrenheit with Rain skies.

Today’s forecast is Rain and wind early. A mix of sun and clouds by afternoon. High 44F. Winds N at 20 to 30 mph. Chance of rain 100%. Rainfall around a half an inch. Winds could occasionally gust over 40 mph.

Tonight’s forecast is Clear to partly cloudy. Low 27F. Winds NNW at 10 to 15 mph.

My wife gets the same briefing and really likes it. I also added an input_text: to my front end so I can write messages to include in her briefing some days. Her automation looks the same as mine, however hers starts with…

{{states('input_text.amybrief')}}{{ "\n" }}
{{ "\n" }}

Not sure what the limit is to adding to an input_text but it seems to be rather long. The first time after I added the input text I explained what I had done and added a nice note, it all showed up in the e-mail.

My full config is on github if you are wondering how some of the weather sensors or anything else is setup.
https://github.com/SilvrrGIT/HomeAssistant

4 Likes

Part Two:

I want to figure out how to integrate my calendar into this. This was the long term goal of this little endeavor. Every morning I would check the weather, my e-mail and my calendar. I thought it would be nice to put this into one nice e-mail as a briefing.

I need to integrate the google calendar component and see how it works and how it can be integrated into the briefing.

I am so going to have to try this…

I have an automation using the calendar message attribute which gives me the heading from the calendar entry, you can also use the description attribute.

{{ states.calendar.sanitation.attributes.message }}

Thanks coolie

Haven’t had much time to work on this but added something to it today so I figured I would post it. I have the input text to add notes to my wife’s brief, however, if I forget to clear it out its included in the brief until I do remember to clear it. So, I automated the removal.

Adding the following as the last action clears the note after its sent.

      - service: input_text.set_value
        data:
          entity_id: input_text.amybriefinput
          value: ""

did you integrate the calendar?

No, I couldn’t pull information in the way I wanted. That combined with my weather forecast getting removed by the provider made me scrap this project for now.

Have this back in my setup again.

Updated this to allow for some formatting.

On the todo list is to try and figure out a way to attach a random picture from the massive collection I have. Also I want to figure out how to make the precipitation sensor say 0 inches instead of None when there is no precipitation in the forecast.

Now displays as.

Today is February 12, 2020

Today’s Weather
The current temperature is 34 degrees Fahrenheit with a forecast of snowy. The low temperature today is 18 degrees Fahrenheit with a high of 37.
The predicted rainfall today is 0.2 inches.

Holiday’s & Birthdays
No Holidays or Birthdays Today

1 Like

Ok, got all of it working.

The preciptation line now uses an if statement so if the sensor is None it reports 0 and if it reports any other value it just reports that value.

The predicted precipitation today is {% if states.weather.dark_sky.attributes.forecast[0].precipitation == None %} 0 inches. {% else %} {{ states.weather.dark_sky.attributes.forecast[0].precipitation }} inches. {% endif %} 
        data_template:
          title: "Moring Briefing"
          message: >
                    <b>Today is {{ now().strftime( '%B %d, %Y') }} </b> <br>
                    <br>
                    <b> Today's Weather </b> <br>
                    The current temperature is {{state_attr('weather.dark_sky', 'temperature')}} degrees Fahrenheit with a forecast of {{ states.weather.dark_sky.attributes.forecast[0].condition }}. The low temperature today is {{ states.weather.dark_sky.attributes.forecast[0].templow }} degrees Fahrenheit with a high of {{ states.weather.dark_sky.attributes.forecast[0].temperature }}. <br>
                    The predicted precipitation today is {% if states.weather.dark_sky.attributes.forecast[0].precipitation == None %} 0 inches. {% else %} {{ states.weather.dark_sky.attributes.forecast[0].precipitation }} inches. {% endif %} <br>
                    <br>
                    <b> Holiday's & Birthdays </b> <br>
                    {% if is_state('sensor.holiday', '') %} No Holidays or Birthdays Today {% else %}Today is {{ states.sensor.holiday.state}}.{% endif %} <br>
                    {% if is_state('sensor.holidaytomorrow', '') %} {% else %}Tomorrow is {{ states.sensor.holidaytomorrow.state}}.{% endif %} <br>
                    {% if is_state('sensor.holidayinaweek', '') %} {% else %} {{ states.sensor.holidayinaweek.state}} is in one week.{% endif %} <br>
                    <br>
                    <b> A Picture of Us! </b>
          data:
            images:
              - /config/www/pictures/to/1.jpg

edit: intresting find. In specifying the file path to the image, if its put in quotes
"/config/www/pictures/to/1.jpg" it is handled more like an attachment. If no quotes are used the picture is inserted inline.

Created a python script to select a random file from a folder full of pictures (from) and move it to another folder (to) with a new filename (1.jpg). This is the only way I could think of to get a random picture each day and have the static filename for the automation to reference.

#!/usr/bin/python
import os
import shutil
import random
import os.path

src_dir = '/usr/share/hassio/homeassistant/www/pictures/from'
target_dir = '/usr/share/hassio/homeassistant/www/pictures/to/1.jpg'
src_files = (os.listdir(src_dir))
def valid_path(dir_path, filename):
    full_path = os.path.join(dir_path, filename)
    return os.path.isfile(full_path)
files = [os.path.join(src_dir, f) for f in src_files if valid_path(src_dir, f)]
choices = random.sample(files, 1)
for files in choices:
    shutil.copy(files, target_dir)
2 Likes

I realize this is basically me talking to myself in this thread but 0.115.0 brought an important update to the way templates are handled. The change allows all templates to be acted on!

This means that rather than having a python script to move the file, changing folders, etc. you can just put all the files in one folder and select a number at random!

You can now add inline variables to things like filenames. See below!

          data:
            images:
              - /config/data/pictures/{{ range(1, 76) | random }}.jpg 
4 Likes

Nice project. It’s certainly not you just talking to yourself. We’re listening even if we’re not talking back. I’ve been thinking about this as well. Original as a dashboard that tablets would switch to in the morning for an hour or so but like the email idea as a second delivery in case we’re away or something. I’d also like to add snapshots from cameras overnight that detected any people or cars outside, calendaring as you mentioned, water consumption overnight (maybe there’s a leak that started) etc. lots of options with all the telemetry we capture in smart homes.

Thank you for sharing!

2 Likes

It’s been a while, curious if you’ve made more progress over the past year or so? I’m thinking of doing this via a local Wordpress install and essentially creating a post per day programmatically that gets populated and appended to overnight (thinking back to the security camera events I’d mentioned previously)