Using !include in automations

Ok, I’m kinda getting stuck here and after searching this community as well as the internet as a while I’m not finding any real answers, so…

I have a few Automations which will notify us over Alexa via speech and await a reply. This is all working great, but it’s rather monotone to have the same question asked every single day so I’m using AI to generate the messages, this is also working fine, but since I’m trying to run as much off the cloud as possible (Yeah, yeah, I know, quite the oxymoron considering the notifications themselves are cloud dependent).

Anyway, to make a long story short, what I’ve done is to get “AI” (or rather LLMs) to create a bunch of suitable sentences for various scenarios and save these out as separate files and, after a LOT of trouble, inserting these dynamically into my automations using !include phrases/gymbag.yaml or similar.

Problem is, using !include inside the automations webui isn’t working, and while editing the yaml files by hand works well and they will then show up perfectly fine in the webui I keep getting server 500 errors when adding new automations or editing an existing one.

Is there a way around this at all? Thinking out loud, would breaking up the automations.yaml file into several fixes and using !include_dir or similar work, or am I stuck editing by hand until the team decides to “fix” the “bug”? I guess I could also break out the offending automations into a separate file and simply removing the !include offending_automations.yaml reference whenever I am actively editing or working on other automations, but it adds one more step that I kinda dont want.

I could also copy the entirety of phrases/gymbag.yaml into the automation in question, but since I’m using other files accross the board for yes/no/norespone replies etc they are re-used among a bunch of different automations, so if I ever wanted to update the possible responses I would have to update umpteen automations…

Am I making any sense? Are any of you able to help? :slight_smile:

Example (should work, but not what I’m actually using as I have several triggers for Yes/No/NoResponse etc)

initial automation

  alias: Fed Dogs
  description: ""
  trigger:
    - platform: time
      at: "17:05:00"
  condition: []
  action:
    - service: script.actionable_notification
      data:
        text: !include phrases/fed_dogs.yaml
        event_id: actionable_notification_fed_dogs
        alexa_device: media_player.offfice
  mode: single

offending reply automation

  trigger:
    - platform: event
      event_type: alexa_actionable_notification
      event_data:
        event_id: actionable_notification_fed_dogs
        event_response_type: ResponseNo
  action:
    - service: notify.alexa_media
      data:
        message: !include phrases_dislike.yaml
        target: media_player.office
        data:
          type: tts

phrases_dislike.yaml

>
  {{ [
    "<voice name='Brian'><prosody rate='fast'>Well, I see you've maintained the status quo – as expected!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Your unique talent for avoiding work is truly remarkable!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Who needs a superhero when we have you to avoid responsibilities?</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>I'm genuinely impressed by your commitment to procrastination!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Another day, another opportunity to embrace inaction.</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Did you decide to take a vacation from productivity today?</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>You're like an artist who's chosen to leave the canvas blank – quite a statement!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Your secret recipe for evading responsibility must be legendary!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>I bet the other obligations are throwing a party in your honor!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>The commitment to dodging must be exhausting, or is it effortless?</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Efficiency may not be your strong suit, but avoidance certainly is!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Neglect executed with such flair, it's almost impressive!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>I'd pay to watch you perfect the art of procrastination – a true spectacle!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Your once-sharp productivity sword now gathers dust – along with the to-dos!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Obligations breathe a sigh of relief when you're around!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Stealthily avoiding responsibilities – you're the ninja of idleness!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Let's hold a ceremony to remember the things you didn't do!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>The champion of procrastination has arrived – and it's you!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>An abundance of obligations magically appears in your presence!</prosody></voice>",
    "<voice name='Brian'><prosody rate='fast'>Thank you, oh great avoider of responsibilities – our hero of inactivity!</prosody></voice>"
  ] | random }}

I’m not entirely sure I get what you want, sorry!

Help me understand this better: your real problem is, when you setup some of the texts in YAML, you get a 500 if you try to safe any other automation in the UI? Correct?

If so, I could imagine a few ways around it.

  • You can devide automations from the UI and YAML. Just use this method to include different automation files.
  • Use packages to split off the automations and texts.
  • You might be able to split of the texts into a script, and call the script to return just the answer.

Did that help? :slight_smile:

1 Like

I had an issue using !include in an automation.

Although I never got 500 errors, anytime I would edit or add a new automation, it would save that automation with the included data and overwrite my !include.

So, using this page:
Automation YAML - Home Assistant (home-assistant.io)

I moved that automation to configuration.yaml without the id. I can no longer edit it in the UI, but I am cool with that and not having to fix it every time I made a change to any other automation.

!includes are not supported in the UI automation editor.

Pretty much, yes. Basically the problem is that once I manually add a !include in the automations file, the UI breaks and I can’t edit any ol my automations using the editor. Gonna try to break out the problematic ones to see if that would work as they are then saved in different places however.

Does it still show up in the list of automations at least? I’ll have to give it a try I guess and see how it works.

Thanks, that’s what I found, but it also breaks the entire UI editor as I now seem unable to edit existing automations or add new ones. The question was really, how do I work around this?

Yes it does.

Now I think I get it. :slight_smile: This is the intended behaviour (sort of). You can’t have both “worlds” in one file. You need to seperate the automations made in the UI from the automations made in YAML. Then you should be able to create/edit/delete the “UI automations”.

That would give you the freedom to !inlcude in your “YAML automation”, and to leave the other automations in the UI. That should be doable with the link @jeffcrum and I posted above. :slight_smile:

Something like this in configuration.yaml:

# /config/configuration.yaml
automation: !include automations.yaml
automation yaml: !include automations_yaml.yaml

Spinning this along, you could split your configuration into folders (with sub-folders) by using any of the directory includes. That could help even further for a better overview.