How do I pass on variables to sonos script

I’m trying to get my Sonos to speak out sensor data using a sonos_say script. For some reason the speaker just reads out the {{ states.sensor.yr_temperature.state }} as a string, not the actual value. This is my script.

sonos_say:
  alias: "Sonos TTS script"
  sequence:
  - service: media_player.sonos_snapshot
    data_template:
      entity_id: "{{ sonos_entity }}"
  - service: media_player.sonos_unjoin
    data_template:
      entity_id: "{{ sonos_entity }}"
  - service: media_player.volume_set
    data_template:
      entity_id: "{{ sonos_entity }}"
      volume_level: "{{ volume }}"
  - service: tts.google_say
    data_template:
      entity_id: "{{ sonos_entity }}"
      message: "{{ message }}"
  - delay: "{{ delay }}"
  - service: media_player.sonos_restore
    data_template:
      entity_id: "{{ sonos_entity }}"

and this is my automation

- id: '1550750799006'
  alias: Sonos_dagstemperatur
  trigger:
  - at: 07:15:00
    platform: time
  action:
  - service: script.sonos_say
    data:
      sonos_entity: media_player.kok
      volume: 0.2
      message: "God morgon! Just nu är det {{ states.sensor.yr_temperature.state }} grader ute."
      delay: '00:00:10'

Using the following an automation works as expected

action:
- service: tts.google_say
  data_template:
    entity_id: media_player.kok
    message: Hej, testar {{ states.sensor.yr_temperature.state }}

How should I write the message variable in my automation to get it to work?

1 Like

change data to data_template,
than it shoud work.

Worked like a charm, thanks!