I made an automatic for when my laundry is done. HA sends a message to me and my girlfriend’s phone, and a message plays through my google home speakers. Now I also want to add the volume in the automation. I have two questions:
What code do I need for this and where do I put it?
What a reasonable sound level that is audible but does not scare us?
Thanks for your help!
alias: Wasmachine is klaar
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.wasmachine_smart_stekker
for:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
below: '4'
condition:
- type: is_not_open
condition: device
device_id: d5c307599cbd71b6f3eb40e484f1ab42
entity_id: binary_sensor.wasmachine_deursensor
domain: binary_sensor
action:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.wasmachine
- repeat:
count: '2'
sequence:
- service: notify.mobile_app_oneplus_van_elvira
data:
message: De was is klaar! :-)
- service: notify.mobile_app_oneplus_van_rob
data:
message: De was is klaar!
- service: tts.google_translate_say
data:
entity_id: >-
media_player.keuken, media_player.mini, media_player.studeerkamer,
media_player.woonkamer
message: De was is klaar!
mode: single
As a side note to the answer already provided, you can always make speaker groups in google home app and then reference the one group entity for any automations. If you use the same speakers for multiple automations then it makes it a little easier…less typing anyway
Lower the volume is possible you just need to save the volumes to variables and after the messages, delay for two seconds then do a wait until media_player is idle (this is to make sure the message is complete before it lowers the volume).
Then lower it using the same as before but with the variable you saved.
Regarding 2, what is playing the music?
Is it a stream or is it Home Assistant?
Edit…
I now realize you asked for a “lower level” not the same as previous.
Lower level is just as before just change 0.5 to 0.3 or what you want.
But you should delay and wait until since actions are not waiting for the message to complete before lowering
Regarding resuming spotify. Not sure.
I don’t use spotify. But if the cast url is visible in the entity then you might be able to use the media extractor to cast it again.
For me when sending tts to my idle state google devices the state never changes from idle anyway so not sure if your wait in this case example would work ?
I realised that nearly 90% of my TTS automations were always playing the same message so ended up just renaming and moving the original cached tts files and referencing those mp3 files now instead of using cloud for the same message over and over.
Will check the above as I do have some bedtime routines that still use TTS as the message are dynamic and remember the timings being a pain due to what I thought was no state change from idle.
you wrote: “Lower the volume is possible you just need to save the volumes to variables and after the messages, delay for two seconds then do a wait until media_player is idle (this is to make sure the message is complete before it lowers the volume).
Then lower it using the same as before but with the variable you saved.”
Can you give me the code? How can I save the volume level in an variable and how can I set volume level after speaking the message?
Hi Hellis81,
Thank you very mutch for your answer. I tried it, but
value: “{{ state_attr(‘media_player.box_buro’, ‘volume’) }}” give no result.
The result is “None” allways.
I think, “volume” is not an attributes of media_player?
Edit:
I discovered, that with the service Turn_on you have to turn on the speaker first and then wait about 5 seconds. Then the volume is stored in the variable
This is my working script now:
alias: Test Lautstärke zwischenspeichern
sequence: