kalkih / mini-media-player

Minimalistic media card for Home Assistant Lovelace UI
MIT License
1.53k stars 207 forks source link

TTS for sonos failed #524

Closed t0ny-peng closed 3 years ago

t0ny-peng commented 3 years ago

Hi there. I'm trying to use the TTS feature of mini-media-player and it looks like it failed with a failure message. Before I dive into the code I just want to see if anyone else saw this error before.

The config part of TTS is:

tts:
  platform: sonos
  entity_id: media_player.bedroom_speaker
  volume: 0.5

The sonos_say script is: (I copied mostly from here

sonos_say:
  alias: "Sonos TTS script"
  fields:
    sonos_entity:
      description: "The eneity of the sonos"
      example: "bedroom_speaker"
    message:
      description: "The message content"
      example: "The light is on!"
    volume:
      description: "The volume"
      example: "0.5"

  sequence:
    - service: sonos.snapshot
      data_template:
        entity_id: "{{ 'media_player.' ~ sonos_entity }}"
    - service: sonos.unjoin
      data_template:
        entity_id: "{{ 'media_player.' ~ sonos_entity }}"
    - service: media_player.volume_set
      data_template:
        entity_id: "{{ 'media_player.' ~ sonos_entity }}"
        volume_level: "{{ volume }}"
    - service: tts.google_say
      data_template:
        entity_id: "{{ 'media_player.' ~ sonos_entity }}"
        message: "{{ message }}"
    - delay: "00:00:01"
    - delay: >-
        {% set duration = states.media_player[sonos_entity].attributes.media_duration %}
        {% if duration > 0 %}
          {% set duration = duration - 1 %}
        {% endif %}
        {% set seconds = duration % 60 %}
        {% set minutes = (duration / 60)|int % 60 %}
        {% set hours = (duration / 3600)|int %}
        {{ [hours, minutes, seconds]|join(':') }}
    - delay: "00:00:05"
    - service: sonos.restore
      data_template:
        entity_id: "{{ 'media_player.' ~ sonos_entity }}"

And the error message is

Sonos TTS script: Error executing script. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data['entity_id']

I'm guessing the member name being passed to the script isn't correct? If I call service like this directly the sonos_say script works like a charm.

service: script.sonos_say
data:
  message: Test message
  sonos_entity: bedroom_speaker
  volume: 0.5

Hope someone could spot the problem immediately. Thx!

t0ny-peng commented 3 years ago

Turned out that I should only use bedroom_speaker in the TTS conf. Closing this issue now.