Automatic generation of daily messages and notifications

Hello all templaters.

I’ve finally gotten so far in my configuration of my Hassbian that I’m not confident in a lot of my sensors and all of them work without problems, so now I’m starting to be more adventurous.

Enter Jeeves -the Facebook notify component and now my personal housekeeper.

I have a notify component configured, and a 13 different automations, sending multiple messages to me every day when I leave the house, enable Guest-mode when people I don’t want to annoy are around and at such simple events as when the sun has set, like this:

#Jeeves actions
- alias: 'Jeeves Sundown - Evening Greeting'
    - platform: sun
      event: sunset
    - service: notify.jeeves
        message: !include response_texts/jeeves_evening_greeting.yaml

It works - and brilliantly so. But let’s say I want to add to the script, building sentences nested, such as including random messages with a different message depending on the time of day.

I already have a file with the different messages scripted in, based upon Phil Hawthornes brilliant guide to building your own J.A.R.V.I.S.:

Contents of jeeves_evening_greeting.yaml
  {% if now().strftime("%H")|int < 12 %}
  Good morning, Sir.
  {% elif now().strftime("%H")|int < 18 %}
  Good afternoon, Sir.
  {% else %}
  Good evening, Sir.
  {% endif %}

But say I want to randomize the message even more. Say I want to call me a random name instead of “Sir”.
So I’ve tried adding an included yaml file in the configuration like this
{% if now().strftime(“%H”)|int < 12 %}
Good morning, {{ !include response_texts/jeeves_friendly_names.yaml }}

Contents of jeeves_friendly_names.yaml:
  {{ [
  "Master Wayne",
  ] | random }}
... But that just results in a message saying exactly that:

Good morning, {{ !include response_texts/jeeves_friendly_names.yaml }}

It would seem like the file isn’t parsed right because the script doesn’t compile includes in an already included file.

So my questions:

  1. Is there a way to parse nested includes?
  2. Is there a way to build sentences with different content based upon sensors like time and states?
  3. Can it be automated?
  4. How do I use multiple !includes in a single sentence without breaking it up?

Not sure what you mean? Including a yaml file simply appends the included file into your current configuration. When including, everything in the included file will be considered the domain you included it to. I’m not sure why or what you plan to do with nested includes, there isn’t a need for it. Just include a directory and drop all your .yaml files into that directory.

Yes, but you’d have to build your logic.

You can do this one of 2 ways using just yaml:

  • have the sensors change based on the time of day and have an automation or sensor that pieces the sentences together
  • have an automation that compares the time of day and pieces it together.

Really depends on what you want to do. Just remember that sensors have a limit of ~240ish characters.

Everything can be automated. Piecing together sentences is very complicated depending on the language. You’d be best to keep them simple or have a pre-loaded list of possible responses without piecing anything together.

I’m not even sure where to begin on this.

My recommendation is for you to understand what include does. That is it purely extends the yaml file into another file. Take a look at the documentation: