Data_template error

I have this automation:

- id: Buongiorno info HUB
  alias: Info
  initial_state: true
  trigger:
    - platform: time
      at: '13:45:00'
  condition:
    - condition: state
      entity_id: input_boolean.mauhome
      state: 'on'
  action:
    - service: tts.google_translate_say
      entity_id: media_player.studio, media_player.sonos_stereo
      data_template:
        message: >-
          Sono le {{states('sensor.time')}},
          ed è {{states('sensor.dark_sky_summary')}}. 
          La temperatura esterna è di {{states('sensor.temperature_158d0001b95f60')|int|string }} gradi,
          mentre la temperatura interna è di {{states('sensor.temperatura_media_casa') |int|string }} gradi. 
          *Previsioni.* {{ states.sensor.dark_sky_hourly_summary.state }}. 
          *Citazione. * {{state_attr('sensor.wikiquote', 'entries')[-1].summary|striptags}}.

It doesn’t work and if i try to trigger it from the services i get:

extra keys not allowed at @data [‘data_template’]

Where is the error in the data_template?

Move the line with entity_id below data_template.

  action:
    - service: tts.google_translate_say
      data_template:
        entity_id: media_player.studio, media_player.sonos_stereo
        message: >-
          Sono le {{states('sensor.time')}},
          ed è {{states('sensor.dark_sky_summary')}}. 
          La temperatura esterna è di {{states('sensor.temperature_158d0001b95f60')|int|string }} gradi,
          mentre la temperatura interna è di {{states('sensor.temperatura_media_casa') |int|string }} gradi. 
          *Previsioni.* {{ states.sensor.dark_sky_hourly_summary.state }}. 
          *Citazione. * {{state_attr('sensor.wikiquote', 'entries')[-1].summary|striptags}}.

No way… always the same error.

This isn’t what you’re asking, but you don’t need the time condition… unless there’s an eighth day I don’t know about :wink:

Also… perhaps it needs to be a single-line template? Even though you properly used > to denote a multi-line template.

Good answer… you’re right… but that is the minimal problem… :slight_smile:
I tried also a single line, but with no good result.

Does that template work in Developer Tools > Template?

Yes, it works fine there…

Try this:

  action:
    - service: tts.google_translate_say
      data:
        entity_id: media_player.studio, media_player.sonos_stereo
        message: "Hello world!"

If that produces an error, I have to admit whatever is causing it is non-obvious to me.

If it works, evolve it to this:

  action:
    - service: tts.google_translate_say
      data_template:
        entity_id: media_player.studio, media_player.sonos_stereo
        message: "{{ now().month }}"

If i do this inside the service UI i get the same error. with data and not data_template

Did you rename the TTS service in your config? It should print a “service not found” error if you use a non-existent service but who knows at this point. Post your TTS config if you’re not sure what I’m talking about.

Wow! It failed with that very basic example? Strange.


EDIT
I agree with Tediore that there may be something fundamentally wrong and the data_template error is misleading but the only way the service can express the underlying flaw.

That’s really strange as now i ran the automation again and all is working good… maybe some bug inside the service UI?
BTW Problem solved !

Based on the recent problems you’ve been experiencing, I would say more than just a bug and possibly a systemic problem with your instance of Home Assistant.

1 Like

You’re right but as i moved to hassio i am fixing all the errors i had previously. Now all seems working as expected. I fixed the google_calendar error, the side_panel in hassio and the mqtt_errors i had with hassbian. Now it seems fixed also this about the data_template, so… i hope to have some time without headaches… :slight_smile:

You can’t use data_templates in the service caller in the UI :wink:

Yes, now i know it !