Script work but gives errors

Hi all,
I’ ve created a script to read garbage collection from a calendar and announce it through speakers.

alias: Garbage Notification
sequence:
  - alias: Search calendar for events
    service: calendar.list_events
    data:
      duration:
        hours: 20
        minutes: 0
        seconds: 0
      start_date_time: "{{ (now().date() + timedelta(days=1)) }}"
    target:
      entity_id:
        - calendar.garbage
    response_variable: garbage
  - alias: Set a templated variable
    variables:
      program: |-
        {% for event in garbage.events %}
          {{ event.summary }}
        {% endfor %}
  - condition: not
    conditions:
      - condition: template
        value_template: "{{ program == 'l' }}"
  - service: chime_tts.say
    data:
      chime_path: custom_components/chime_tts/mp3s/click.mp3
      volume_level: 0.25
      tts_platform: cloud
      message: Ricorda di mettere fuori la spazzatura. Domani {{ program }}.
    target:
      device_id: 1c90c59aaa2fe7941c87dbfde4aa608d
mode: single
icon: mdi:delete

The script work as expected and I can hear the message but then home assistant prompt me an error and I get these in the registry:

[547691860416] cannot access local variable 'result' where it is not associated with a value
Garbage Notification: Error executing script. Unexpected error for call_service at pos 4: cannot access local variable 'result' where it is not associated with a value

What am I missing?
Thanks for any hint.

Probably because you’re using a custom component that doesn’t support response_variable. Contact the custom component’s author.

Thanks @123
Looking at the component example code I thought it worked. But maybe it only works the other way?

sequence:
  - service: chime_tts.say_url
    data:
      chime_path: mp3_path_placeholder-bells_2
      tts_platform: google_translate
      message: This is a Chime TTS test on Alexa speakers
      language: en
    response_variable: chime_tts
  - service: notify.alexa_media
    data:
      message: |
        <audio src='{{chime_tts.url}}'/>
      target:
        - media_player.echo_show
        - media_player.echo_plus
        - media_player.bathroom_echo
        - media_player.bedroom_echo
      data:
        type: tts

Maybe @nimrod_dolev can clarify this.

Hi @infiniteloop.

It seems that playing MP3s on Alexa speakers is not straight forward. You’re not the first to run into issues but unfortunately I don’t own any Alexa speakers and so I can’t help you troubleshoot against this hardware.
I suggest you post in the Chime TTS post and ask if anyone else can provide further guidance.

Thank you.
I’m not using Alexa speakers, anyway I will try to post in the other thread.

Hi @infiniteloop. I am not sure I understand.
In your YAML you provided you call the notify.alexa_media service for Amazon Echo speakers. Is this not the case?

Hi @Nimrod_Dolev,
the second example YAML I posted is from your original post about Chime_tts where you use response_variable.

The YAML I use is the one on the first post.
In the script I call the chime_tts.say service passing a variable in the message.
The target speaker is an HomePod mini.

Hi @infiniteloop, sorry for missing that.

I ran the following script with 2 service calls (1. assigning a string to a variable, and 2. using the variable in a chime_tts.say service call) and had no errors such as the one you referred to in your initial post.

alias: Garbage Notification
sequence:
  - alias: Set a templated variable
    variables:
      program: |
        This is the variable string
  - service: chime_tts.say
    data:
      chime_path: bells_2
      tts_platform: google_translate
      message: This is the Chime TTS string. {{ program }}.
    target:
      entity_id: media_player.homepod_mini
mode: single
icon: mdi:delete

I also used a HomePod mini, and the audio I received was as expected.
This suggests to me at least, that the issue lies in the Set a templated variable step of the script in your initial post.

Hi @Nimrod_Dolev,
following your example, I did several tests with my script and found that it kept giving me the same error even without using any variables.
So I’ve tried changing the speaker to another one (Sonos) and it gave me no error.
After that I took a closer look at the Registy and found out that there was another error before the one about the variable…

Service call to chime_tts.say timed out after 15 seconds.

Maybe this is the cause of subsequent errors as well?
Anyway, as I’ve written in the first post, the script is working despite the errors and I can hear the message through the HomePod mini.

EDIT:
Continuing with other tests, I realized that if I add other actions in the sequence (after the call to chime_tts) they are not being executed.

1 Like

I think something went wrong in the queue and it got stuck. This can be fixed by restarting the Chime TTS integration. If it happens after restarting the integration please send full logs so I can see what happened.

I think I got it…
I was using a custom mp3 sound chime_path: custom_components/chime_tts/mp3s/click.mp3
I switched back to default sounds and with some of them I get no errors.
I’ve made a list… if you want to investigate the problem I hope it can help you.

Working sounds:

  • Bells
  • Bright
  • Chirp
  • Chord
  • Glockenspiel
  • Hail
  • Marimba
  • Mario Coin
  • Microphone Tap
  • Whistle

Not working sounds:

  • Bells 2
  • Choir
  • Classical
  • Ding Dong
  • Drum Roll
  • Dun dun DUUUN!
  • Error
  • Ta-da!
  • Toast
  • Twenty Four
  • Sad Trombone → Using this one I got no sound and no message either.

Interestingly it seems your Chime TTS has an issue with chime sounds longer than 1.3 second: All your ‘working’ sounds are less than 1.3 seconds long, and those that don’t are longer:

Chme Sound Duration Working?
dun_dun_dun.mp3 4.440000 No
sad_trombone.mp3 3.960000 No
classical.mp3 3.096000 No
choir.mp3 2.904000 No
tada.mp3 2.351020 No
twenty_four.mp3 2.351020 No
drumroll.mp3 2.016000 No
toast.mp3 1.848000 No
ding_dong.mp3 1.560000 No
error.mp3 1.436735 No
bells_2.mp3 1.306122 No
chord.mp3 1.201633 Yes
glockenspiel.mp3 1.176000 Yes
bells.mp3 1.008000 Yes
mario_coin.mp3 0.992653 Yes
microphone_tap.mp3 0.816000 Yes
whistle.mp3 0.809796 Yes
bright.mp3 0.696000 Yes
hail.mp3 0.679184 Yes
marimba.mp3 0.574694 Yes
chirp.mp3 0.444082 Yes

My best guess is that the error is related to some process which times out after 1.2 seconds.

I doubt it is Chime TTS, but to be sure you can check your timeout setting by going to:
SettingsDevices & servicesChime TTSCONFIGURE
and increasing it.

I’ve no CONFIGURE button under the Chime TTS Integration :face_with_diagonal_mouth:
Probably I have to try to install from scratch.

Check that Chime TTS is up to date in HACS.

You should see the button in the integrations page:

Damn… my bad.
Updating the integration seems to have solved all my issues.

Thanks a lot.

:laughing: Great! Glad everything is working for you now :+1:

Should that setting be still available for increasing timeout?
I cannot see it anymore with HA 2024.4.2 and Chime TTS 1.0.0

@Nimrod_Dolev : never mind. I’ve reloaded Chime TTS manually and surprise, there it was available!
Just wondering if that shouldn’t happen eg. should be done with an Update anyway to prevent future errors like this or if this is a Home Assistant System issue that should be adressed…?
I’ve manually reloaded all components as of today, just to make sure…

Hi @andyfrei. I don’t know why you needed to manually reload Chime TTS to see the timeout configuration option…it seems like a Home Assistant bug. I don’t remember experiencing anything like this myself.

In any event, each configurable option has a default value to fallback on if not configured so I don’t think it should be a problem in the future.

1 Like