Easy automation with !include

  alias: test
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.testknop
  condition: []
  action:
  - service: script.tekst_motor
    data:
      wie: Bureau
      spreker: Google
      tekst: !include ../teksten/tekst.yaml       
      volume: 0.5
  mode: single

Hi, I am very new to HA. try to make a simple automation that says some text. What am I doing wrong here. HA does not accept the "!include …/teksten/tekst.yaml ". thanks in advance.

First off you need to start getting used to posting your code snippets properly formatted by using three back-ticks (```) on the line before and after the code block. it makes it hard to read and understand it if you don’t.

But you can’t use !include in a service call. You have to write the text out in that variable data line.

Thanks for your response, Think it looks better now. However, I don’t understand what you mean! Could you maybe give me an example?

  - service: script.tekst_motor
    data:
      wie: Bureau
      spreker: Google
      tekst: !include ../teksten/tekst.yaml  #<-- replace this with the text in the file
      volume: 0.5

Thank you very much for your response.
Yes, that works but according to this video Build a Daily Briefing in Home Assistant - YouTube it should also work via

   description: ''
   trigger:
   - platform: state
     entity_id: input_boolean.testbutton
   condition: []
   action:
   - service: script.text_engine
     dates:
       who: Office
       speaker: Google
       text: !include ../texts/text.yaml
       volume: 0.5
   mode: single

Why doesn’t that work for me then?
I try as much as possible and try to understand as much as possible about HA!

The automation editor reacts differently than code stored in a .yaml file. Accordingly, the author of the youtube tutorial uses packages to insert .yaml files via !include.

apparently i was wrong and you can use !includes in service calls.

never mind…

I have created a file text.yaml in folder packages. When I check HA the configuration I get the following error"Error loading /config/configuration.yaml: in “/config/automations.yaml”, line 998, column 14: Unable to read file /config/…/text.yaml. " What is the problem here and how do I get this resolved?

automations.yaml represents the UI automation editor’s content. Create a file or a folder in your packages directory and put your automation into it:

# Example path: /config/packages/automations/custom_automations.yaml

# custom_automations.yaml:

automation:
- id: tekst_motor
  alias: Tekst Motor
  mode: single
  max_exceeded: silent
  trigger:
    …
    …

What are the contents of the file?

>
    {# Daily Briefing #}
    {%- macro getGreeting() -%}
    
        random Text.
    
    {%- endmacro -%}

    {{ getGreeting() }}

Best,

Thanks for your response. I don’t get it anymore. Don’t get it working!! I think this is still a bit too difficult for me. Will have to read and practice some more. :thinking: :thinking:

remove the >. The file should only contain the contents.

Thank you for the response.

When I check configuration I get the following error: “Error loading /config/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/packages/tekst.yaml”, line 3, column 6”
:thinking:

Place quotes around the entire template inside the file.

[
    {# Daily Briefing #}
    {% macro getGreeting() %}
    
        randoml Text.
    {% endmacro %}

    {{ getGreeting() }}  ]

Like this? Error loading /config/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/packages/tekst.yaml”, line 3, column 6
same error!

are [ a quote?