Changes in the way data is shared with the Google Home Resume script. So if you update this script, make sure to also update the other one. However, as of this version, it is also possible to use this script without the Google Home Resume script
Improvements
The ytube music player integration will now resume at the right position in the track
Support for extra variables in service calls added. This is a new feature of the Google Home Resume script. Version 2.0.0 or higher of the Google Home Resume script is required for this. For more information see here
Hello!
I’m really thankfull for your work, but I haven’t been able to modify all the settings of both script to make them work; seems that there are a lot of scripts inside, with radios and all, lots of diferrent entities that I don’t have, and I really don’t want that. All that I really wanted was to know the entity_id of the media_player that was used to call a script, is there any way to simplify this, without thinking in youtube / spotify or any other integration for that matter? I thisnk that would be very usefull, for a lot of people, on it’s own.
For instance, I have this list of media_players, and is possible to know the “last_changed”, but that doesn’t quite work as expected:
{% set colunas = ['media_player.coluna_da_sala', 'media_player.coluna_da_cozinha', 'media_player.coluna_da_cave'] %}
{{ expand(colunas) | sort(attribute='last_changed', reverse=true) | map(attribute='entity_id') | first }}
Is there something that I could do before just to get the correct media_player ?
Thanks in advance!
The script is intended to actually send an action to the right Google Home.
The Google Home Resume script is not required, you can use this script without the Google Home Resume script if you use: use_resume: false
I don’t know what you actually mean with your template example, because it doesn’t seem related to starting an action by voice on your Google Home, and knowing which one you asked it to in Home Assistant.
What your template does is determine which media_player was changed last, which of course could be because of the question asked, but also because someone changed the volume or whatever. So that might be the reason why it doesn’t work as expected.
I know you are right, and I’m thankfull for your approach. I will try to make both scripts work, but mainly understand the sequence to send the white noise and get the media_player from there. That’s mainly what I want.
I managed to replicate the white noise and possibly get the player, but as it goes last in the sequence in Google Home app it has to wait for it to be identified, as I understand. Don’t know any better aproach, so I will try to addapt your scrits to my entities. Thanks again.
You could use a trigger based template sensor with an event trigger on state change
Then use the media_title attribute with the title for the ambient sound, and use the entity_id which triggered is as the state of the sensor
Every time an entity starts playing White Noise (please check if this is the correct title), the state of this sensor (sensor.google_home_entity) will reflect the entity_id playing the sound.
Added the target_variable option. When set to true it will add the variable voice_target to the service call containing the entity_id of the Google Home which was used to trigger the script. This can be used to use the entity in a script. It will only be added on script service calls. In case the Google Home Resume script is used as well, it will also add the entity_id under extra, so the resume script will recognize it as a target to be resumed.
in the example at the first post you used the service highlighted to send the tts message.
in the latest script this part is missing.
Sorry for the noob question but “where” I have to call the chosen tts service?
You can provide any service call there, so just provide the tts service call as you would normally do under action in the script call. But don’t provide the target, as that is determined by the script.
alias: Buondì Marco
sequence:
- variables:
check_for_title: Rumore bianco
- alias: Wait until white noise started
wait_template: |
{{
expand(states.media_player)
| selectattr('attributes.media_title', 'eq', check_for_title)
| map(attribute='entity_id')
| list
| count > 0
}}
- variables:
tts_target: |
{{
expand(states.media_player)
| selectattr('attributes.media_title', 'eq', "Rumore bianco")
| map(attribute='entity_id')
| join
}}
- service: script.my_notify
data:
notify: 0
priority: 1
google:
media_player: '{{ tts_target }}'
mode: 'on'
volume: 0.5
message: >-
Sono le {{states('sensor.time')}} di {{states('sensor.weekday')}}
{{states('sensor.data')}} ed in casa ci sono mediamente {{
state_attr('climate.riscaldamento_casa',
'current_temperature')|int|string }} gradi. Fuori il clima è
{{states('sensor.dark_sky_summary')}}, con una temperatura esterna di
{{states('sensor.dark_sky_apparent_temperature')|int|string }} gradi. La
qualità dell aria è {{states('sensor.aqicn')}}. Durante la giornata il
clima sarà {{ states.sensor.dark_sky_summary_0d.state }}. La massima
sarà di
{{states.sensor.dark_sky_daytime_high_temperature_0d.state|round}} gradi
e la minima
{{states.sensor.dark_sky_overnight_low_temperature_0d.state|round}}
gradi. Oggi c è il {{states('sensor.dark_sky_precip_probability_0d') |
round (0)}} percento di probabilità di pioggia. Citazione di oggi.
{{state_attr('sensor.wikiquote', 'entries')[-1].summary|striptags}}.
- alias: Wait until white noise started
wait_template: |
{{
expand(states.media_player)
| selectattr('attributes.media_title', 'eq', check_for_title)
| map(attribute='entity_id')
| list
| count > 0
}}
- service: media_player.media_stop
target:
entity_id: '{{ tts_target }}'
mode: single
icon: mdi:tie
it doesn’t work anymore.
That’s weird because other script with similal structure
alias: Notifica Posizione Renata Hub
sequence:
- variables:
check_for_title: Rumore bianco
- alias: Wait until white noise started
wait_template: |
{{
expand(states.media_player)
| selectattr('attributes.media_title', 'eq', check_for_title)
| map(attribute='entity_id')
| list
| count > 0
}}
- variables:
tts_target: |
{{
expand(states.media_player)
| selectattr('attributes.media_title', 'eq', "Rumore bianco")
| map(attribute='entity_id')
| join
}}
- service: script.my_notify
data:
notify: 0
priority: 1
google:
media_player: '{{ tts_target }}'
mode: 'on'
volume: 0.5
message: >-
Renata dovrebbe essere vicino al civico {{ state_attr('sensor.renata',
'street_number') }} in {{ state_attr('sensor.renata', 'street') }}, {{
state_attr('sensor.renata', 'city') }}.
- alias: Wait until white noise started
wait_template: |
{{
expand(states.media_player)
| selectattr('attributes.media_title', 'eq', check_for_title)
| map(attribute='entity_id')
| list
| count > 0
}}
- service: media_player.media_stop
target:
entity_id: '{{ tts_target }}'
mode: single
icon: mdi:tie
Ah, seems you created your own version.
I tried to put all the logic to determine the target in one script, where you’ve put it directly in the script called by your Google Home.
I don’t see a reason why the second script would work, and the first one not. Is there any information in the trace?
Anyway, as you seem to be calling another script, and send the target as a variable, you could use the latest version of my script, and use the target_variable option. However, the variable containing the entity_id of the Google Home will be voice_target and not tts_target