Storing current volume levels

I have created the following helper: input_number.photoframe_current_volume but I can’t work out how to assign it the current volume of my PhotoFrame player. I thought I would do this via call service but that appears to be wrong.

Post what you tried but failed to work.

When I try make an automation to store the current value, I can’t find the input_number.photoframe_current_volume helper.

Are you saying after typing “inp” (as in your screenshot) you’re not seeing “Input Number - Set”, or after doing this and clicking on “Choose Entity”, it does not show your helper entity?

The service I think you’re looking for is input_number.set_value. The issue you’ll have is how to pull the current volume out of your photo frame.

I personally use the below automation to change the volumes on my speaker devices, but this is updating their volume to be as per the input_number, not updating the input_number to be as per the device’s volume. I use this to change their volumes manually (by changing the input_number.volume_current) or automatically based on occupancy or time of day via another automation which changes the value of input_number.volume_current which then triggers this automation.

alias: Media Player - Update Current Volume
description: ""
trigger:
  - platform: state
    entity_id: input_number.volume_current
condition: []
action:
  - service: media_player.volume_set
    data:
      volume_level: "{{ states('input_number.volume_current') | float }}"
    target:
      device_id:
        - device_ids_go_here
mode: single

Ah, it slolwy makes sense

My last quesiton then is if I want to set this to the current volume of my “media_player.photo_display” what I put in the value field? It only appears to allow me to enter a nymber but I need it to be something like media_player.volume_level

Thanks for this but I am trying to work out if it is possible to do this using the UI.

It depends on what you call “using the UI”. Through the “visual editor” UI you are seeing, you can enter values, but to do what you want, you need to enter the following template for volume:

"{{ states('input_number.volume_current') | float }}"

This cannot be done in the visual editor - if you click on the kebab menu (3 dots) on the right, you can select “edit in YAML” and just put that part in. If you change back to “edit in visual editor” you will see something like this:

image

So set all of the things you can in the visual editor before switching to editing in YAML so it fills out as much as possible.

Thanks for that. So to store the value in the help is this what I do?
This is the visual editor:

and this after clicking the YAML editor

If so, how do I tellit what media player to store the volume off

Looking at the automations.yaml file

- id: '1671467056829'
  alias: 'Helper: Store current volume'
  description: ''
  trigger:
  - platform: time
    at: '10:00:00'
  condition: []
  action:
  - service: input_number.set_value
    data: {}
    target:
      entity_id: input_number.photoframe_current_volume
  mode: single

I a m not worried about the trigger just yet; just trying to work out how to store the value :slight_smile:

Let’s step back: Why do you want to store the volume?

If the goal is to restore a media_player to its previous state (volume, content, etc) it can be more efficient, and simpler, to use a snapshot scene.

1 Like

I am using telegram to broadcast an audio message to a speaker. I turn the volume up but now wanting to return it to original state. I will look for a snapshot scene tutorial.

Many thanks

You can use scenes for that - create snapshot before and then restore it.

1 Like

Review the second example shown here: Creating scenes on the fly. Let me know if you need additional assistance.

Many thanks. I am using the following Blueprint: “Telegram Bot: Respond to Telegram Command by executing an action”

The yaml part of the scene activation is
image

but this says the device is known even though the visual editor lists it.

Not sure how to link it all together.

I can help you compose an automation that employs snapshot scenes. If you’re encountering difficulties with someone’s blueprint, ask them for assistance. They invented it so they know it best.


EDIT

FWIW, the screenshot you posted contains an invalid value for device_id. You supplied an entity_id (scene.photoframe_savesettings) but it wants a device_id (a long string of numbers and letters). I guess you entered the entity_id in the wrong field of the blueprint.

There’s something you need to take into account: the volume is only there when the media_player is on.

1 Like

Ok, not sure… but I will eventually get there :slight_smile:

aah, ok so that it why I don’t see any reference to in in any dropdowns of the visual interface then. Looks like I am going to need to spend the time getting to know YAML :wink:

Not unless the blueprint is designed to exclude media_players that are stopped/idle (which would be a strange constraint).

BTW, I looked at the blueprint you said you were using:

However, I also looked at the blueprint’s code and it doesn’t appear to be anything like the screenshot you posted.

https://raw.githubusercontent.com/marc-romu/home-assistant_blueprints/main/blueprints/automation/marc-romu_telegram-bot/telegram-bot--command__action.yaml

Ok so I think I understand how it works now

scene.create locks in the current settings for media_player.photo_display

scene.turn_on should restore them.

However my volume does not return to it’s original state.