Storing current volume levels

By posting screenshots, instead of YAML, you’re effectively discouraging others from posting corrections to your example. Why? Because in order to reply to you, they have to re-type what is shown in your screenshots. In addition, no one can see what you entered in the sections that are not expanded.

For more information, refer to guideline 11 in the FAQ.

image

Appologies

alias: "Telegram: /say"
description: Broadcast message to speakers
use_blueprint:
  path: marc-romu/telegram-bot--command__action.yaml
  input:
    telegram_command: /say
    telegram_bot: "@mybot_bot"
    sequence:
      - service: scene.create
        data:
          scene_id: photoframe_savesettings
          snapshot_entities: media_player.photo_display
        enabled: true
      - service: media_player.volume_set
        data:
          volume_level: 1
        target:
          device_id: c56f7aaf9b35374575f9b029884c52d2
      - service: tts.google_translate_say
        data:
          entity_id: media_player.photo_display
          message: "{{ telegram_args_as_text }} "
      - delay:
          hours: 0
          minutes: 0
          seconds: 5
          milliseconds: 0
      - service: scene.turn_on
        data: {}
        target:
          entity_id: scene.photoframe_savesettings
        enabled: true

Create the following script (using the built-in Script Editor, create a new empty script, copy-paste the YAML shown below into it, then save the script).

alias: Example 1
sequence:
  - service: scene.create
    data:
      scene_id: example_1
      snapshot_entities: media_player.photo_display
  - service: media_player.volume_set
    data:
      volume_level: 0.75
    target:
      entity_id: media_player.photo_display
  - service: tts.google_translate_say
    data:
      entity_id: media_player.photo_display
      message: "Hello world!"
  - delay:
      seconds: 5
  - service: scene.turn_on
    target:
      entity_id: scene.example_1
  • To test it, first set the media_player’s volume to a value lower than 75% like 25%.
  • Run the script. Confirm the media_player announces "Hello world!
  • Check if the media_player’s volume is now back to 25% or is still at 75%.
1 Like

Additionally you might want to actually open the scene and look at it’s YAML and post it here.
That will at least tell us if it did actually snapshot the volume.
But because the media_player is called photo_display I am guessing it’s probably a Google Nest Display Gen 2, or a Lenovo Smart Display - and Chromecast devices don’t provide a volume level when they are not active, so the volume would not be part of the snapshot.

You would need to first send the power on command to the media player, then snapshot it.

A good spot to learn what attributes are available is in the Developer Tools “States” tab.

When writing my original reply I went there to see if I could do what you’re looking for myself, as I do have some automations that play with media_player volumes but only to set them, not store them. When I did look there I didn’t find a attribute for the current volume, hence I commented that you may have difficulty pulling that value from your photoframe. but thanks to @Edwin_D’s comment I now know that the attributes do exist but are only accessible when the media_player is on.

1 Like

One comment I have on this snippet is the delay - whilst this will likely achieve what you’re after, one thing to consider is the intent. The intent here is to delay the rest of the script while the photo frame plays the audio.

I did this the same way with my announcements, but that involved some tweaking on the longer “briefings” to allow sufficient delay. I then had some occasions that the announcement would get cut off as there was a slight timing differences between the script triggering, the media_player turning on, then starting the audio. You could obviously resolve this with a longer delay, but again: intent.

What I ended up doing was changing the script from having a delay to having two wait_for_trigger's. One would wait for the media_player to be playing, the next would wait for the media_player to be idle. The script would then continue as normal. This meant that I could have the delay without having to fuss about with timings, and I could use the same code on any annoucement (I actually ended up moving this ‘delay’ code out to it’s own automation which triggers when media_player's start playing and waits for them to become idle; but my use case was for switching them back off when done, not fiddling with volumes)

1 Like

The volume stays at 75%

What kind of media player is it? To put it another way, which integration are you using to integrate the media player with Home Assistant?

It lists under Google Cast: Lenovo Smart Display 10