Wait for idle state on google device(s) not working

Hi all
I have a script to call a TTS services to my google devices to announce whatever is needed in the automation. I have an idle check before restoring the state on them. This works if I do the same script for a single coded in entity (instead of the inputted list) or for the entire lot using the home group. But it doesn’t work for the inputed field. Can anyone help? Ignore the timeout option as I just put that in to get around my issue.
Thanks
Alan

alias: Notify Chosen Google Devices
sequence:
  - service: scene.create
    data:
      scene_id: google_state
      snapshot_entities: "{{devices}}"
    enabled: true
  - service: media_player.volume_set
    target:
      entity_id: "{{devices}}"
    data:
      volume_level: 0.6
    enabled: true
  - service: tts.speak
    target:
      entity_id: tts.google_en_com
    data_template:
      cache: false
      media_player_entity_id: "{{devices}}"
      message: "{{message}}"
  - wait_template: "{{ is_state('{{devices}}', 'idle') }}"
    enabled: true
    timeout: "10"
    continue_on_timeout: true
  - service: scene.turn_on
    target:
      entity_id: scene.google_state
    data: {}
    enabled: true
description: Send message to chosen google devices
icon: mdi:speaker-multiple
fields:
  message:
    selector:
      text: null
    name: Message
    description: What is the message to announce on a specific speaker
    required: true
  devices:
    selector:
      entity:
        domain: media_player
        multiple: true
    name: Devices
    description: What google devices do you want to run on
    required: true
    default:
      - media_player.gh_chef
      - media_player.gh_lunar_lander
      - media_player.gh_main
      - media_player.gh_sleepy
      - media_player.gh_toto
      - media_player.gh_sausage_giraffe

You can use a list of states in is_state, but not a list of entities. So you should use something like:

"{{ expand(devices) | rejectattr('state', 'eq', 'idle') | list | count == 0 }}"

I’m not sure you need the expand here, and I’m also doubting if it is possible one or more can be off after an announcement. You may want to experiment or maybe some one else can check what I answered.

1 Like

Thanks a lot. That is working.
Only issue I have now is that the script is working on my google hub devices but not the mini’s. Do you have any idea why?

Not working how? Not speaking or not waiting?

The mini’s don’t seem to restore the scene. I don’t know if they are not completing the wait till idle command or something else. But the nest hub works, strange.
I’ll dig in the logs a bit and see if I can make any sense some day soon.

Hi I have similar problem. The media player is still in state “playing”, so I am unable to trigger state Idle. This stopped working after upgrading HA to 2024.8